Skip to content

Commit 6948c01

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

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-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: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,24 +223,32 @@ 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 &&
241+
(force_master || !osql_shadtbl_empty(clnt))) {
235242
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) {
243+
if ((serial_rc = bdb_osql_serial_check(thedb->bdb_env, clnt->selectv_arr, &(clnt->selectv_arr->file),
244+
&(clnt->selectv_arr->offset), 0)) != 0) {
245+
clnt->early_retry = (serial_rc == -99) ? EARLY_ERR_GENCHANGE : EARLY_ERR_SELECTV;
246+
}
247+
}
248+
249+
BDB_RELLOCK();
250+
251+
if (clnt->early_retry == EARLY_ERR_VERIFY) {
244252
if (clnt->dbtran.mode == TRANLEVEL_SERIAL) {
245253
clnt->osql.xerr.errval = ERR_NOTSERIAL;
246254
errstat_cat_str(&(clnt->osql.xerr),
@@ -253,7 +261,7 @@ static int rese_commit(struct sqlclntstate *clnt, struct sql_thread *thd,
253261
rc = SQLITE_ABORT;
254262
} else if (clnt->early_retry == EARLY_ERR_SELECTV) {
255263
clnt->osql.xerr.errval = ERR_CONSTR;
256-
errstat_cat_str(&(clnt->osql.xerr), "constraints error, no genid");
264+
errstat_cat_str(&(clnt->osql.xerr), "constraints error");
257265
rc = SQLITE_ABORT;
258266
} else if (clnt->early_retry == EARLY_ERR_GENCHANGE) {
259267
clnt->osql.xerr.errval = ERR_BLOCK_FAILED + ERR_VERIFY;

0 commit comments

Comments
 (0)