Commit 810373a1 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:4874], move all usage of h->live_brts to brt_header.c

git-svn-id: file:///svn/toku/tokudb@43432 c7de825b-a66e-492c-adef-691d508d4ae1
parent 87a994a7
...@@ -614,6 +614,7 @@ toku_block_verify_no_free_blocknums(BLOCK_TABLE bt) { ...@@ -614,6 +614,7 @@ toku_block_verify_no_free_blocknums(BLOCK_TABLE bt) {
//Verify there are no data blocks except root. //Verify there are no data blocks except root.
void void
toku_block_verify_no_data_blocks_except_root_unlocked(BLOCK_TABLE bt, BLOCKNUM root) { toku_block_verify_no_data_blocks_except_root_unlocked(BLOCK_TABLE bt, BLOCKNUM root) {
lock_for_blocktable(bt);
//Relies on checkpoint having used optimize_translation //Relies on checkpoint having used optimize_translation
assert(root.b >= RESERVED_BLOCKNUMS); assert(root.b >= RESERVED_BLOCKNUMS);
assert(bt->current.smallest_never_used_blocknum.b == root.b + 1); assert(bt->current.smallest_never_used_blocknum.b == root.b + 1);
...@@ -622,6 +623,7 @@ toku_block_verify_no_data_blocks_except_root_unlocked(BLOCK_TABLE bt, BLOCKNUM r ...@@ -622,6 +623,7 @@ toku_block_verify_no_data_blocks_except_root_unlocked(BLOCK_TABLE bt, BLOCKNUM r
BLOCKNUM b = make_blocknum(i); BLOCKNUM b = make_blocknum(i);
assert(bt->current.block_translation[b.b].size == size_is_free); assert(bt->current.block_translation[b.b].size == size_is_free);
} }
unlock_for_blocktable(bt);
} }
//Verify a blocknum is currently allocated. //Verify a blocknum is currently allocated.
......
...@@ -532,6 +532,18 @@ int toku_remove_brtheader (struct brt_header* h, char **error_string, BOOL oplsn ...@@ -532,6 +532,18 @@ int toku_remove_brtheader (struct brt_header* h, char **error_string, BOOL oplsn
return r; return r;
} }
// gets the first existing BRT handle, if it exists. If no BRT handle exists
// for this header, returns NULL
BRT toku_brtheader_get_some_existing_brt(struct brt_header* h) {
BRT brt_ret = NULL;
toku_brtheader_lock(h);
if (toku_list_empty(&h->live_brts)) {
brt_ret = toku_list_struct(toku_list_head(&h->live_brts), struct brt, live_brt_link);
}
toku_brtheader_unlock(h);
return brt_ret;
}
// Purpose: set fields in brt_header to capture accountability info for start of HOT optimize. // Purpose: set fields in brt_header to capture accountability info for start of HOT optimize.
// Note: HOT accountability variables in header are modified only while holding header lock. // Note: HOT accountability variables in header are modified only while holding header lock.
// (Header lock is really needed for touching the dirty bit, but it's useful and // (Header lock is really needed for touching the dirty bit, but it's useful and
......
...@@ -30,6 +30,8 @@ void toku_brtheader_note_brt_open(BRT live); ...@@ -30,6 +30,8 @@ void toku_brtheader_note_brt_open(BRT live);
int toku_brt_header_needed(struct brt_header* h); int toku_brt_header_needed(struct brt_header* h);
int toku_remove_brtheader (struct brt_header* h, char **error_string, BOOL oplsn_valid, LSN oplsn) __attribute__ ((warn_unused_result)); int toku_remove_brtheader (struct brt_header* h, char **error_string, BOOL oplsn_valid, LSN oplsn) __attribute__ ((warn_unused_result));
BRT toku_brtheader_get_some_existing_brt(struct brt_header* h);
void toku_brt_header_note_hot_begin(BRT brt); void toku_brt_header_note_hot_begin(BRT brt);
void toku_brt_header_note_hot_complete(BRT brt, BOOL success, MSN msn_at_start_of_hot); void toku_brt_header_note_hot_complete(BRT brt, BOOL success, MSN msn_at_start_of_hot);
......
...@@ -194,12 +194,10 @@ toku_logger_open_rollback(TOKULOGGER logger, CACHETABLE cachetable, BOOL create) ...@@ -194,12 +194,10 @@ toku_logger_open_rollback(TOKULOGGER logger, CACHETABLE cachetable, BOOL create)
r = toku_brt_open(t, ROLLBACK_CACHEFILE_NAME, create, create, cachetable, NULL_TXN); r = toku_brt_open(t, ROLLBACK_CACHEFILE_NAME, create, create, cachetable, NULL_TXN);
assert_zero(r); assert_zero(r);
logger->rollback_cachefile = t->h->cf; logger->rollback_cachefile = t->h->cf;
toku_brtheader_lock(t->h);
//Verify it is empty //Verify it is empty
assert(!t->h->panic); assert(!t->h->panic);
//Must have no data blocks (rollback logs or otherwise). //Must have no data blocks (rollback logs or otherwise).
toku_block_verify_no_data_blocks_except_root_unlocked(t->h->blocktable, t->h->root_blocknum); toku_block_verify_no_data_blocks_except_root_unlocked(t->h->blocktable, t->h->root_blocknum);
toku_brtheader_unlock(t->h);
BOOL is_empty; BOOL is_empty;
is_empty = toku_brt_is_empty_fast(t); is_empty = toku_brt_is_empty_fast(t);
assert(is_empty); assert(is_empty);
...@@ -219,10 +217,9 @@ toku_logger_close_rollback(TOKULOGGER logger, BOOL recovery_failed) { ...@@ -219,10 +217,9 @@ toku_logger_close_rollback(TOKULOGGER logger, BOOL recovery_failed) {
BRT brt_to_close; BRT brt_to_close;
{ //Find "brt" { //Find "brt"
struct brt_header *h = toku_cachefile_get_userdata(cf); struct brt_header *h = toku_cachefile_get_userdata(cf);
toku_brtheader_lock(h);
if (!h->panic && recovery_failed) { if (!h->panic && recovery_failed) {
r = toku_brt_header_set_panic(h, EINVAL, "Recovery failed"); r = toku_brt_header_set_panic(h, EINVAL, "Recovery failed");
assert_zero(r); assert_zero(r);
} }
//Verify it is safe to close it. //Verify it is safe to close it.
if (!h->panic) { //If paniced, it is safe to close. if (!h->panic) { //If paniced, it is safe to close.
...@@ -230,19 +227,15 @@ toku_logger_close_rollback(TOKULOGGER logger, BOOL recovery_failed) { ...@@ -230,19 +227,15 @@ toku_logger_close_rollback(TOKULOGGER logger, BOOL recovery_failed) {
//Must have no data blocks (rollback logs or otherwise). //Must have no data blocks (rollback logs or otherwise).
toku_block_verify_no_data_blocks_except_root_unlocked(h->blocktable, h->root_blocknum); toku_block_verify_no_data_blocks_except_root_unlocked(h->blocktable, h->root_blocknum);
} }
assert(!toku_list_empty(&h->live_brts)); // there is always one brt associated with the header assert(!h->dirty);
brt_to_close = toku_list_struct(toku_list_head(&h->live_brts), struct brt, live_brt_link); brt_to_close = toku_brtheader_get_some_existing_brt(h);
assert(brt_to_close); assert(brt_to_close);
assert(!brt_to_close->h->dirty); {
toku_brtheader_unlock(h); BOOL is_empty;
{
// This almost doesn't work. If there were anything in there, then the header might get dirtied by
// toku_brt_is_empty(). But it turns out absolutely nothing is in there, so it's OK to assert that it's empty.
BOOL is_empty;
is_empty = toku_brt_is_empty_fast(brt_to_close); is_empty = toku_brt_is_empty_fast(brt_to_close);
assert(is_empty); assert(is_empty);
} }
assert(!h->dirty); // it should not have been dirtied by the toku_brt_is_empty test. assert(!h->dirty); // it should not have been dirtied by the toku_brt_is_empty test.
} }
char *error_string_ignore = NULL; char *error_string_ignore = NULL;
......
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