Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't wait for likely leaked transactions on exit #4295

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions db/db_tunables.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ extern int gbl_timer_warn_interval;
int gbl_incoherent_clnt_wait = 0;
int gbl_new_leader_duration = 3;
extern int gbl_transaction_grace_period;
extern int gbl_transaction_grace_period_timeout;

/*
=========================================================
Expand Down
4 changes: 4 additions & 0 deletions db/db_tunables.h
Original file line number Diff line number Diff line change
Expand Up @@ -2497,5 +2497,9 @@ REGISTER_TUNABLE("transaction_grace_period",
"Time to wait for connections with pending transactions to go away on exit. (Default: 60)",
TUNABLE_INTEGER, &gbl_transaction_grace_period, 0, NULL, NULL, NULL, NULL);

REGISTER_TUNABLE("transaction_grace_period_timeout",
"Ignore transactions at exit older than this (seconds). (Default: 5min)",
TUNABLE_INTEGER, &gbl_transaction_grace_period_timeout, 0, NULL, NULL, NULL, NULL);


#endif /* _DB_TUNABLES_H */
1 change: 1 addition & 0 deletions db/sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,7 @@ struct connection_info {
int time_in_state_int;
enum connection_state state_int;
int64_t in_transaction;
char *argv0;
};

/* makes master swing verbose */
Expand Down
14 changes: 12 additions & 2 deletions db/sqlinterfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -6682,6 +6682,7 @@ static void gather_connection_int(struct connection_info *c, struct sqlclntstate
c->fingerprint = NULL;
}
c->in_transaction = clnt->in_client_trans;
c->argv0 = strdup(clnt->argv0);
Pthread_mutex_unlock(&clnt->state_lk);
}

Expand Down Expand Up @@ -6731,6 +6732,7 @@ void free_connection_info(struct connection_info *info, int num_connections)
for (int i = 0; i < num_connections; i++) {
if (info[i].sql) free(info[i].sql);
if (info[i].fingerprint) free(info[i].fingerprint);
if (info[i].argv0) free(info[i].argv0);
/* state is static, don't free */
}
free(info);
Expand Down Expand Up @@ -7166,15 +7168,18 @@ char *clnt_tzname(struct sqlclntstate *clnt, sqlite3_stmt *stmt)
}

int gbl_transaction_grace_period = 60;
int gbl_transaction_grace_period_timeout = 300 ;
void wait_for_transactions(void) {
int ntrans;
int nwaits = 0;
static int once = 1;


for (nwaits = 0; nwaits < gbl_transaction_grace_period; nwaits++) {
ntrans = 0;
struct connection_info *connections;
int nconnections;
int now = comdb2_time_epochms();

int rc = gather_connection_info(&connections, &nconnections);
if (rc) {
Expand All @@ -7183,15 +7188,20 @@ void wait_for_transactions(void) {
}
for (int i = 0; i < nconnections; i++) {
struct connection_info *c = &connections[i];
if (c->in_transaction) {
int runtime = (now - c->time_in_state_int) / 1000;
if (c->in_transaction && runtime < gbl_transaction_grace_period_timeout) {
ntrans++;
if (nwaits > 10) {
if (ntrans == 1)
logmsg(LOGMSG_INFO, "waiting for transactions:\n------------------------\n");
logmsg(LOGMSG_INFO, "open transaction on connection from %s pid %d\n", c->host, (int) c->pid);
logmsg(LOGMSG_INFO, "open transaction on connection from %s pid %d argv0 %s age %d seconds\n", c->host, (int) c->pid, c->argv0, runtime);
}
}
if (once && c->in_transaction && runtime >= gbl_transaction_grace_period_timeout) {
logmsg(LOGMSG_INFO, "old open transaction on connection from %s pid %d argv0 %s age %d seconds\n", c->host, (int) c->pid, c->argv0, runtime);
}
}
once = 0;
free_connection_info(connections, nconnections);
if (ntrans) {
if (nwaits > 10)
Expand Down
2 changes: 2 additions & 0 deletions sqlite/ext/comdb2/connections.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,7 @@ int systblConnectionsInit(sqlite3 *db) {
CDB2_INTEGER, "is_ssl", -1, offsetof(struct connection_info, is_ssl),
CDB2_INTEGER, "has_cert", -1, offsetof(struct connection_info, has_cert),
CDB2_CSTRING, "common_name", -1, offsetof(struct connection_info, common_name),
CDB2_CSTRING, "argv0", -1, offsetof(struct connection_info, argv0),
CDB2_INTEGER, "in_transaction", -1, offsetof(struct connection_info, in_transaction),
SYSTABLE_END_OF_FIELDS);
}
1 change: 1 addition & 0 deletions tests/tunables.test/t00_all_tunables.expected
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@
(name='track_replication_times_max_lsns', description='Track replication times for up to this many transactions.', type='INTEGER', value='50', read_only='N')
(name='tracked_locklist_init', description='Initial allocation count for tracked locks', type='INTEGER', value='10', read_only='N')
(name='transaction_grace_period', description='Time to wait for connections with pending transactions to go away on exit. (Default: 60)', type='INTEGER', value='60', read_only='N')
(name='transaction_grace_period_timeout', description='Ignore transactions at exit older than this (seconds). (Default: 5min)', type='INTEGER', value='300', read_only='N')
(name='transient_page_reallocation', description='Orphaned pages are maintained locally', type='BOOLEAN', value='OFF', read_only='N')
(name='typessql', description='Use typessql to attempt to buffer results until all columns are non-null. (Default: off)', type='BOOLEAN', value='OFF', read_only='N')
(name='typessql_records_max', description='The maximum number of records for typessql to buffer and find non-null types before giving up. (Default: 1000)', type='INTEGER', value='1000', read_only='N')
Expand Down