Skip to content

Commit

Permalink
rework to avoid changing clnt->sql
Browse files Browse the repository at this point in the history
Signed-off-by: Aakash Arayambeth <[email protected]>
  • Loading branch information
Aakash Arayambeth committed Oct 21, 2024
1 parent 06fe4f6 commit c1480cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
4 changes: 3 additions & 1 deletion db/reqlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,6 @@ inline void reqlog_set_sql(struct reqlogger *logger, struct string_ref *sr)
put_ref(&logger->sql_ref);
if (sr) {
logger->sql_ref = get_ref(sr);
reqlog_logf(logger, REQL_INFO, "sql=%s", string_ref_cstr(logger->sql_ref));
}
}

Expand Down Expand Up @@ -2189,6 +2188,9 @@ void reqlog_end_request(struct reqlogger *logger, int rc, const char *callfunc,
long_request_thresh = long_request_ms;
}

if (logger->sql_ref)
reqlog_logf(logger, REQL_INFO, "sql=%s", string_ref_cstr(logger->sql_ref));

if (logger->durationus >= M2U(long_request_thresh)) {
if (logger->clnt) {
log_params(logger);
Expand Down
12 changes: 1 addition & 11 deletions lua/sp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2200,16 +2200,6 @@ static int dbstmt_bind_int(Lua lua, dbstmt_t *dbstmt)
return stmt_bind(lua, dbstmt->stmt);
}

static void lua_set_clnt_sql(struct sqlclntstate *clnt, char *sql) {
if (!clnt || !sql) return;
clnt->sql = sql;
}

static void lua_set_clnt_origin(struct sqlclntstate *clnt, char *origin) {
if (!clnt || !origin) return;
clnt->origin = origin;
}

static int lua_prepare_sql_int(SP sp, const char *sql, sqlite3_stmt **stmt,
struct sql_state *rec, int flags)
{
Expand All @@ -2225,7 +2215,6 @@ static int lua_prepare_sql_int(SP sp, const char *sql, sqlite3_stmt **stmt,
print events (see reqlog_logv_int) in the logger. */
reqlog_reset_logger(sp->thd->logger);
reqlog_set_origin(sp->thd->logger, "%s", sp->clnt->origin);
lua_set_clnt_sql(sp->clnt, (char *)sql);
retry:
memset(&err, 0, sizeof(struct errstat));
if (sp->initial) {
Expand All @@ -2238,6 +2227,7 @@ static int lua_prepare_sql_int(SP sp, const char *sql, sqlite3_stmt **stmt,
sp->rc = get_prepared_stmt_try_lock(sp->thd, sp->clnt, rec_ptr, &err, flags & ~PREPARE_RECREATE);
}
sp->initial = 0;
reqlog_set_sql(sp->thd->logger, create_string_ref(sql));
if ((sp->rc == SQLITE_PERM) && (maxRetries != 0) &&
((maxRetries == -1) || (nRetry++ < maxRetries))) {
int sleepms = ATOMIC_LOAD32(gbl_lua_prepare_retry_sleep);
Expand Down

0 comments on commit c1480cd

Please sign in to comment.