3838#include <limits.h> // int_max
3939
4040#include "cdb2api.h"
41+ #include "cdb2api_hndl.h"
4142
4243#include "sqlquery.pb-c.h"
4344#include "sqlresponse.pb-c.h"
@@ -57,7 +58,6 @@ static char *SOCKPOOL_OTHER_NAME = NULL;
5758#define COMDB2DB "comdb2db"
5859#define COMDB2DB_NUM 32432
5960#define MAX_BUFSIZE_ONSTACK 8192
60- #define CDB2HOSTNAME_LEN 128
6161static char COMDB2DB_OVERRIDE [32 ] = {0 };
6262static int COMDB2DB_NUM_OVERRIDE = 0 ;
6363
@@ -162,7 +162,6 @@ static double cdb2_min_tls_ver = CDB2_MIN_TLS_VER_DEFAULT;
162162
163163static pthread_mutex_t cdb2_ssl_sess_lock = PTHREAD_MUTEX_INITIALIZER ;
164164
165- typedef struct cdb2_ssl_sess cdb2_ssl_sess ;
166165static cdb2_ssl_sess * cdb2_get_ssl_sessions (cdb2_hndl_tp * hndl );
167166static int cdb2_set_ssl_sessions (cdb2_hndl_tp * hndl ,
168167 cdb2_ssl_sess * sessions );
@@ -181,12 +180,6 @@ static int iam_identity = 0;
181180
182181#define DB_TZNAME_DEFAULT "America/New_York"
183182
184- #define MAX_NODES 128
185- #define MAX_CONTEXTS 10 /* Maximum stack size for storing context messages */
186- #define MAX_CONTEXT_LEN 100 /* Maximum allowed length of a context message */
187-
188- #define MAX_STACK 512 /* Size of call-stack which opened the handle */
189-
190183pthread_mutex_t cdb2_sockpool_mutex = PTHREAD_MUTEX_INITIALIZER ;
191184#define MAX_SOCKPOOL_FDS 8
192185
@@ -197,17 +190,6 @@ static int log_calls = 0; /* ONE-TIME */
197190
198191static void reset_sockpool (void );
199192
200- struct cdb2_event {
201- cdb2_event_type types ;
202- cdb2_event_ctrl ctrls ;
203- cdb2_event_callback cb ;
204- int global ;
205- void * user_arg ;
206- cdb2_event * next ;
207- int argc ;
208- cdb2_event_arg argv [1 ];
209- };
210-
211193static pthread_mutex_t cdb2_event_mutex = PTHREAD_MUTEX_INITIALIZER ;
212194static cdb2_event cdb2_gbl_events ;
213195static int cdb2_gbl_event_version ;
@@ -937,12 +919,6 @@ static int cdb2_do_tcpconnect(struct in_addr in, int port, int myport,
937919 return (sockfd ); /* all OK */
938920}
939921
940- struct context_messages {
941- char * message [MAX_CONTEXTS ];
942- int count ;
943- int has_changed ;
944- };
945-
946922/* Forward declarations. */
947923static void cdb2_init_context_msgs (cdb2_hndl_tp * hndl );
948924static int cdb2_free_context_msgs (cdb2_hndl_tp * hndl );
@@ -955,158 +931,8 @@ struct newsqlheader {
955931 int length ;
956932};
957933
958- typedef struct cdb2_query_list_item {
959- void * buf ;
960- int len ;
961- int is_read ;
962- char * sql ;
963- struct cdb2_query_list_item * next ;
964- } cdb2_query_list ;
965-
966- struct cdb2_ssl_sess {
967- struct cdb2_ssl_sess * next ;
968- char dbname [64 ];
969- char cluster [64 ];
970- int ref ;
971- SSL_SESSION * sessobj ;
972- };
973-
974934static cdb2_ssl_sess cdb2_ssl_sess_cache ;
975935
976- /* A cnonce is composed of
977- - 32 bits of machine ID
978- - 32 bits of process PID
979- - 32 or 64 bits of handle address
980- - 52 bits for the epoch time in microseconds
981- - 12 bits for the sequence number
982-
983- The allocation allows a handle to run at a maximum transaction rate of
984- 4096 txn/us (~4 billion transactions per second) till September 17, 2112.
985-
986- See next_cnonce() for details. */
987- #define CNONCE_STR_FMT "%lx-%x-%llx-"
988- #define CNONCE_STR_SZ 60 /* 16 + 1 + 8 + 1 + 16 + 1 + 16 + 1 (NUL) */
989-
990- #define CNT_BITS 12
991- #define TIME_MASK (-1ULL << CNT_BITS)
992- #define CNT_MASK (-1ULL ^ TIME_MASK)
993-
994- typedef struct cnonce {
995- long hostid ;
996- int pid ;
997- struct cdb2_hndl * hndl ;
998- uint64_t seq ;
999- int ofs ;
1000- char str [CNONCE_STR_SZ ];
1001- } cnonce_t ;
1002-
1003- #define DBNAME_LEN 64
1004- #define TYPE_LEN 64
1005- #define POLICY_LEN 24
1006-
1007- struct cdb2_hndl {
1008- char dbname [DBNAME_LEN ];
1009- char cluster [64 ];
1010- char type [TYPE_LEN ];
1011- char hosts [MAX_NODES ][CDB2HOSTNAME_LEN ];
1012- uint64_t timestampus ; // client query timestamp of first try
1013- int ports [MAX_NODES ];
1014- int hosts_connected [MAX_NODES ];
1015- char shards [MAX_NODES ][DBNAME_LEN ];
1016- char cached_host [CDB2HOSTNAME_LEN ]; /* hostname of a sockpool connection */
1017- int cached_port ; /* port of a sockpool connection */
1018- SBUF2 * sb ;
1019- int dbnum ;
1020- int num_hosts ; /* total number of hosts */
1021- int num_hosts_sameroom ; /* number of hosts that are in my datacenter (aka room) */
1022- int num_shards ;
1023- int num_shards_sameroom ;
1024- int node_seq ; /* fail over to the `node_seq'-th host */
1025- int in_trans ;
1026- int temp_trans ;
1027- int is_retry ;
1028- int is_chunk ;
1029- int is_set ;
1030- char newsql_typestr [DBNAME_LEN + TYPE_LEN + POLICY_LEN + 16 ];
1031- char policy [POLICY_LEN ];
1032- int master ;
1033- int connected_host ;
1034- char * query ;
1035- char * query_hint ;
1036- char * hint ;
1037- int use_hint ;
1038- int flags ;
1039- char errstr [1024 ];
1040- cnonce_t cnonce ;
1041- char * sql ;
1042- int ntypes ;
1043- int * types ;
1044- uint8_t * last_buf ;
1045- CDB2SQLRESPONSE * lastresponse ;
1046- uint8_t * first_buf ;
1047- CDB2SQLRESPONSE * firstresponse ;
1048- int error_in_trans ;
1049- int client_side_error ;
1050- int n_bindvars ;
1051- CDB2SQLQUERY__Bindvalue * * bindvars ;
1052- cdb2_query_list * query_list ;
1053- int snapshot_file ;
1054- int snapshot_offset ;
1055- int query_no ;
1056- int retry_all ;
1057- int num_set_commands ;
1058- int num_set_commands_sent ;
1059- int is_read ;
1060- unsigned long long rows_read ;
1061- int read_intrans_results ;
1062- int first_record_read ;
1063- char * * commands ;
1064- int ack ;
1065- int is_hasql ;
1066- int is_admin ;
1067- int clear_snap_line ;
1068- int debug_trace ;
1069- int max_retries ;
1070- int min_retries ;
1071- ssl_mode c_sslmode ; /* client SSL mode */
1072- peer_ssl_mode s_sslmode ; /* server SSL mode */
1073- int sslerr ; /* 1 if unrecoverable SSL error. */
1074- char * sslpath ; /* SSL certificates */
1075- char * cert ;
1076- char * key ;
1077- char * ca ;
1078- char * crl ;
1079- int cache_ssl_sess ;
1080- double min_tls_ver ;
1081- cdb2_ssl_sess * sess ;
1082- int nid_dbname ;
1083- /* 1 if it's a newly established session which needs to be cached. */
1084- int newsess ;
1085- struct context_messages context_msgs ;
1086- char * env_tz ;
1087- int sent_client_info ;
1088- char stack [MAX_STACK ];
1089- int send_stack ;
1090- void * user_arg ;
1091- int * gbl_event_version ; /* Cached global event version */
1092- int api_call_timeout ;
1093- int connect_timeout ;
1094- int comdb2db_timeout ;
1095- int socket_timeout ;
1096- int request_fp ; /* 1 if requesting the fingerprint; 0 otherwise. */
1097- cdb2_event * events ;
1098- // Protobuf allocator data used only for row data i.e. lastresponse
1099- void * protobuf_data ;
1100- int protobuf_size ;
1101- int protobuf_offset ;
1102- ProtobufCAllocator allocator ;
1103- int auto_consume_timeout_ms ;
1104- int max_auto_consume_rows ;
1105- struct cdb2_hndl * fdb_hndl ;
1106- int is_child_hndl ;
1107- CDB2SQLQUERY__IdentityBlob * id_blob ;
1108- };
1109-
1110936static void * cdb2_protobuf_alloc (void * allocator_data , size_t size )
1111937{
1112938 struct cdb2_hndl * hndl = allocator_data ;
0 commit comments