Skip to content

Commit 32a26b8

Browse files
committed
Port over internal cdb2api changes
Signed-off-by: Michael Ponomarenko <mponomarenko@bloomberg.net>
1 parent 575a2a3 commit 32a26b8

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

cdb2api/cdb2api.c

Lines changed: 35 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 *);
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;
@@ -4281,6 +4282,7 @@ static int cdb2_convert_error_code(int rc)
42814282

42824283
static void clear_responses(cdb2_hndl_tp *hndl)
42834284
{
4285+
free_raw_response(hndl);
42844286
if (hndl->lastresponse) {
42854287
cdb2__sqlresponse__free_unpacked(hndl->lastresponse, hndl->allocator);
42864288
if (hndl->protobuf_size)
@@ -4585,6 +4587,11 @@ static int cdb2_send_query(cdb2_hndl_tp *hndl, cdb2_hndl_tp *event_hndl, COMDB2B
45854587
#if _LINUX_SOURCE
45864588
sqlquery.little_endian = 1;
45874589
#endif
4590+
if (hndl) {
4591+
sqlquery.has_is_tagged = 1;
4592+
sqlquery.is_tagged = hndl->is_tagged;
4593+
}
4594+
45884595

45894596
sqlquery.n_bindvars = n_bindvars;
45904597
sqlquery.bindvars = bindvars;
@@ -4687,6 +4694,9 @@ static int cdb2_send_query(cdb2_hndl_tp *hndl, cdb2_hndl_tp *event_hndl, COMDB2B
46874694
sqlquery.has_skip_rows = 1;
46884695
sqlquery.skip_rows = skip_nrows;
46894696
}
4697+
if (hndl) {
4698+
sqlquery.is_tagged = hndl->is_tagged;
4699+
}
46904700

46914701
uint8_t trans_append = hndl && hndl->in_trans && do_append;
46924702
CDB2SQLQUERY__Reqinfo req_info = CDB2__SQLQUERY__REQINFO__INIT;
@@ -5151,7 +5161,9 @@ int cdb2_close(cdb2_hndl_tp *hndl)
51515161
newsql_disconnect(hndl, hndl->sb, __LINE__);
51525162

51535163
if (hndl->firstresponse) {
5154-
cdb2__sqlresponse__free_unpacked(hndl->firstresponse, NULL);
5164+
free_raw_response(hndl);
5165+
if (hndl->firstresponse)
5166+
cdb2__sqlresponse__free_unpacked(hndl->firstresponse, NULL);
51555167
hndl->firstresponse = NULL;
51565168
free((void *)hndl->first_buf);
51575169
hndl->first_buf = NULL;
@@ -5965,6 +5977,21 @@ static void attach_to_handle(cdb2_hndl_tp *child, cdb2_hndl_tp *parent)
59655977
}
59665978
}
59675979

5980+
static void free_raw_response(cdb2_hndl_tp *hndl) {
5981+
// Tagged requests receive a RESPONSE_HEADER__SQL_RESPONSE_RAW response that
5982+
// contains both the "header" and the row data. So the first response is
5983+
// also the last response and we only need to free one.
5984+
if (hndl->is_tagged && hndl->firstresponse && hndl->firstresponse == hndl->lastresponse) {
5985+
free(hndl->firstresponse->value[0]->value.data);
5986+
free(hndl->firstresponse->value[1]->value.data);
5987+
free(hndl->firstresponse->value[0]);
5988+
free(hndl->firstresponse->value[1]);
5989+
free(hndl->firstresponse->value);
5990+
free(hndl->firstresponse);
5991+
hndl->firstresponse = hndl->lastresponse = NULL;
5992+
}
5993+
}
5994+
59685995
static void pb_alloc_heuristic(cdb2_hndl_tp *hndl)
59695996
{
59705997
if (!cdb2_protobuf_heuristic)
@@ -8227,8 +8254,12 @@ static int get_connection_int(cdb2_hndl_tp *hndl, int *err)
82278254
before_discovery(hndl);
82288255
COMDB2BUF *sb = sockpool_get(hndl);
82298256
after_discovery(hndl);
8230-
if (sb == NULL)
8231-
return -1;
8257+
if (sb == NULL && hndl->type && strcmp(hndl->type, "configured") == 0 && hndl->num_hosts > 0) {
8258+
// Special setting of "configured" means the proxy generated a list of hosts in its config and we should·
8259+
// use that. Don't try discovery - use what's in the proxy config.
8260+
return 0;
8261+
}
8262+
if (sb == NULL) return -1;
82328263
return init_connection(hndl, sb);
82338264
}
82348265

@@ -8781,6 +8812,7 @@ int cdb2_open(cdb2_hndl_tp **handle, const char *dbname, const char *type,
87818812

87828813
hndl->env_tz = getenv("COMDB2TZ");
87838814
hndl->is_admin = (flags & CDB2_ADMIN);
8815+
hndl->is_tagged = (flags & CDB2_SET_TAGGED);
87848816

87858817
if (hndl->env_tz == NULL)
87868818
hndl->env_tz = getenv("TZ");

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
@@ -237,5 +237,6 @@ struct cdb2_hndl {
237237
CDB2SQLQUERY__IdentityBlob *id_blob;
238238
struct cdb2_stmt_types *stmt_types;
239239
RETRY_CALLBACK retry_clbk;
240+
int is_tagged;
240241
};
241242
#endif

0 commit comments

Comments
 (0)