Skip to content

Commit c294b2e

Browse files
committed
serial-commit requires the bdb-lock
selectv precheck is an optimization Signed-off-by: Mark Hannum <[email protected]>
1 parent 28f580b commit c294b2e

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

bdb/serializable.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,12 @@ static int osql_serial_check(bdb_state_type *bdb_state, void *ranges,
432432
/* find the next valid commit (prev_lsn of DB___txn_regop points to
433433
* DB_llog_ltran_commit) */
434434
while (1) {
435+
if (bdb_lock_desired(bdb_state)) {
436+
logmsg(LOGMSG_ERROR, "bdb-lock desired, halting serial check\n");
437+
logmsg(LOGMSG_ERROR, "@ file: %d, offset %d\n", seriallsn.file, seriallsn.offset);
438+
rc = -99;
439+
goto done;
440+
}
435441
if (logdta.data) {
436442
free(logdta.data);
437443
logdta.data = NULL;

db/sqloffload.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,24 +223,31 @@ static int rese_commit(struct sqlclntstate *clnt, struct sql_thread *thd,
223223
int sentops = 0;
224224
int bdberr = 0;
225225
int rc = 0;
226+
int serial_rc = 0;
226227
int usedb_only = 0;
227228
int force_master = gbl_serialize_reads_like_writes;
229+
bdb_state_type *bdb_state = thedb->bdb_env;
230+
231+
/* get_rep_gen & serial_check call into berkley */
232+
BDB_READLOCK("rese_commit");
228233

229234
if (gbl_early_verify && !clnt->early_retry && gbl_osql_send_startgen &&
230235
clnt->start_gen) {
231236
if (clnt->start_gen != bdb_get_rep_gen(thedb->bdb_env))
232237
clnt->early_retry = EARLY_ERR_GENCHANGE;
233238
}
234-
if (clnt->selectv_arr)
239+
/* selectv pre-check optimization */
240+
if (clnt->early_retry == 0 && clnt->selectv_arr && (force_master || !osql_shadtbl_empty(clnt))) {
235241
currangearr_build_hash(clnt->selectv_arr);
236-
if (clnt->selectv_arr &&
237-
bdb_osql_serial_check(thedb->bdb_env, clnt->selectv_arr,
238-
&(clnt->selectv_arr->file),
239-
&(clnt->selectv_arr->offset), 0)) {
240-
clnt->osql.xerr.errval = ERR_CONSTR;
241-
errstat_cat_str(&(clnt->osql.xerr), "selectv constraints");
242-
rc = SQLITE_ABORT;
243-
} else if (clnt->early_retry == EARLY_ERR_VERIFY) {
242+
if ((serial_rc = bdb_osql_serial_check(thedb->bdb_env, clnt->selectv_arr, &(clnt->selectv_arr->file),
243+
&(clnt->selectv_arr->offset), 0)) != 0) {
244+
clnt->early_retry = (serial_rc == -99) ? EARLY_ERR_GENCHANGE : EARLY_ERR_SELECTV;
245+
}
246+
}
247+
248+
BDB_RELLOCK();
249+
250+
if (clnt->early_retry == EARLY_ERR_VERIFY) {
244251
if (clnt->dbtran.mode == TRANLEVEL_SERIAL) {
245252
clnt->osql.xerr.errval = ERR_NOTSERIAL;
246253
errstat_cat_str(&(clnt->osql.xerr),
@@ -253,7 +260,7 @@ static int rese_commit(struct sqlclntstate *clnt, struct sql_thread *thd,
253260
rc = SQLITE_ABORT;
254261
} else if (clnt->early_retry == EARLY_ERR_SELECTV) {
255262
clnt->osql.xerr.errval = ERR_CONSTR;
256-
errstat_cat_str(&(clnt->osql.xerr), "constraints error, no genid");
263+
errstat_cat_str(&(clnt->osql.xerr), "constraints error");
257264
rc = SQLITE_ABORT;
258265
} else if (clnt->early_retry == EARLY_ERR_GENCHANGE) {
259266
clnt->osql.xerr.errval = ERR_BLOCK_FAILED + ERR_VERIFY;

0 commit comments

Comments
 (0)