Skip to content

Commit 575a2a3

Browse files
committed
Allow optional comdb2_legacy parameter to track tag origin.
Signed-off-by: Mike Ponomarenko <mponomarenko@bloomberg.net>
1 parent bfaa756 commit 575a2a3

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

db/comdb2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,7 @@ struct ireq {
15051505
// in an inline call to handle_buf
15061506
void *authdata;
15071507
char *argv0;
1508+
char *origin_argv0;
15081509
int has_ssl;
15091510
void *setup_data;
15101511
char *identity;

db/sltdbt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ int handle_ireq(struct ireq *iq)
428428
req2a(iq->opcode));
429429

430430
if (!iq->sorese) /* don't count osql */
431-
iq->rawnodestats =
432-
get_raw_node_stats(NULL, NULL, iq->frommach, cdb2buf_fileno(iq->sb), 0 /* tag does not support ssl */);
431+
iq->rawnodestats = get_raw_node_stats(iq->origin_argv0 ? iq->origin_argv0 : NULL, NULL, iq->frommach,
432+
cdb2buf_fileno(iq->sb), 0 /* tag does not support ssl */);
433433
if (iq->rawnodestats && iq->opcode >= 0 && iq->opcode < MAXTYPCNT)
434434
iq->rawnodestats->opcode_counts[iq->opcode]++;
435435
if (gbl_print_deadlock_cycles && IQ_HAS_SNAPINFO(iq))

db/sql.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ struct sqlclntstate {
10851085

10861086
// this is not an SQL request, distpatch it elsewhere
10871087
int is_tagged;
1088+
char *origin_argv0;
10881089

10891090
unsigned blocking_tranlog : 1;
10901091
};

db/sqlinterfaces.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5348,6 +5348,8 @@ void cleanup_clnt(struct sqlclntstate *clnt)
53485348
if (clnt->modsnap_in_progress) {
53495349
clear_modsnap_state(clnt);
53505350
}
5351+
free(clnt->origin_argv0);
5352+
clnt->origin_argv0 = NULL;
53515353

53525354
reset_authz_hash(clnt, 1);
53535355
}

plugins/newsql/newsql_evbuffer.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ static void legacy_iq_setup(struct ireq *iq, void *setup_data)
455455
iq->setup_data = setup_data;
456456
iq->has_ssl = clnt->plugin.has_ssl(clnt);
457457
iq->identity = clnt->plugin.get_identity(clnt);
458+
iq->origin_argv0 = clnt->origin_argv0;
458459
get_client_origin(iq->corigin, sizeof(iq->corigin), clnt);
459460
}
460461

@@ -468,6 +469,12 @@ static int dispatch_tagged(struct sqlclntstate *clnt)
468469
p_slock = pool_getablk(p_slocks);
469470
Pthread_mutex_unlock(&buf_lock);
470471

472+
if (appdata->sqlquery == NULL || appdata->sqlquery->n_bindvars < 3 || appdata->sqlquery->bindvars[0] == NULL ||
473+
appdata->sqlquery->bindvars[1] == NULL || appdata->sqlquery->bindvars[1]->value.len != sizeof(int) ||
474+
appdata->sqlquery->bindvars[2] == NULL || appdata->sqlquery->bindvars[2]->value.len != sizeof(int)) {
475+
return 1;
476+
}
477+
471478
void *buf = appdata->sqlquery->bindvars[0]->value.data;
472479
int sz = appdata->sqlquery->bindvars[0]->value.len;
473480

@@ -479,10 +486,18 @@ static int dispatch_tagged(struct sqlclntstate *clnt)
479486
p_slock->reply_state = REPLY_STATE_NA;
480487

481488
clnt->authdata = get_authdata(clnt);
482-
if (appdata->sqlquery == NULL || appdata->sqlquery->n_bindvars < 3 || appdata->sqlquery->bindvars[0] == NULL ||
483-
appdata->sqlquery->bindvars[1] == NULL || appdata->sqlquery->bindvars[1]->value.len != sizeof(int) ||
484-
appdata->sqlquery->bindvars[2] == NULL || appdata->sqlquery->bindvars[2]->value.len != sizeof(int)) {
485-
return 1;
489+
490+
if (appdata->sqlquery->n_bindvars > 3 && appdata->sqlquery->bindvars[3] &&
491+
appdata->sqlquery->bindvars[3]->value.data) {
492+
// note - we specifically don't override clnt->argv0 here - we want
493+
// the original sender (typically the proxy) there, and we save on whose behalf we're
494+
// proxying elsewhere.
495+
if (clnt->origin_argv0) {
496+
free(clnt->origin_argv0);
497+
clnt->origin_argv0 = NULL;
498+
}
499+
clnt->origin_argv0 =
500+
strndup((char *)appdata->sqlquery->bindvars[3]->value.data, appdata->sqlquery->bindvars[3]->value.len);
486501
}
487502

488503
int luxref;

0 commit comments

Comments
 (0)