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
210 lines (187 loc) · 5.52 KB
/
cdb2api_hndl.h
File metadata and controls
210 lines (187 loc) · 5.52 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
/*
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 <sbuf2.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];
} cnonce_t;
#define MAX_CONTEXTS 10 /* Maximum stack size for storing context messages */
#define MAX_CONTEXT_LEN 100 /* Maximum allowed length of a context message */
struct context_messages {
char *message[MAX_CONTEXTS];
int count;
int has_changed;
};
struct cdb2_stmt_types;
typedef struct cdb2_query_list_item {
void *buf;
int len;
int is_read;
char *sql;
struct cdb2_query_list_item *next;
} cdb2_query_list;
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;
struct cdb2_hndl {
char dbname[DBNAME_LEN];
char cluster[64];
char type[TYPE_LEN];
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 */
SBUF2 *sb;
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[DBNAME_LEN + TYPE_LEN + POLICY_LEN + 16];
char policy[POLICY_LEN];
int master;
int connected_host;
char *query;
char *query_hint;
char *hint;
int use_hint;
int flags;
char errstr[1024];
cnonce_t cnonce;
char *sql;
int ntypes;
int *types;
uint8_t *last_buf;
CDB2SQLRESPONSE *lastresponse;
uint8_t *first_buf;
CDB2SQLRESPONSE *firstresponse;
int error_in_trans;
int client_side_error;
int n_bindvars;
CDB2SQLQUERY__Bindvalue **bindvars;
cdb2_query_list *query_list;
int snapshot_file;
int snapshot_offset;
int query_no;
int retry_all;
int num_set_commands;
int num_set_commands_sent;
int is_read;
unsigned long long rows_read;
int read_intrans_results;
int first_record_read;
char **commands;
int ack;
int is_hasql;
int is_admin;
int clear_snap_line;
int debug_trace;
int max_retries;
int min_retries;
ssl_mode c_sslmode; /* client SSL mode */
peer_ssl_mode s_sslmode; /* server SSL mode */
int sslerr; /* 1 if unrecoverable SSL error. */
char *sslpath; /* SSL certificates */
char *cert;
char *key;
char *ca;
char *crl;
int cache_ssl_sess;
double min_tls_ver;
cdb2_ssl_sess *sess;
int nid_dbname;
/* 1 if it's a newly established session which needs to be cached. */
int newsess;
struct context_messages context_msgs;
char *env_tz;
int sent_client_info;
char stack[MAX_STACK];
int send_stack;
void *user_arg;
int *gbl_event_version; /* Cached global event version */
int api_call_timeout;
int connect_timeout;
int comdb2db_timeout;
int socket_timeout;
int request_fp; /* 1 if requesting the fingerprint; 0 otherwise. */
cdb2_event *events;
// Protobuf allocator data used only for row data i.e. lastresponse
void *protobuf_data;
int protobuf_size;
int protobuf_offset;
ProtobufCAllocator allocator;
int auto_consume_timeout_ms;
int max_auto_consume_rows;
struct cdb2_hndl *fdb_hndl;
int is_child_hndl;
CDB2SQLQUERY__IdentityBlob *id_blob;
struct cdb2_stmt_types *stmt_types;
};
#endif