Skip to content

Commit b6507b7

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

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

cdb2api/cdb2api.c

Lines changed: 26 additions & 3 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;
@@ -4614,6 +4615,10 @@ static int cdb2_send_query(cdb2_hndl_tp *hndl, cdb2_hndl_tp *event_hndl, COMDB2B
46144615
#if _LINUX_SOURCE
46154616
sqlquery.little_endian = 1;
46164617
#endif
4618+
if (hndl && hndl->is_tagged) {
4619+
sqlquery.has_is_tagged = 1;
4620+
sqlquery.is_tagged = 1;
4621+
}
46174622

46184623
sqlquery.n_bindvars = n_bindvars;
46194624
sqlquery.bindvars = bindvars;
@@ -5191,7 +5196,9 @@ int cdb2_close(cdb2_hndl_tp *hndl)
51915196
newsql_disconnect(hndl, hndl->sb, __LINE__);
51925197

51935198
if (hndl->firstresponse) {
5194-
cdb2__sqlresponse__free_unpacked(hndl->firstresponse, NULL);
5199+
free_raw_response(hndl);
5200+
if (hndl->firstresponse)
5201+
cdb2__sqlresponse__free_unpacked(hndl->firstresponse, NULL);
51955202
hndl->firstresponse = NULL;
51965203
free((void *)hndl->first_buf);
51975204
hndl->first_buf = NULL;
@@ -6005,6 +6012,17 @@ static void attach_to_handle(cdb2_hndl_tp *child, cdb2_hndl_tp *parent)
60056012
}
60066013
}
60076014

6015+
static void free_raw_response(cdb2_hndl_tp *hndl)
6016+
{
6017+
// Tagged requests receive a RESPONSE_HEADER__SQL_RESPONSE_RAW response that
6018+
// contains both the "header" and the row data. So the first response is
6019+
// also the last response and we only need to free one.
6020+
if (hndl->is_tagged && hndl->firstresponse && hndl->firstresponse == hndl->lastresponse) {
6021+
cdb2__sqlresponse__free_unpacked(hndl->firstresponse, NULL);
6022+
hndl->firstresponse = hndl->lastresponse = NULL;
6023+
}
6024+
}
6025+
60086026
static void pb_alloc_heuristic(cdb2_hndl_tp *hndl)
60096027
{
60106028
if (!cdb2_protobuf_heuristic)
@@ -8273,6 +8291,11 @@ static int get_connection_int(cdb2_hndl_tp *hndl, int *err)
82738291
if (get_dbinfo || *err)
82748292
return -1;
82758293
before_discovery(hndl);
8294+
if (strcmp(hndl->type, "configured") == 0 && hndl->num_hosts > 0) {
8295+
// Special setting of "configured" means the proxy generated a list of hosts in its config and we should
8296+
// use that. Don't try discovery or sockpool - use what's in the proxy config.
8297+
return 0;
8298+
}
82768299
COMDB2BUF *sb = sockpool_get(hndl);
82778300
after_discovery(hndl);
82788301
if (sb == NULL)
@@ -8827,6 +8850,8 @@ int cdb2_open(cdb2_hndl_tp **handle, const char *dbname, const char *type,
88278850
hndl->connected_host = -1;
88288851
hndl->send_stack = 0;
88298852
hndl->read_intrans_results = 1;
8853+
hndl->is_admin = (flags & CDB2_ADMIN);
8854+
hndl->is_tagged = (flags & CDB2_SET_TAGGED);
88308855

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

8839-
hndl->is_admin = (flags & CDB2_ADMIN);
8840-
88418864
if (cdb2_use_env_vars) {
88428865
hndl->db_default_type_override_env = 0;
88438866
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

0 commit comments

Comments
 (0)