CUBRID Engine  latest
shard_statement.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "cas_common.h"
#include "shard_proxy.h"
#include "shard_proxy_common.h"
#include "shard_statement.h"
#include "shard_shm.h"
Include dependency graph for shard_statement.c:

Go to the source code of this file.

Functions

static int shard_stmt_lru_insert (T_SHARD_STMT *stmt_p)
 
static int shard_stmt_lru_delete (T_SHARD_STMT *stmt_p)
 
static T_SHARD_STMTshard_stmt_get_lru (void)
 
static int * shard_stmt_pos_srv_h_id (T_SHARD_STMT *stmt_p, int shard_id, int cas_id)
 
static int shard_stmt_find_srv_h_id (T_SHARD_STMT *stmt_p, int shard_id, int cas_id)
 
static int shard_stmt_set_srv_h_id (T_SHARD_STMT *stmt_p, int shard_id, int cas_id, int srv_h_id)
 
static T_SHARD_STMTshard_stmt_find_unused (void)
 
static T_SHARD_STMTshard_stmt_new_internal (int stmt_type, char *sql_stmt, int ctx_cid, unsigned int ctx_uid, T_BROKER_VERSION client_version)
 
static int shard_stmt_change_shard_val_to_id (char **sql_stmt, const char **buf, char appl_server)
 
static char * shard_stmt_write_buf_to_sql (char *sql_stmt, const char *buf, int length, bool is_to_upper, char appl_server)
 
static T_BROKER_VERSION shard_stmt_make_protocol_version (T_BROKER_VERSION client_version)
 
static void shard_stmt_put_statement_to_map (const char *sql_stmt, T_SHARD_STMT *stmt_p)
 
static void shard_stmt_del_statement_from_map (T_SHARD_STMT *stmt_p)
 
static void shard_stmt_set_status (int stmt_h_id, int status)
 
T_SHARD_STMTshard_stmt_find_by_sql (char *sql_stmt, const char *db_user, T_BROKER_VERSION client_version)
 
T_SHARD_STMTshard_stmt_find_by_stmt_h_id (int stmt_h_id)
 
int shard_stmt_pin (T_SHARD_STMT *stmt_p)
 
int shard_stmt_unpin (T_SHARD_STMT *stmt_p)
 
void shard_stmt_check_waiter_and_wakeup (T_SHARD_STMT *stmt_p)
 
T_SHARD_STMTshard_stmt_new_prepared_stmt (char *sql_stmt, int ctx_cid, unsigned int ctx_uid, T_BROKER_VERSION client_version)
 
T_SHARD_STMTshard_stmt_new_schema_info (int ctx_cid, unsigned int ctx_uid)
 
T_SHARD_STMTshard_stmt_new_exclusive (char *sql_stmt, int ctx_cid, unsigned int ctx_uid, T_BROKER_VERSION client_version)
 
void shard_stmt_destroy (void)
 
void shard_stmt_free (T_SHARD_STMT *stmt_p)
 
int shard_stmt_find_srv_h_id_for_shard_cas (int stmt_h_id, int shard_id, int cas_id)
 
int shard_stmt_add_srv_h_id_for_shard_cas (int stmt_h_id, int shard_id, int cas_id, int srv_h_id)
 
void shard_stmt_del_srv_h_id_for_shard_cas (int stmt_h_id, int shard_id, int cas_id)
 
void shard_stmt_del_all_srv_h_id_for_shard_cas (int shard_id, int cas_id)
 
int shard_stmt_set_hint_list (T_SHARD_STMT *stmt_p)
 
int shard_stmt_get_hint_type (T_SHARD_STMT *stmt_p)
 
int shard_stmt_save_prepare_request (T_SHARD_STMT *stmt_p, bool has_shard_val_hint, char **prepare_req, int *prepare_req_len, char *argv_sql_stmt, char *argv_remainder, char *orgzd_sql)
 
char * shard_str_stmt (T_SHARD_STMT *stmt_p)
 
int shard_stmt_initialize (int initial_size)
 
char * shard_stmt_rewrite_sql (bool *has_shard_val_hint, char *sql_stmt, char appl_server)
 
void shard_statement_wait_timer (void)
 
void shard_stmt_set_status_invalid (int stmt_h_id)
 
void shard_stmt_set_status_complete (int stmt_h_id)
 

Variables

T_SHM_SHARD_KEYshm_key_p
 
T_PROXY_INFOproxy_info_p
 
T_SHARD_STMT_GLOBAL shard_Stmt
 
int shard_Stmt_max_num_alloc = SHARD_STMT_MAX_NUM_ALLOC
 

Function Documentation

void shard_statement_wait_timer ( void  )
int shard_stmt_add_srv_h_id_for_shard_cas ( int  stmt_h_id,
int  shard_id,
int  cas_id,
int  srv_h_id 
)
void shard_stmt_del_all_srv_h_id_for_shard_cas ( int  shard_id,
int  cas_id 
)
void shard_stmt_del_srv_h_id_for_shard_cas ( int  stmt_h_id,
int  shard_id,
int  cas_id 
)
static void shard_stmt_del_statement_from_map ( T_SHARD_STMT stmt_p)
static

Definition at line 1465 of file shard_statement.c.

References assert, t_shard_stmt::hash_next, t_shard_stmt::hash_prev, mht_get(), mht_put(), mht_rem(), NULL, t_shard_stmt::parser, sp_get_sql_stmt(), and t_shard_stmt_global::stmt_map.

Referenced by shard_stmt_free().

Here is the caller graph for this function:

static int shard_stmt_find_srv_h_id ( T_SHARD_STMT stmt_p,
int  shard_id,
int  cas_id 
)
static

Definition at line 169 of file shard_statement.c.

References NULL, and shard_stmt_pos_srv_h_id().

Referenced by shard_stmt_find_srv_h_id_for_shard_cas().

Here is the caller graph for this function:

static T_SHARD_STMT * shard_stmt_find_unused ( void  )
static

Definition at line 289 of file shard_statement.c.

References i, t_shard_stmt_global::max_num_stmt, NULL, SHARD_STMT_STATUS_UNUSED, t_shard_stmt::status, and t_shard_stmt_global::stmt_ent.

Referenced by shard_stmt_new_internal().

Here is the caller graph for this function:

static T_SHARD_STMT * shard_stmt_get_lru ( void  )
static

Definition at line 141 of file shard_statement.c.

References t_shard_stmt_global::lru.

Referenced by shard_stmt_new_internal().

Here is the caller graph for this function:

static int shard_stmt_lru_delete ( T_SHARD_STMT stmt_p)
static
static int shard_stmt_lru_insert ( T_SHARD_STMT stmt_p)
static
static T_BROKER_VERSION shard_stmt_make_protocol_version ( T_BROKER_VERSION  client_version)
static

Definition at line 198 of file shard_statement.c.

References CAS_MAKE_VER, CAS_PROTO_CURRENT_VER, CAS_PROTO_MAKE_VER, and PROTOCOL_V1.

Referenced by shard_stmt_find_by_sql(), and shard_stmt_new_internal().

Here is the caller graph for this function:

T_SHARD_STMT* shard_stmt_new_exclusive ( char *  sql_stmt,
int  ctx_cid,
unsigned int  ctx_uid,
T_BROKER_VERSION  client_version 
)

Definition at line 548 of file shard_statement.c.

References NULL, shard_stmt_new_internal(), and SHARD_STMT_TYPE_EXCLUSIVE.

Referenced by fn_proxy_client_prepare(), and fn_proxy_client_prepare_and_execute().

Here is the caller graph for this function:

static T_SHARD_STMT * shard_stmt_new_internal ( int  stmt_type,
char *  sql_stmt,
int  ctx_cid,
unsigned int  ctx_uid,
T_BROKER_VERSION  client_version 
)
static
T_SHARD_STMT* shard_stmt_new_prepared_stmt ( char *  sql_stmt,
int  ctx_cid,
unsigned int  ctx_uid,
T_BROKER_VERSION  client_version 
)

Definition at line 530 of file shard_statement.c.

References NULL, shard_stmt_new_internal(), and SHARD_STMT_TYPE_PREPARED.

Referenced by fn_proxy_client_prepare().

Here is the caller graph for this function:

T_SHARD_STMT* shard_stmt_new_schema_info ( int  ctx_cid,
unsigned int  ctx_uid 
)

Definition at line 539 of file shard_statement.c.

References NULL, shard_stmt_new_internal(), and SHARD_STMT_TYPE_SCHEMA_INFO.

Referenced by fn_proxy_client_schema_info().

Here is the caller graph for this function:

static int * shard_stmt_pos_srv_h_id ( T_SHARD_STMT stmt_p,
int  shard_id,
int  cas_id 
)
static
static void shard_stmt_put_statement_to_map ( const char *  sql_stmt,
T_SHARD_STMT stmt_p 
)
static
char* shard_stmt_rewrite_sql ( bool has_shard_val_hint,
char *  sql_stmt,
char  appl_server 
)

The 'shard_val(n)' is changed to 'shard_id(N)'. a minimum number of chipers of n is 1; a maximum number of chipers of N is 3; so length of organized sql can be larger than length of original sql.

Definition at line 1133 of file shard_statement.c.

References error(), HT_NONE, HT_VAL, NO_ERROR, NULL, p, shard_stmt_change_shard_val_to_id(), shard_stmt_write_buf_to_sql(), sp_get_hint_type(), sp_get_token_type(), sp_is_exist_pair_token(), sp_is_pair_token(), strlen, TT_CPP_COMMENT, TT_CSQL_COMMENT, TT_DOUBLE_QUOTED, TT_HINT, TT_NEWLINE, TT_NONE, TT_SINGLE_QUOTED, and TT_WHITESPACE.

Referenced by fn_proxy_client_prepare().

Here is the caller graph for this function:

static int shard_stmt_set_srv_h_id ( T_SHARD_STMT stmt_p,
int  shard_id,
int  cas_id,
int  srv_h_id 
)
static

Definition at line 183 of file shard_statement.c.

References NULL, and shard_stmt_pos_srv_h_id().

Referenced by shard_stmt_add_srv_h_id_for_shard_cas().

Here is the caller graph for this function:

static void shard_stmt_set_status ( int  stmt_h_id,
int  status 
)
static
void shard_stmt_set_status_complete ( int  stmt_h_id)

Definition at line 1432 of file shard_statement.c.

References shard_stmt_set_status(), and SHARD_STMT_STATUS_COMPLETE.

Referenced by shard_stmt_add_srv_h_id_for_shard_cas().

Here is the caller graph for this function:

void shard_stmt_set_status_invalid ( int  stmt_h_id)

Definition at line 1426 of file shard_statement.c.

References shard_stmt_set_status(), and SHARD_STMT_STATUS_INVALID.

Referenced by fn_proxy_cas_prepare(), and proxy_cas_execute_internal().

Here is the caller graph for this function:

int shard_stmt_unpin ( T_SHARD_STMT stmt_p)
char * shard_stmt_write_buf_to_sql ( char *  sql_stmt,
const char *  buf,
int  length,
bool  is_to_upper,
char  appl_server 
)
static

Definition at line 1380 of file shard_statement.c.

References APPL_SERVER_CAS, and i.

Referenced by shard_stmt_change_shard_val_to_id(), and shard_stmt_rewrite_sql().

Here is the caller graph for this function:

Variable Documentation

T_SHARD_STMT_GLOBAL shard_Stmt

Definition at line 67 of file shard_statement.c.

int shard_Stmt_max_num_alloc = SHARD_STMT_MAX_NUM_ALLOC

Definition at line 69 of file shard_statement.c.

Referenced by shard_stmt_initialize(), and shard_stmt_new_internal().