Commit 946e8dea authored by Yoni Fogel's avatar Yoni Fogel

Addresses #1691 Fix bug where abort(truncate) could crash us.

Remove transactions' need to count references to cachefiles (they already have references to brts)
Errors in rolling back certain functions were ignored (r = blah; return something_else);
They are now reported, so diskfull had to be updated to expect ENOSPC under certain circumstances.

git-svn-id: file:///svn/toku/tokudb@11371 c7de825b-a66e-492c-adef-691d508d4ae1
parent 558fcdb9
......@@ -2653,7 +2653,6 @@ int toku_brt_insert (BRT brt, DBT *key, DBT *val, TOKUTXN txn)
{
int r;
if (txn && (brt->h->txnid_that_created_or_locked_when_empty != toku_txn_get_txnid(txn))) {
toku_cachefile_refup(brt->cf);
BYTESTRING keybs = {key->size, toku_memdup_in_rollback(txn, key->data, key->size)};
int need_data = (brt->flags&TOKU_DB_DUPSORT)!=0; // dupsorts don't need the data part
if (need_data) {
......@@ -2676,7 +2675,6 @@ int toku_brt_delete(BRT brt, DBT *key, TOKUTXN txn) {
int r;
if (txn && (brt->h->txnid_that_created_or_locked_when_empty != toku_txn_get_txnid(txn))) {
BYTESTRING keybs = {key->size, toku_memdup_in_rollback(txn, key->data, key->size)};
toku_cachefile_refup(brt->cf);
r = toku_logger_save_rollback_cmddelete(txn, toku_txn_get_txnid(txn), toku_cachefile_filenum(brt->cf), keybs);
if (r!=0) return r;
r = toku_txn_note_brt(txn, brt);
......@@ -4421,7 +4419,6 @@ int toku_brt_delete_both(BRT brt, DBT *key, DBT *val, TOKUTXN txn) {
if (txn && (brt->h->txnid_that_created_or_locked_when_empty != toku_txn_get_txnid(txn))) {
BYTESTRING keybs = {key->size, toku_memdup_in_rollback(txn, key->data, key->size)};
BYTESTRING databs = {val->size, toku_memdup_in_rollback(txn, val->data, val->size)};
toku_cachefile_refup(brt->cf);
r = toku_logger_save_rollback_cmddeleteboth(txn, toku_txn_get_txnid(txn), toku_cachefile_filenum(brt->cf), keybs, databs);
if (r!=0) return r;
r = toku_txn_note_brt(txn, brt);
......@@ -4741,10 +4738,12 @@ brt_is_empty (BRT brt, TOKULOGGER logger) {
int
toku_brt_note_table_lock (BRT brt, TOKUTXN txn)
{
if (brt_is_empty(brt, toku_txn_logger(txn))) {
assert(brt->h->txnid_that_created_or_locked_when_empty == 0);
if (brt->h->txnid_that_created_or_locked_when_empty != toku_txn_get_txnid(txn) &&
brt_is_empty(brt, toku_txn_logger(txn))) {
assert(brt->h->txnid_that_created_or_locked_when_empty == 0);
brt->h->txnid_that_created_or_locked_when_empty = toku_txn_get_txnid(txn);
toku_cachefile_refup(brt->cf);
int r = toku_txn_note_brt(txn, brt);
assert(r==0);
return toku_logger_save_rollback_tablelock_on_empty_table(txn, toku_cachefile_filenum(brt->cf));
}
return 0;
......
......@@ -1171,14 +1171,14 @@ static int remove_txn (OMTVALUE brtv, u_int32_t UU(idx), void *txnv) {
assert((void*)txnv_again==txnv);
r = toku_omt_delete_at(brt->txns, index);
assert(r==0);
if (txn->txnid64==brt->h->txnid_that_created_or_locked_when_empty) {
brt->h->txnid_that_created_or_locked_when_empty = 0;
}
if (toku_omt_size(brt->txns)==0 && brt->was_closed) {
//Close immediately.
assert(brt->close_db);
r = brt->close_db(brt->db, brt->close_flags);
}
if (txn->txnid64==brt->h->txnid_that_created_or_locked_when_empty) {
brt->h->txnid_that_created_or_locked_when_empty = 0;
}
return r;
}
......
......@@ -81,7 +81,7 @@ static int do_insertion (enum brt_cmd_type type, TXNID xid, FILENUM filenum, BYT
assert(r==0);
BRT brt = brtv;
r = toku_brt_root_put_cmd(brt, &brtcmd, txn->logger);
return toku_cachefile_close(&cf, toku_txn_logger(txn), 0);
return r;
}
......@@ -89,7 +89,7 @@ static int do_nothing_with_filenum(TOKUTXN txn, FILENUM filenum) {
CACHEFILE cf;
int r = toku_cachefile_of_filenum(txn->logger->ct, filenum, &cf);
assert(r==0);
return toku_cachefile_close(&cf, toku_txn_logger(txn), 0);
return r;
}
......@@ -308,7 +308,7 @@ toku_rollback_tablelock_on_empty_table (FILENUM filenum, TOKUTXN txn, YIELDF UU(
assert(r==0);
}
return toku_cachefile_close(&cf, toku_txn_logger(txn), 0);
return r;
}
int
......
......@@ -46,7 +46,7 @@ do_db_work(void) {
r=env->txn_begin(env, 0, &tid, 0); assert(r==0);
r=db->put(db, tid, dbt_init(&key, "a", 2), dbt_init(&data, "b", 2), 0); DOERR(r);
if (did_fail) {
r = tid->abort(tid); CKERR(r);
r = tid->abort(tid); CKERR2s(r, 0, ENOSPC);
} else {
r=tid->commit(tid, 0); DOERR(r);
}
......@@ -83,7 +83,7 @@ do_db_work(void) {
r=env->txn_begin(env, 0, &tid, 0); assert(r==0);
r=db->open(db, tid, "foo.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); DOERR(r);
if (did_fail) {
r = tid->abort(tid); CKERR(r);
r = tid->abort(tid); CKERR2s(r, 0, ENOSPC);
} else {
r=tid->commit(tid, 0); DOERR(r);
}
......@@ -120,7 +120,7 @@ do_db_work(void) {
break_out_of_loop:
//system("ls -l " ENVDIR);
if (did_fail) {
r=tid->abort(tid); CKERR(r);
r = tid->abort(tid); CKERR2s(r, 0, ENOSPC);
} else {
r=tid->commit(tid, 0); DOERR(r);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment