Skip to content
Draft
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
6 changes: 0 additions & 6 deletions db/comdb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ int __berkdb_write_alarm_ms;
int __berkdb_read_alarm_ms;
int __berkdb_fsync_alarm_ms;

extern int gbl_delay_sql_lock_release_sec;

void __berkdb_set_num_read_ios(long long *n);
void __berkdb_set_num_write_ios(long long *n);
void __berkdb_set_num_fsyncs(long long *n);
Expand Down Expand Up @@ -5580,10 +5578,6 @@ static void register_all_int_switches()
register_int_switch("osql_odh_blob",
"Send ODH'd blobs to master. (Default: ON)",
&gbl_osql_odh_blob);
register_int_switch("delay_sql_lock_release",
"Delay release locks in cursor move if bdb lock "
"desired but client sends rows back",
&gbl_delay_sql_lock_release_sec);
register_int_switch("sqlite_makerecord_for_comdb2",
"Enable MakeRecord optimization which converts Mem to comdb2 row data directly",
&gbl_sqlite_makerecord_for_comdb2);
Expand Down
38 changes: 15 additions & 23 deletions db/sqlglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@

#include "views.h"

int gbl_delay_sql_lock_release_sec = 5;

unsigned long long get_id(bdb_state_type *);
static void unlock_bdb_cursors(struct sql_thread *thd, bdb_cursor_ifn_t *bdbcur, int *bdberr);

Expand Down Expand Up @@ -681,27 +679,6 @@ static int sql_tick(struct sql_thread *thd, int no_recover_deadlock)
goto done;
}

if ((rc = check_recover_deadlock(clnt)))
goto done;

if (clnt->in_sqlite_init == 0) {
if (no_recover_deadlock == 0) {
if ((gbl_epoch_time - clnt->last_sent_row_sec) >= gbl_delay_sql_lock_release_sec) {

rc = clnt_check_bdb_lock_desired(clnt);

} else if (gbl_sql_random_release_interval && !(rand() % gbl_sql_random_release_interval)) {

rc = recover_deadlock(thedb->bdb_env, clnt, NULL, 0);

if ((rc = check_recover_deadlock(clnt)))
goto done;

logmsg(LOGMSG_DEBUG, "%s recovered deadlock\n", __func__);
}
}
}

if (check_sql_client_disconnect(clnt, __FILE__, __LINE__)) {
rc = SQLITE_ABORT;
goto done;
Expand All @@ -712,6 +689,21 @@ static int sql_tick(struct sql_thread *thd, int no_recover_deadlock)
goto done;
}

if (clnt->in_sqlite_init || no_recover_deadlock) {
rc = 0;
goto done;
}

if (clnt->dbtran.mode > TRANLEVEL_RECOM) {
int do_da_recover(struct sqlclntstate *clnt);
rc = do_da_recover(clnt);
} else if (gbl_sql_random_release_interval && !(rand() % gbl_sql_random_release_interval)) {
recover_deadlock(thedb->bdb_env, clnt, NULL, 0);
rc = check_recover_deadlock(clnt);
} else {
rc = check_recover_deadlock(clnt);
}

done:
Pthread_mutex_unlock(&clnt->sql_tick_lk);
return rc;
Expand Down
33 changes: 21 additions & 12 deletions db/sqlinterfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,23 +355,32 @@ void unlock_client_write_lock(struct sqlclntstate *clnt)
Pthread_mutex_unlock(&clnt->write_lock);
}

int do_da_recover(struct sqlclntstate *clnt)
{
struct timeval now, diff;
gettimeofday(&now, NULL);
timersub(&now, &clnt->last_sql_recover_time, &diff);
int64_t ms = diff.tv_sec * 1000 - diff.tv_usec / 1000;
if (ms >= gbl_sql_recover_time) {
clnt->last_sql_recover_time = now;
if (recover_deadlock_evbuffer(clnt) != 0) {
logmsg(LOGMSG_ERROR, "%s recover_deadlock failed sql:%32s\n", __func__, clnt->sql);
return -1;
} else {
logmsg(LOGMSG_ERROR, "%s recover_deadlock done sql:%32s now:%zd\n", __func__, clnt->sql, ms);
}
}
return 0;
}

int write_response(struct sqlclntstate *clnt, int R, void *D, int I)
{
#ifdef DEBUG
logmsg(LOGMSG_DEBUG, "write_response(%s,%p,%d)\n", WriteRespString[R], D, I);
#endif
if (gbl_sql_recover_time && R == RESPONSE_ROW) {
/* TODO: Also do this for OP_SorterInsert */
struct timeval now, diff;
gettimeofday(&now, NULL);
timersub(&now, &clnt->last_sql_recover_time, &diff);
int64_t ms = diff.tv_sec * 1000 - diff.tv_usec / 1000;
if (ms >= gbl_sql_recover_time) {
clnt->last_sql_recover_time = now;
if (recover_deadlock_evbuffer(clnt) != 0) {
logmsg(LOGMSG_ERROR, "%s recover_deadlock failed sql:%32s\n", __func__, clnt->sql);
return -1;
}
if (gbl_sql_recover_time && R == RESPONSE_ROW) { /* TODO: Also do this for OP_SorterInsert */
if (do_da_recover(clnt)) {
return -1;
}
}
return clnt->plugin.write_response(clnt, R, D, I); /* newsql_write_response */
Expand Down
1 change: 0 additions & 1 deletion docs/pages/config/config_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,6 @@ These options are toggle-able at runtime.
|debugthreads | off | If set to 'on' enables trace on thread events.
|decimal_rounding | DEC_ROUND_HALF_EVEN | See [decimal rounding options](#decimal-rounding-options)
|default_sql_mspace_kbsz | 1024 | Default size of memory regions owned by SQL threads, in KB
|delay_sql_lock_release| 1 | Delay release locks in cursor move if bdb lock desired but client sends rows back
|disable_cache_internal_nodes | | Disable enable_cache_internal_nodes
|disable_inplace_blob_optimization | | Disables enable_inplace_blob_optimization
|disable_inplace_blobs | | Disables enable_inplace_blobs (needs enable_inplace_blob_optimization, and enable_osql_blob_optimization also enabled - which they are by default)
Expand Down
3 changes: 1 addition & 2 deletions tests/reco-ddlk-sql.test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ else
include $(TESTSROOTDIR)/testcase.mk
endif
ifeq ($(TEST_TIMEOUT),)
export TEST_TIMEOUT=10m
export TEST_TIMEOUT=20m
endif
#export SP_OPTIONS=-s --cdb2cfg $(CDB2_CONFIG) $(DBNAME) default
4 changes: 4 additions & 0 deletions tests/reco-ddlk-sql.test/snapshot.testopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cache 1 gb
do debug recover_deadlock_evbuffer
enable_snapshot_isolation
sql_tranlevel_default snapshot
1 change: 0 additions & 1 deletion tests/tunables.test/t00_all_tunables.expected
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
(name='delay_after_saveop_done', description='', type='INTEGER', value='0', read_only='N')
(name='delay_after_saveop_usedb', description='', type='INTEGER', value='0', read_only='N')
(name='delay_file_open', description='', type='INTEGER', value='0', read_only='N')
(name='delay_sql_lock_release', description='Delay release locks in cursor move if bdb lock desired but client sends rows back', type='BOOLEAN', value='ON', read_only='N')
(name='delay_writes_in_record_c', description='', type='INTEGER', value='0', read_only='N')
(name='delayed_oldfile_cleanup', description='If set, don't delete unused data/index files in the critical path of schema change; schedule them for deletion later.', type='BOOLEAN', value='ON', read_only='N')
(name='delete_old_file_debug', description='Spew debug info about deleting old files.', type='BOOLEAN', value='OFF', read_only='N')
Expand Down
Loading