Skip to content

Commit d0cc93d

Browse files
committed
Track API history for tagged requests
Signed-off-by: Mike Ponomarenko <mponomarenko@bloomberg.net>
1 parent 00c3cf2 commit d0cc93d

9 files changed

Lines changed: 19 additions & 12 deletions

File tree

db/api_history.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static char *toLower(char *str)
5151
return str;
5252
}
5353

54-
static api_driver_t *create_entry(char *api_driver_name, char *api_driver_version)
54+
static api_driver_t *create_entry(const char *api_driver_name, const char *api_driver_version)
5555
{
5656
const char default_value[] = "unknown";
5757
api_driver_t *entry = malloc(sizeof(api_driver_t));
@@ -97,13 +97,12 @@ int get_num_api_history_entries(struct rawnodestats *stats)
9797
return num;
9898
}
9999

100-
int update_api_history(struct sqlclntstate *clnt)
100+
int update_api_history(struct rawnodestats *stats, const char *api_driver_name, const char *api_driver_version)
101101
{
102-
assert(clnt && clnt->rawnodestats);
103-
struct rawnodestats *stats = clnt->rawnodestats;
102+
assert(stats);
104103

105104
Pthread_mutex_lock(&stats->lk);
106-
api_driver_t *search_entry = create_entry(clnt->api_driver_name, clnt->api_driver_version);
105+
api_driver_t *search_entry = create_entry(api_driver_name, api_driver_version);
107106
api_driver_t *found_entry = hash_find(stats->api_history, search_entry);
108107

109108
if (found_entry) {

db/api_history.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ struct rawnodestats;
3434
api_history_t *init_api_history();
3535
void free_api_history(api_history_t *);
3636
int get_num_api_history_entries(struct rawnodestats *);
37-
int update_api_history(struct sqlclntstate *);
37+
int update_api_history(struct rawnodestats *stats, const char *api_driver_name, const char *api_driver_version);
3838

3939
#endif

db/comdb2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,8 @@ struct ireq {
15111511
int has_ssl;
15121512
void *setup_data;
15131513
char *identity;
1514+
char *api_driver_name;
1515+
char *api_driver_version;
15141516
/* REVIEW COMMENTS AT BEGINING OF STRUCT BEFORE ADDING NEW VARIABLES */
15151517
};
15161518

db/reqlog.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,6 +2381,10 @@ void reqlog_end_request(struct reqlogger *logger, int rc, const char *callfunc,
23812381
norm_reqs++;
23822382
}
23832383

2384+
if (logger->iq && !logger->clnt) {
2385+
update_api_history(logger->iq->rawnodestats, logger->iq->api_driver_name, logger->iq->api_driver_version);
2386+
}
2387+
23842388
if (logger->iq && logger->iq->sorese) {
23852389
if (gbl_time_osql)
23862390
osql_bplog_time_done(&logger->iq->timings);

db/sltdbt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ int handle_ireq(struct ireq *iq)
595595
/* Free the sorese transaction buffer */
596596
free(iq->p_buf_out_start);
597597
} else {
598-
release_node_stats(NULL, NULL, iq->frommach);
598+
release_node_stats(iq->origin_argv0 ? iq->origin_argv0 : NULL, NULL, iq->frommach);
599599
}
600600
reqlog_end_request(iq->reqlogger, rc, __func__, __LINE__);
601601
if (gbl_print_deadlock_cycles)

db/sqlinterfaces.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ static void sql_statement_done(struct sql_thread *thd, struct reqlogger *logger,
13471347
if (have_fingerprint)
13481348
add_fingerprint_to_rawstats(clnt->rawnodestats, fingerprint, cost,
13491349
rows, time);
1350-
update_api_history(clnt);
1350+
update_api_history(clnt->rawnodestats, clnt->api_driver_name, clnt->api_driver_version);
13511351
}
13521352

13531353
reset_sql_steps(thd);
@@ -5283,7 +5283,7 @@ void cleanup_clnt(struct sqlclntstate *clnt)
52835283
}
52845284
_free_set_commands(clnt);
52855285
if (clnt->rawnodestats) {
5286-
release_node_stats(clnt->argv0, clnt->stack, clnt->origin);
5286+
release_node_stats(clnt->origin_argv0 ? clnt->origin_argv0 : clnt->argv0, clnt->stack, clnt->origin);
52875287
clnt->rawnodestats = NULL;
52885288
}
52895289
close_sp(clnt);
@@ -5444,7 +5444,7 @@ void reset_clnt(struct sqlclntstate *clnt, int initial)
54445444
clnt_try_enable_logdel(clnt);
54455445

54465446
if (clnt->rawnodestats) {
5447-
release_node_stats(clnt->argv0, clnt->stack, clnt->origin);
5447+
release_node_stats(clnt->origin_argv0 ? clnt->origin_argv0 : clnt->argv0, clnt->stack, clnt->origin);
54485448
clnt->rawnodestats = NULL;
54495449
}
54505450
clnt->recno = 1;

lua/sp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ static void lua_end_step(struct sqlclntstate *clnt, SP sp,
20402040
put_ref(&sql_ref);
20412041
if (clnt->rawnodestats) {
20422042
add_fingerprint_to_rawstats(clnt->rawnodestats, fingerprint, cost, pVdbe->luaRows, timeMs);
2043-
update_api_history(clnt);
2043+
update_api_history(clnt->rawnodestats, clnt->api_driver_name, clnt->api_driver_version);
20442044
}
20452045

20462046
clnt->spcost.cost += cost;

plugins/newsql/newsql.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2449,7 +2449,7 @@ newsql_loop_result newsql_loop(struct sqlclntstate *clnt, CDB2SQLQUERY *sql_quer
24492449
}
24502450
if (sql_query->client_info) {
24512451
if (clnt->rawnodestats) {
2452-
release_node_stats(clnt->argv0, clnt->stack, clnt->origin);
2452+
release_node_stats(clnt->origin_argv0 ? clnt->origin_argv0 : clnt->argv0, clnt->stack, clnt->origin);
24532453
clnt->rawnodestats = NULL;
24542454
}
24552455
if (clnt->conninfo.pid && clnt->conninfo.pid != sql_query->client_info->pid) {

plugins/newsql/newsql_evbuffer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ static void legacy_iq_setup(struct ireq *iq, void *setup_data)
467467
iq->has_ssl = clnt->plugin.has_ssl(clnt);
468468
iq->identity = clnt->plugin.get_identity(clnt);
469469
iq->origin_argv0 = clnt->origin_argv0;
470+
iq->api_driver_name = clnt->api_driver_name;
471+
iq->api_driver_version = clnt->api_driver_version;
470472
get_client_origin(iq->corigin, sizeof(iq->corigin), clnt);
471473
}
472474

0 commit comments

Comments
 (0)