Skip to content

Commit ba79e47

Browse files
committed
Port changes from prox
Signed-off-by: Salil Chandra <schandra107@bloomberg.net>
1 parent 0f66630 commit ba79e47

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

cdb2api/cdb2api.c

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ static int refresh_gbl_events_on_hndl(cdb2_hndl_tp *);
325325
static int cdb2_get_dbhosts(cdb2_hndl_tp *);
326326
static void hndl_set_comdb2buf(cdb2_hndl_tp *, COMDB2BUF *, int idx);
327327
static int send_reset(COMDB2BUF *sb, int localcache);
328+
static void free_raw_response(cdb2_hndl_tp *hndl);
328329

329330
static int check_hb_on_blocked_write = 0; // temporary switch - this will be default behavior
330331
static int check_hb_on_blocked_write_set_from_env = 0;
@@ -1484,7 +1485,11 @@ void cdb2_set_sockpool(const char *sp_path)
14841485
SOCKPOOL_OTHER_NAME = strdup(sp_path);
14851486
}
14861487

1487-
static int is_valid_int(const char *str)
1488+
#ifndef CDB2API_SERVER
1489+
static
1490+
#endif
1491+
int
1492+
cdb2_is_valid_int(const char *str)
14881493
{
14891494
while (*str) {
14901495
if (!isdigit(*str))
@@ -1582,7 +1587,7 @@ static void parse_dbhosts_from_env(int *dbnum, int *num_hosts, char hosts[][CDB2
15821587
if (tok == NULL) {
15831588
return;
15841589
}
1585-
if (is_valid_int(tok)) {
1590+
if (cdb2_is_valid_int(tok)) {
15861591
*dbnum = atoi(tok);
15871592
tok = strtok_r(NULL, " :,", &last);
15881593
}
@@ -1758,7 +1763,7 @@ static void read_comdb2db_cfg(cdb2_hndl_tp *hndl, COMDB2BUF *s, const char *comd
17581763
}
17591764
if (comdb2db_name && strcasecmp(comdb2db_name, tok) == 0) {
17601765
tok = strtok_r(NULL, " :,", &last);
1761-
if (tok && is_valid_int(tok)) {
1766+
if (tok && cdb2_is_valid_int(tok)) {
17621767
*comdb2db_num = atoi(tok);
17631768
tok = strtok_r(NULL, " :,", &last);
17641769
}
@@ -1778,7 +1783,7 @@ static void read_comdb2db_cfg(cdb2_hndl_tp *hndl, COMDB2BUF *s, const char *comd
17781783
CDB2DBCONFIG_ADDL_PATH[sizeof(CDB2DBCONFIG_ADDL_PATH) - 1] = '\0';
17791784
}
17801785
} else { /* host list */
1781-
if (tok && is_valid_int(tok)) {
1786+
if (tok && cdb2_is_valid_int(tok)) {
17821787
*dbnum = atoi(tok);
17831788
tok = strtok_r(NULL, " :,", &last);
17841789
}
@@ -1854,7 +1859,7 @@ static void read_comdb2db_cfg(cdb2_hndl_tp *hndl, COMDB2BUF *s, const char *comd
18541859
for (ii = 0; ii <= current_size; ii++)
18551860
cdb2_room_distance[ii] = INT_MAX;
18561861
while (tok != NULL) {
1857-
if (!is_valid_int(tok))
1862+
if (!cdb2_is_valid_int(tok))
18581863
break;
18591864
ii = atoi(tok);
18601865
if (ii == 0) {
@@ -1870,7 +1875,7 @@ static void read_comdb2db_cfg(cdb2_hndl_tp *hndl, COMDB2BUF *s, const char *comd
18701875
}
18711876
tok = strtok_r(NULL, " ,", &last);
18721877

1873-
if (tok && is_valid_int(tok))
1878+
if (tok && cdb2_is_valid_int(tok))
18741879
distance = atoi(tok);
18751880
else
18761881
continue;
@@ -1897,7 +1902,7 @@ static void read_comdb2db_cfg(cdb2_hndl_tp *hndl, COMDB2BUF *s, const char *comd
18971902
cdb2_alarm_unread_socket_data = value_on_off(tok, &err);
18981903
} else if (!cdb2_max_discard_records_set_from_env && (strcasecmp("max_discard_records", tok) == 0)) {
18991904
tok = strtok_r(NULL, " =:,", &last);
1900-
if (tok && is_valid_int(tok))
1905+
if (tok && cdb2_is_valid_int(tok))
19011906
cdb2_max_discard_records = atoi(tok);
19021907
} else if (!cdb2_flat_col_vals_set_from_env && strcasecmp("flat_col_vals", tok) == 0) {
19031908
if ((tok = strtok_r(NULL, " =:,", &last)) != NULL)
@@ -4614,6 +4619,10 @@ static int cdb2_send_query(cdb2_hndl_tp *hndl, cdb2_hndl_tp *event_hndl, COMDB2B
46144619
#if _LINUX_SOURCE
46154620
sqlquery.little_endian = 1;
46164621
#endif
4622+
if (hndl && hndl->is_tagged) {
4623+
sqlquery.has_is_tagged = 1;
4624+
sqlquery.is_tagged = 1;
4625+
}
46174626

46184627
sqlquery.n_bindvars = n_bindvars;
46194628
sqlquery.bindvars = bindvars;
@@ -5191,7 +5200,9 @@ int cdb2_close(cdb2_hndl_tp *hndl)
51915200
newsql_disconnect(hndl, hndl->sb, __LINE__);
51925201

51935202
if (hndl->firstresponse) {
5194-
cdb2__sqlresponse__free_unpacked(hndl->firstresponse, NULL);
5203+
free_raw_response(hndl);
5204+
if (hndl->firstresponse)
5205+
cdb2__sqlresponse__free_unpacked(hndl->firstresponse, NULL);
51955206
hndl->firstresponse = NULL;
51965207
free((void *)hndl->first_buf);
51975208
hndl->first_buf = NULL;
@@ -6005,6 +6016,17 @@ static void attach_to_handle(cdb2_hndl_tp *child, cdb2_hndl_tp *parent)
60056016
}
60066017
}
60076018

6019+
static void free_raw_response(cdb2_hndl_tp *hndl)
6020+
{
6021+
// Tagged requests receive a RESPONSE_HEADER__SQL_RESPONSE_RAW response that
6022+
// contains both the "header" and the row data. So the first response is
6023+
// also the last response and we only need to free one.
6024+
if (hndl->is_tagged && hndl->firstresponse && hndl->firstresponse == hndl->lastresponse) {
6025+
cdb2__sqlresponse__free_unpacked(hndl->firstresponse, NULL);
6026+
hndl->firstresponse = hndl->lastresponse = NULL;
6027+
}
6028+
}
6029+
60086030
static void pb_alloc_heuristic(cdb2_hndl_tp *hndl)
60096031
{
60106032
if (!cdb2_protobuf_heuristic)
@@ -8273,6 +8295,11 @@ static int get_connection_int(cdb2_hndl_tp *hndl, int *err)
82738295
if (get_dbinfo || *err)
82748296
return -1;
82758297
before_discovery(hndl);
8298+
if (strcmp(hndl->type, "configured") == 0 && hndl->num_hosts > 0) {
8299+
// Special setting of "configured" means the proxy generated a list of hosts in its config and we should
8300+
// use that. Don't try discovery or sockpool - use what's in the proxy config.
8301+
return 0;
8302+
}
82768303
COMDB2BUF *sb = sockpool_get(hndl);
82778304
after_discovery(hndl);
82788305
if (sb == NULL)
@@ -8827,6 +8854,8 @@ int cdb2_open(cdb2_hndl_tp **handle, const char *dbname, const char *type,
88278854
hndl->connected_host = -1;
88288855
hndl->send_stack = 0;
88298856
hndl->read_intrans_results = 1;
8857+
hndl->is_admin = (flags & CDB2_ADMIN);
8858+
hndl->is_tagged = (flags & CDB2_SET_TAGGED);
88308859

88318860
/* We don't do dbinfo if DIRECT_CPU. So we'd default peer SSL mode to
88328861
ALLOW. We will find it out later when we send SSL negotitaion packet
@@ -8836,8 +8865,6 @@ int cdb2_open(cdb2_hndl_tp **handle, const char *dbname, const char *type,
88368865
hndl->max_retries = MAX_RETRIES;
88378866
hndl->min_retries = MIN_RETRIES;
88388867

8839-
hndl->is_admin = (flags & CDB2_ADMIN);
8840-
88418868
if (cdb2_use_env_vars) {
88428869
hndl->db_default_type_override_env = 0;
88438870
hndl->sockpool_enabled = 0;

cdb2api/cdb2api.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ enum cdb2_hndl_alloc_flags {
4242
#endif
4343
CDB2_REQUIRE_FASTSQL = 512,
4444
CDB2_MASTER = 1024,
45-
CDB2_ALLOW_INCOHERENT = 2048
45+
CDB2_ALLOW_INCOHERENT = 2048,
46+
CDB2_SET_TAGGED = 4096
4647
};
4748

4849
enum cdb2_request_type {

cdb2api/cdb2api_hndl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,5 +236,6 @@ struct cdb2_hndl {
236236
CDB2SQLQUERY__IdentityBlob *id_blob;
237237
struct cdb2_stmt_types *stmt_types;
238238
RETRY_CALLBACK retry_clbk;
239+
int is_tagged;
239240
};
240241
#endif

cdb2api/cdb2api_int.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void cdb2_hndl_set_min_retries(cdb2_hndl_tp *hndl, int min_retries);
5252
int cdb2_get_comdb2db(char **comdb2db_name, char **comdb2db_class);
5353

5454
void cdb2_set_debug_trace(cdb2_hndl_tp *hndl);
55+
int cdb2_is_valid_int(const char *str);
5556
#endif
5657

5758
struct cdb2_identity {

0 commit comments

Comments
 (0)