Skip to content

Commit 620cc9c

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

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

cdb2api/cdb2api.c

Lines changed: 34 additions & 1 deletion
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,10 @@ 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+
}
45884594

45894595
sqlquery.n_bindvars = n_bindvars;
45904596
sqlquery.bindvars = bindvars;
@@ -4687,6 +4693,9 @@ static int cdb2_send_query(cdb2_hndl_tp *hndl, cdb2_hndl_tp *event_hndl, COMDB2B
46874693
sqlquery.has_skip_rows = 1;
46884694
sqlquery.skip_rows = skip_nrows;
46894695
}
4696+
if (hndl) {
4697+
sqlquery.is_tagged = hndl->is_tagged;
4698+
}
46904699

46914700
uint8_t trans_append = hndl && hndl->in_trans && do_append;
46924701
CDB2SQLQUERY__Reqinfo req_info = CDB2__SQLQUERY__REQINFO__INIT;
@@ -5151,7 +5160,9 @@ int cdb2_close(cdb2_hndl_tp *hndl)
51515160
newsql_disconnect(hndl, hndl->sb, __LINE__);
51525161

51535162
if (hndl->firstresponse) {
5154-
cdb2__sqlresponse__free_unpacked(hndl->firstresponse, NULL);
5163+
free_raw_response(hndl);
5164+
if (hndl->firstresponse)
5165+
cdb2__sqlresponse__free_unpacked(hndl->firstresponse, NULL);
51555166
hndl->firstresponse = NULL;
51565167
free((void *)hndl->first_buf);
51575168
hndl->first_buf = NULL;
@@ -5965,6 +5976,22 @@ static void attach_to_handle(cdb2_hndl_tp *child, cdb2_hndl_tp *parent)
59655976
}
59665977
}
59675978

5979+
static void free_raw_response(cdb2_hndl_tp *hndl)
5980+
{
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,6 +8254,11 @@ 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);
8257+
if (sb == NULL && 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+
}
82308262
if (sb == NULL)
82318263
return -1;
82328264
return init_connection(hndl, sb);
@@ -8781,6 +8813,7 @@ int cdb2_open(cdb2_hndl_tp **handle, const char *dbname, const char *type,
87818813

87828814
hndl->env_tz = getenv("COMDB2TZ");
87838815
hndl->is_admin = (flags & CDB2_ADMIN);
8816+
hndl->is_tagged = (flags & CDB2_SET_TAGGED);
87848817

87858818
if (hndl->env_tz == NULL)
87868819
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)