Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion cdb2api/cdb2api.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ static int refresh_gbl_events_on_hndl(cdb2_hndl_tp *);
static int cdb2_get_dbhosts(cdb2_hndl_tp *);
static void hndl_set_comdb2buf(cdb2_hndl_tp *, COMDB2BUF *);
static int send_reset(COMDB2BUF *sb, int localcache);
static void free_raw_response(cdb2_hndl_tp *hndl);

static int check_hb_on_blocked_write = 0; // temporary switch - this will be default behavior
static int check_hb_on_blocked_write_set_from_env = 0;
Expand Down Expand Up @@ -4281,6 +4282,7 @@ static int cdb2_convert_error_code(int rc)

static void clear_responses(cdb2_hndl_tp *hndl)
{
free_raw_response(hndl);
if (hndl->lastresponse) {
cdb2__sqlresponse__free_unpacked(hndl->lastresponse, hndl->allocator);
if (hndl->protobuf_size)
Expand Down Expand Up @@ -4585,6 +4587,10 @@ static int cdb2_send_query(cdb2_hndl_tp *hndl, cdb2_hndl_tp *event_hndl, COMDB2B
#if _LINUX_SOURCE
sqlquery.little_endian = 1;
#endif
if (hndl) {
sqlquery.has_is_tagged = 1;
sqlquery.is_tagged = hndl->is_tagged;
}

sqlquery.n_bindvars = n_bindvars;
sqlquery.bindvars = bindvars;
Expand Down Expand Up @@ -4687,6 +4693,9 @@ static int cdb2_send_query(cdb2_hndl_tp *hndl, cdb2_hndl_tp *event_hndl, COMDB2B
sqlquery.has_skip_rows = 1;
sqlquery.skip_rows = skip_nrows;
}
if (hndl) {
sqlquery.is_tagged = hndl->is_tagged;
}

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

if (hndl->firstresponse) {
cdb2__sqlresponse__free_unpacked(hndl->firstresponse, NULL);
free_raw_response(hndl);
if (hndl->firstresponse)
cdb2__sqlresponse__free_unpacked(hndl->firstresponse, NULL);
hndl->firstresponse = NULL;
free((void *)hndl->first_buf);
hndl->first_buf = NULL;
Expand Down Expand Up @@ -5965,6 +5976,22 @@ static void attach_to_handle(cdb2_hndl_tp *child, cdb2_hndl_tp *parent)
}
}

static void free_raw_response(cdb2_hndl_tp *hndl)
{
// Tagged requests receive a RESPONSE_HEADER__SQL_RESPONSE_RAW response that
// contains both the "header" and the row data. So the first response is
// also the last response and we only need to free one.
if (hndl->is_tagged && hndl->firstresponse && hndl->firstresponse == hndl->lastresponse) {
free(hndl->firstresponse->value[0]->value.data);
free(hndl->firstresponse->value[1]->value.data);
free(hndl->firstresponse->value[0]);
free(hndl->firstresponse->value[1]);
free(hndl->firstresponse->value);
free(hndl->firstresponse);
hndl->firstresponse = hndl->lastresponse = NULL;
}
}

static void pb_alloc_heuristic(cdb2_hndl_tp *hndl)
{
if (!cdb2_protobuf_heuristic)
Expand Down Expand Up @@ -8227,6 +8254,11 @@ static int get_connection_int(cdb2_hndl_tp *hndl, int *err)
before_discovery(hndl);
COMDB2BUF *sb = sockpool_get(hndl);
after_discovery(hndl);
if (sb == NULL && strcmp(hndl->type, "configured") == 0 && hndl->num_hosts > 0) {
// Special setting of "configured" means the proxy generated a list of hosts in its config and we should·
// use that. Don't try discovery - use what's in the proxy config.
return 0;
}
if (sb == NULL)
return -1;
return init_connection(hndl, sb);
Expand Down Expand Up @@ -8781,6 +8813,7 @@ int cdb2_open(cdb2_hndl_tp **handle, const char *dbname, const char *type,

hndl->env_tz = getenv("COMDB2TZ");
hndl->is_admin = (flags & CDB2_ADMIN);
hndl->is_tagged = (flags & CDB2_SET_TAGGED);

if (hndl->env_tz == NULL)
hndl->env_tz = getenv("TZ");
Expand Down
3 changes: 2 additions & 1 deletion cdb2api/cdb2api.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ enum cdb2_hndl_alloc_flags {
#endif
CDB2_REQUIRE_FASTSQL = 512,
CDB2_MASTER = 1024,
CDB2_ALLOW_INCOHERENT = 2048
CDB2_ALLOW_INCOHERENT = 2048,
CDB2_SET_TAGGED = 4096
};

enum cdb2_request_type {
Expand Down
1 change: 1 addition & 0 deletions cdb2api/cdb2api_hndl.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,6 @@ struct cdb2_hndl {
CDB2SQLQUERY__IdentityBlob *id_blob;
struct cdb2_stmt_types *stmt_types;
RETRY_CALLBACK retry_clbk;
int is_tagged;
};
#endif