Commit b5084ff8 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:4874], remove dependence of ydb lock from h->live_brts and live->txns

git-svn-id: file:///svn/toku/tokudb@43433 c7de825b-a66e-492c-adef-691d508d4ae1
parent 20d141c0
...@@ -19,6 +19,19 @@ toku_brt_header_suppress_rollbacks(struct brt_header *h, TOKUTXN txn) { ...@@ -19,6 +19,19 @@ toku_brt_header_suppress_rollbacks(struct brt_header *h, TOKUTXN txn) {
h->root_that_created_or_locked_when_empty = rootid; h->root_that_created_or_locked_when_empty = rootid;
} }
void
toku_reset_root_xid_that_created(struct brt_header* h, TXNID new_root_xid_that_created) {
// Reset the root_xid_that_created field to the given value.
// This redefines which xid created the dictionary.
// hold lock around setting and clearing of dirty bit
// (see cooperative use of dirty bit in brtheader_begin_checkpoint())
toku_brtheader_lock (h);
h->root_xid_that_created = new_root_xid_that_created;
h->dirty = 1;
toku_brtheader_unlock (h);
}
static void static void
brtheader_destroy(struct brt_header *h) { brtheader_destroy(struct brt_header *h) {
if (!h->panic) assert(!h->checkpoint_header); if (!h->panic) assert(!h->checkpoint_header);
...@@ -804,17 +817,51 @@ cleanup: ...@@ -804,17 +817,51 @@ cleanup:
return r; return r;
} }
void //Heaviside function to find a TOKUTXN by TOKUTXN (used to find the index)
toku_reset_root_xid_that_created(struct brt_header* h, TXNID new_root_xid_that_created) { static int find_xid (OMTVALUE v, void *txnv) {
// Reset the root_xid_that_created field to the given value. TOKUTXN txn = v;
// This redefines which xid created the dictionary. TOKUTXN txnfind = txnv;
if (txn->txnid64<txnfind->txnid64) return -1;
if (txn->txnid64>txnfind->txnid64) return +1;
return 0;
}
// hold lock around setting and clearing of dirty bit void
// (see cooperative use of dirty bit in brtheader_begin_checkpoint()) toku_brtheader_maybe_add_txn_ref(struct brt_header* h, TOKUTXN txn) {
toku_brtheader_lock (h); OMTVALUE txnv;
h->root_xid_that_created = new_root_xid_that_created; u_int32_t index;
h->dirty = 1; toku_brtheader_lock(h);
toku_brtheader_unlock (h); // Does brt already know about transaction txn?
int r = toku_omt_find_zero(h->txns, find_xid, txn, &txnv, &index);
if (r==0) {
// It's already there.
assert((TOKUTXN)txnv==txn);
return 0;
}
// Otherwise it's not there.
// Insert reference to transaction into brt
r = toku_omt_insert_at(h->txns, txn, index);
assert(r==0);
toku_brtheader_unlock(h);
} }
void
toku_brtheader_remove_txn_ref(struct brt_header* h, TOKUTXN txn) {
OMTVALUE txnv_again=NULL;
u_int32_t index;
toku_brtheader_lock(h);
int r = toku_omt_find_zero(h->txns, find_xid, txn, &txnv_again, &index);
assert(r==0);
assert(txnv_again == txn);
r = toku_omt_delete_at(h->txns, index);
assert(r==0);
if (!toku_brt_header_needed(h)) {
//Close immediately.
// I have no idea how this error string business works
char *error_string = NULL;
r = toku_remove_brtheader(h, &error_string, false, ZERO_LSN);
lazy_assert_zero(r);
}
toku_brtheader_unlock(h);
}
...@@ -52,4 +52,11 @@ void toku_reset_root_xid_that_created(struct brt_header* h, TXNID new_root_xid_t ...@@ -52,4 +52,11 @@ void toku_reset_root_xid_that_created(struct brt_header* h, TXNID new_root_xid_t
// Reset the root_xid_that_created field to the given value. // Reset the root_xid_that_created field to the given value.
// This redefines which xid created the dictionary. // This redefines which xid created the dictionary.
void
toku_brtheader_maybe_add_txn_ref(struct brt_header* h, TOKUTXN txn);
void
toku_brtheader_remove_txn_ref(struct brt_header* h, TOKUTXN txn);
#endif #endif
...@@ -242,20 +242,13 @@ static int find_xid (OMTVALUE v, void *txnv) { ...@@ -242,20 +242,13 @@ static int find_xid (OMTVALUE v, void *txnv) {
return 0; return 0;
} }
static int remove_txn (OMTVALUE hv, u_int32_t UU(idx), void *txnv) static int remove_txn (OMTVALUE hv, u_int32_t UU(idx), void *txnv)
// Effect: This function is called on every open BRT that a transaction used. // Effect: This function is called on every open BRT that a transaction used.
// This function removes the transaction from that BRT. // This function removes the transaction from that BRT.
{ {
struct brt_header* h = hv; struct brt_header* h = hv;
TOKUTXN txn = txnv; TOKUTXN txn = txnv;
OMTVALUE txnv_again=NULL;
u_int32_t index;
int r = toku_omt_find_zero(h->txns, find_xid, txn, &txnv_again, &index);
assert(r==0);
assert(txnv_again == txnv);
r = toku_omt_delete_at(h->txns, index);
assert(r==0);
if (txn->txnid64==h->txnid_that_created_or_locked_when_empty) { if (txn->txnid64==h->txnid_that_created_or_locked_when_empty) {
h->txnid_that_created_or_locked_when_empty = TXNID_NONE; h->txnid_that_created_or_locked_when_empty = TXNID_NONE;
h->root_that_created_or_locked_when_empty = TXNID_NONE; h->root_that_created_or_locked_when_empty = TXNID_NONE;
...@@ -263,14 +256,9 @@ static int remove_txn (OMTVALUE hv, u_int32_t UU(idx), void *txnv) ...@@ -263,14 +256,9 @@ static int remove_txn (OMTVALUE hv, u_int32_t UU(idx), void *txnv)
if (txn->txnid64==h->txnid_that_suppressed_recovery_logs) { if (txn->txnid64==h->txnid_that_suppressed_recovery_logs) {
h->txnid_that_suppressed_recovery_logs = TXNID_NONE; h->txnid_that_suppressed_recovery_logs = TXNID_NONE;
} }
if (!toku_brt_header_needed(h)) { toku_brtheader_remove_txn_ref(h, txn);
//Close immediately.
// I have no idea how this error string business works return 0;
char *error_string = NULL;
r = toku_remove_brtheader(h, &error_string, false, ZERO_LSN);
lazy_assert_zero(r);
}
return r;
} }
// for every BRT in txn, remove it. // for every BRT in txn, remove it.
...@@ -697,21 +685,9 @@ static int find_filenum (OMTVALUE v, void *hv) { ...@@ -697,21 +685,9 @@ static int find_filenum (OMTVALUE v, void *hv) {
//Notify a transaction that it has touched a brt. //Notify a transaction that it has touched a brt.
int toku_txn_note_brt (TOKUTXN txn, struct brt_header* h) { int toku_txn_note_brt (TOKUTXN txn, struct brt_header* h) {
OMTVALUE txnv; toku_brtheader_maybe_add_txn_ref(h, txn);
u_int32_t index;
// Does brt already know about transaction txn?
int r = toku_omt_find_zero(h->txns, find_xid, txn, &txnv, &index);
if (r==0) {
// It's already there.
assert((TOKUTXN)txnv==txn);
return 0;
}
// Otherwise it's not there.
// Insert reference to transaction into brt
r = toku_omt_insert_at(h->txns, txn, index);
assert(r==0);
// Insert reference to brt into transaction // Insert reference to brt into transaction
r = toku_omt_insert(txn->open_brt_headers, h, find_filenum, h, 0); int r = toku_omt_insert(txn->open_brt_headers, h, find_filenum, h, 0);
assert(r==0); assert(r==0);
return 0; return 0;
} }
......
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