forked from bloomberg/comdb2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcdb2api_hndl.h
More file actions
241 lines (210 loc) · 6.63 KB
/
cdb2api_hndl.h
File metadata and controls
241 lines (210 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
Copyright 2025 Bloomberg Finance L.P.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
* CDB2API HNDL
*
*/
#ifndef INCLUDED_CDB2API_HNDL_H
#define INCLUDED_CDB2API_HNDL_H
#include <comdb2buf.h>
#include <sys/types.h>
#include <sys/queue.h>
#define MAX_NODES 128
#define DBNAME_LEN 64
#define TYPE_LEN 64
#define POLICY_LEN 24
#define CDB2HOSTNAME_LEN 128
#define MAX_STACK 512 /* Size of call-stack which opened the handle */
#include "sqlquery.pb-c.h"
#include "sqlresponse.pb-c.h"
#include "cdb2api.h"
struct cdb2_event {
cdb2_event_type types;
cdb2_event_ctrl ctrls;
cdb2_event_callback cb;
int global;
void *user_arg;
cdb2_event *next;
int argc;
cdb2_event_arg argv[1];
};
/* A cnonce is composed of
- 32 bits of machine ID
- 32 bits of process PID
- 32 or 64 bits of handle address
- 52 bits for the epoch time in microseconds
- 12 bits for the sequence number
The allocation allows a handle to run at a maximum transaction rate of
4096 txn/us (~4 billion transactions per second) till September 17, 2112.
See next_cnonce() for details. */
#define CNONCE_STR_FMT "%lx-%x-%llx-"
#define CNONCE_STR_SZ 60 /* 16 + 1 + 8 + 1 + 16 + 1 + 16 + 1 (NUL) */
#define CNT_BITS 12
#define TIME_MASK (-1ULL << CNT_BITS)
#define CNT_MASK (-1ULL ^ TIME_MASK)
typedef struct cnonce {
long hostid;
int pid;
struct cdb2_hndl *hndl;
uint64_t seq;
int ofs;
char str[CNONCE_STR_SZ];
int len;
} cnonce_t;
struct cdb2_stmt_types;
struct cdb2_query {
TAILQ_ENTRY(cdb2_query) entry;
void *buf;
int len;
int is_read;
char *sql;
};
TAILQ_HEAD(query_list, cdb2_query);
struct cdb2_ssl_sess {
struct cdb2_ssl_sess *next;
char dbname[64];
char cluster[64];
int ref;
SSL_SESSION *sessobj;
};
typedef struct cdb2_ssl_sess cdb2_ssl_sess;
#define TYPESTR_LEN DBNAME_LEN + TYPE_LEN + POLICY_LEN + 16
struct cdb2_hndl {
char dbname[DBNAME_LEN];
char type[TYPE_LEN];
int resolv_def; /* 1 if type argument is "default" */
char hosts[MAX_NODES][CDB2HOSTNAME_LEN];
uint64_t timestampus; // client query timestamp of first try
int ports[MAX_NODES];
int hosts_connected[MAX_NODES];
char shards[MAX_NODES][DBNAME_LEN];
char cached_host[CDB2HOSTNAME_LEN]; /* hostname of a sockpool connection */
int cached_port; /* port of a sockpool connection */
COMDB2BUF *sb;
int num_set_commands;
int num_set_commands_sent;
char **commands;
int dbnum;
int num_hosts; /* total number of hosts */
int num_hosts_sameroom; /* number of hosts that are in my datacenter (aka room) */
int num_shards;
int num_shards_sameroom;
int node_seq; /* fail over to the `node_seq'-th host */
int in_trans;
int temp_trans;
int is_retry;
int is_chunk;
int is_set;
char newsql_typestr[TYPESTR_LEN];
char policy[POLICY_LEN];
int master;
int connected_host;
int flags;
char errstr[1024];
cnonce_t cnonce;
char *sql;
char partial_sql[64];
int ntypes;
const int *types;
unsigned char *last_buf;
CDB2SQLRESPONSE *lastresponse;
unsigned char *first_buf;
CDB2SQLRESPONSE *firstresponse;
int error_in_trans;
int client_side_error;
int n_bindvars;
CDB2SQLQUERY__Bindvalue **bindvars;
struct query_list queries;
int snapshot_file;
int snapshot_offset;
int query_no;
int retry_all;
int is_read;
int is_invalid;
int is_rejected;
unsigned long long rows_read;
int read_intrans_results;
int first_record_read;
int ack;
int is_hasql;
int sent_client_info;
void *user_arg;
long long max_call_time;
int api_call_timeout;
int connect_timeout;
int comdb2db_timeout;
int socket_timeout;
int sockpool_send_timeoutms;
int sockpool_recv_timeoutms;
int gbl_event_version; /* Cached global event version */
cdb2_event events; /* event linkedlist head */
pid_t pid;
int got_dbinfo;
int is_admin;
int sockpool_enabled;
int db_default_type_override_env;
int clear_snap_line;
int debug_trace;
int max_retries;
int min_retries;
/* SSL variables */
/* client SSL mode */
ssl_mode c_sslmode;
/* server SSL mode */
peer_ssl_mode s_sslmode;
/* 1 if unrecoverable SSL error. */
int sslerr;
/* SSL certificate path. When specified, code looks for $sslpath/root.crt,
$sslpath/client.key, $sslpath/client.crt and $sslpath/root.crl, for
root certificate, client certificate, client key, and root CRL, respectively. */
char *sslpath;
/* client certificate. overrides sslpath when specified. */
char *cert;
/* client key. overrides sslpath when specified. */
char *key;
/* root CA certificate. overrides sslpath when specified. */
char *ca;
/* root certificate revocation list (CRL). overrides sslpath when specified. */
char *crl;
/* minimal TLS version. Set it to 0 if we want client and server to negotiate.
The final version will be the minimal version that are mutually understood by
both client and server. Set it to an TLS version (1.2, 1.3, etc.) to override.
Note that if either side does not support the version, handshake will fail. */
double min_tls_ver;
/* 1 if caching ssl sessions (can speed up SSL handshake) */
int cache_ssl_sess;
cdb2_ssl_sess *sess;
/* 1 if it's a newly established session which needs to be cached. */
int newsess;
/* X509 attribute to check database name against */
int nid_dbname;
char stack[MAX_STACK];
int send_stack;
int request_fp; /* 1 if requesting the fingerprint; 0 otherwise. */
/* per handle iaaap::IIdentity */
const void *identity;
// Protobuf allocator data used only for row data i.e. lastresponse
ProtobufCAllocator s_allocator;
void *protobuf_data;
int protobuf_size;
int protobuf_offset;
ProtobufCAllocator *allocator;
int max_auto_consume_rows;
struct cdb2_hndl *fdb_hndl;
int is_child_hndl;
CDB2SQLQUERY__IdentityBlob *id_blob;
struct cdb2_stmt_types *stmt_types;
RETRY_CALLBACK retry_clbk;
int is_tagged;
};
#endif