diff --git a/newbrt/brt-flusher.c b/newbrt/brt-flusher.c index d9a8c33d569..13da2c18e07 100644 --- a/newbrt/brt-flusher.c +++ b/newbrt/brt-flusher.c @@ -403,10 +403,11 @@ ct_maybe_merge_child(struct flusher_advice *fa, toku_brtheader_grab_treelock(h); u_int32_t fullhash; - CACHEKEY *rootp = toku_calculate_root_offset_pointer(h, &fullhash); + CACHEKEY root; + toku_calculate_root_offset_pointer(h, &root, &fullhash); struct brtnode_fetch_extra bfe; fill_bfe_for_full_read(&bfe, h); - toku_pin_brtnode_off_client_thread(h, *rootp, fullhash, &bfe, TRUE, 0, NULL, &root_node); + toku_pin_brtnode_off_client_thread(h, root, fullhash, &bfe, TRUE, 0, NULL, &root_node); toku_assert_entire_node_in_memory(root_node); toku_brtheader_release_treelock(h); diff --git a/newbrt/brt-hot-flusher.c b/newbrt/brt-hot-flusher.c index 177f6e4c8ef..9e768224e1b 100644 --- a/newbrt/brt-hot-flusher.c +++ b/newbrt/brt-hot-flusher.c @@ -264,7 +264,7 @@ toku_brt_hot_optimize(BRT brt, // the hot optimize contract. do { BRTNODE root; - CACHEKEY *rootp; + CACHEKEY root_key; u_int32_t fullhash; { @@ -272,11 +272,11 @@ toku_brt_hot_optimize(BRT brt, // Get root node (the first parent of each successive HOT // call.) - rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); + toku_calculate_root_offset_pointer(brt->h, &root_key, &fullhash); struct brtnode_fetch_extra bfe; fill_bfe_for_full_read(&bfe, brt->h); toku_pin_brtnode_off_client_thread(brt->h, - (BLOCKNUM) *rootp, + (BLOCKNUM) root_key, fullhash, &bfe, TRUE, diff --git a/newbrt/brt-verify.c b/newbrt/brt-verify.c index 93e6f849cbe..ba41b7ed98a 100644 --- a/newbrt/brt-verify.c +++ b/newbrt/brt-verify.c @@ -407,8 +407,9 @@ toku_verify_brt_with_progress (BRT brt, int (*progress_callback)(void *extra, fl toku_brtheader_grab_treelock(brt->h); u_int32_t root_hash; - CACHEKEY *rootp = toku_calculate_root_offset_pointer(brt->h, &root_hash); - toku_get_node_for_verify(*rootp, brt, &root_node); + CACHEKEY root_key; + toku_calculate_root_offset_pointer(brt->h, &root_key, &root_hash); + toku_get_node_for_verify(root_key, brt, &root_node); toku_brtheader_release_treelock(brt->h); } diff --git a/newbrt/brt.c b/newbrt/brt.c index 10136531e7f..b709baada51 100644 --- a/newbrt/brt.c +++ b/newbrt/brt.c @@ -2146,14 +2146,15 @@ brt_nonleaf_put_cmd (brt_compare_func compare_fun, DESCRIPTOR desc, BRTNODE node } -static void +// return TRUE if root changed, FALSE otherwise +static BOOL brt_handle_maybe_reactive_root (struct brt_header *h, CACHEKEY *rootp, BRTNODE *nodep) { BRTNODE node = *nodep; toku_assert_entire_node_in_memory(node); enum reactivity re = get_node_reactivity(node); switch (re) { case RE_STABLE: - return; + return FALSE; case RE_FISSIBLE: // The root node should split, so make a new root. { @@ -2171,10 +2172,10 @@ brt_handle_maybe_reactive_root (struct brt_header *h, CACHEKEY *rootp, BRTNODE * brt_nonleaf_split(h, node, &nodea, &nodeb, &splitk, 0, NULL); } brt_init_new_root(h, nodea, nodeb, splitk, rootp, nodep); - return; + return TRUE; } case RE_FUSIBLE: - return; // Cannot merge anything at the root, so return happy. + return FALSE; // Cannot merge anything at the root, so return happy. } abort(); // cannot happen } @@ -2575,7 +2576,7 @@ toku_brt_root_put_cmd (struct brt_header *h, BRT_MSG_S * cmd) // - cmd will set new msn in tree { BRTNODE node; - CACHEKEY *rootp; + CACHEKEY root_key; //assert(0==toku_cachetable_assert_all_unpinned(brt->cachetable)); assert(h); // @@ -2610,14 +2611,14 @@ toku_brt_root_put_cmd (struct brt_header *h, BRT_MSG_S * cmd) toku_brtheader_grab_treelock(h); u_int32_t fullhash; - rootp = toku_calculate_root_offset_pointer(h, &fullhash); + toku_calculate_root_offset_pointer(h, &root_key, &fullhash); // get the root node struct brtnode_fetch_extra bfe; fill_bfe_for_full_read(&bfe, h); toku_pin_brtnode_off_client_thread( h, - *rootp, + root_key, fullhash, &bfe, TRUE, // may_modify_node @@ -2638,7 +2639,11 @@ toku_brt_root_put_cmd (struct brt_header *h, BRT_MSG_S * cmd) brt_verify_flags(h, node); // first handle a reactive root, then put in the message - brt_handle_maybe_reactive_root(h, rootp, &node); + CACHEKEY new_root_key; + BOOL root_changed = brt_handle_maybe_reactive_root(h, &new_root_key, &node); + if (root_changed) { + toku_brtheader_set_new_root_blocknum(h, new_root_key); + } toku_brtheader_release_treelock(h); } @@ -4867,10 +4872,11 @@ try_again: { toku_brtheader_grab_treelock(brt->h); u_int32_t fullhash; - CACHEKEY *rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); + CACHEKEY root_key; + toku_calculate_root_offset_pointer(brt->h, &root_key, &fullhash); toku_pin_brtnode_off_client_thread( brt->h, - *rootp, + root_key, fullhash, &bfe, FALSE, // may_modify_node set to FALSE, because root cannot change during search @@ -5427,10 +5433,11 @@ toku_brt_keyrange (BRT brt, DBT *key, u_int64_t *less_p, u_int64_t *equal_p, u_i toku_brtheader_grab_treelock(brt->h); u_int32_t fullhash; - CACHEKEY *rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); + CACHEKEY root_key; + toku_calculate_root_offset_pointer(brt->h, &root_key, &fullhash); toku_pin_brtnode_off_client_thread( brt->h, - *rootp, + root_key, fullhash, &bfe, FALSE, // may_modify_node, cannot change root during keyrange @@ -5589,8 +5596,9 @@ int toku_dump_brt (FILE *f, BRT brt) { toku_brtheader_grab_treelock(brt->h); u_int32_t fullhash = 0; - CACHEKEY *rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); - r = toku_dump_brtnode(f, brt, *rootp, 0, 0, 0); + CACHEKEY root_key; + toku_calculate_root_offset_pointer(brt->h, &root_key, &fullhash); + r = toku_dump_brtnode(f, brt, root_key, 0, 0, 0); toku_brtheader_release_treelock(brt->h); } @@ -5793,12 +5801,13 @@ BOOL toku_brt_is_empty_fast (BRT brt) { toku_brtheader_grab_treelock(brt->h); - CACHEKEY *rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); + CACHEKEY root_key; + toku_calculate_root_offset_pointer(brt->h, &root_key, &fullhash); struct brtnode_fetch_extra bfe; fill_bfe_for_full_read(&bfe, brt->h); toku_pin_brtnode_off_client_thread( brt->h, - *rootp, + root_key, fullhash, &bfe, FALSE, // may_modify_node set to FALSE, node does not change diff --git a/newbrt/brt_header.c b/newbrt/brt_header.c index 1c56efd9dd1..2c48b54b7b5 100644 --- a/newbrt/brt_header.c +++ b/newbrt/brt_header.c @@ -336,7 +336,7 @@ brtheader_note_unpin_by_checkpoint (CACHEFILE UU(cachefile), void *header_v) } // -// End of Functions that are callbacks to the cachefule +// End of Functions that are callbacks to the cachefile ///////////////////////////////////////////////////////////////////////// static int setup_initial_brtheader_root_node (struct brt_header* h, BLOCKNUM blocknum) { @@ -873,9 +873,21 @@ toku_brtheader_remove_txn_ref(struct brt_header* h, TOKUTXN txn) { } } -CACHEKEY* toku_calculate_root_offset_pointer (struct brt_header* h, u_int32_t *roothash) { +void toku_calculate_root_offset_pointer ( + struct brt_header* h, + CACHEKEY* root_key, + u_int32_t *roothash + ) +{ *roothash = toku_cachetable_hash(h->cf, h->root_blocknum); - return &h->root_blocknum; + *root_key = h->root_blocknum; } +void toku_brtheader_set_new_root_blocknum( + struct brt_header* h, + CACHEKEY new_root_key + ) +{ + h->root_blocknum = new_root_key; +} diff --git a/newbrt/brt_header.h b/newbrt/brt_header.h index b9c1fdd92ae..d046b035e43 100644 --- a/newbrt/brt_header.h +++ b/newbrt/brt_header.h @@ -58,6 +58,7 @@ toku_brtheader_maybe_add_txn_ref(struct brt_header* h, TOKUTXN txn); void toku_brtheader_remove_txn_ref(struct brt_header* h, TOKUTXN txn); -CACHEKEY* toku_calculate_root_offset_pointer (struct brt_header* h, u_int32_t *root_hash); +void toku_calculate_root_offset_pointer ( struct brt_header* h, CACHEKEY* root_key, u_int32_t *roothash); +void toku_brtheader_set_new_root_blocknum(struct brt_header* h, CACHEKEY new_root_key); #endif diff --git a/newbrt/tests/make-tree.c b/newbrt/tests/make-tree.c index 3a6a05c9672..05644cc22ef 100644 --- a/newbrt/tests/make-tree.c +++ b/newbrt/tests/make-tree.c @@ -132,13 +132,8 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) { int seq = 0, minkey, maxkey; BRTNODE newroot = make_tree(brt, height, fanout, nperleaf, &seq, &minkey, &maxkey); - // discard the old root block - u_int32_t fullhash = 0; - CACHEKEY *rootp; - rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); - // set the new root to point to the new tree - *rootp = newroot->thisnodename; + toku_brtheader_set_new_root_blocknum(brt->h, newroot->thisnodename); newroot->max_msn_applied_to_node_on_disk = last_dummymsn(); // capture msn of last message injected into tree diff --git a/newbrt/tests/msnfilter.c b/newbrt/tests/msnfilter.c index b513ccf4655..ece54a12e72 100644 --- a/newbrt/tests/msnfilter.c +++ b/newbrt/tests/msnfilter.c @@ -121,15 +121,10 @@ test_msnfilter(int do_verify) { r = toku_open_brt(fname, 1, &brt, 1024, 256, ct, null_txn, toku_builtin_compare_fun); assert(r == 0); - // discard the old root block - u_int32_t fullhash = 0; - CACHEKEY *rootp; - rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); - BRTNODE newroot = make_node(brt, 0); // set the new root to point to the new tree - *rootp = newroot->thisnodename; + toku_brtheader_set_new_root_blocknum(brt->h, newroot->thisnodename); // KLUDGE: Unpin the new root so toku_brt_lookup() can pin it. (Pin lock is no longer a recursive // mutex.) Just leaving it unpinned for this test program works because it is the only diff --git a/newbrt/tests/verify-bad-msn.c b/newbrt/tests/verify-bad-msn.c index 3e7fd5a638a..85a58935c81 100644 --- a/newbrt/tests/verify-bad-msn.c +++ b/newbrt/tests/verify-bad-msn.c @@ -138,13 +138,8 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) { int seq = 0, minkey, maxkey; BRTNODE newroot = make_tree(brt, height, fanout, nperleaf, &seq, &minkey, &maxkey); - // discard the old root block - u_int32_t fullhash = 0; - CACHEKEY *rootp; - rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); - // set the new root to point to the new tree - *rootp = newroot->thisnodename; + toku_brtheader_set_new_root_blocknum(brt->h, newroot->thisnodename); // Create bad tree (don't do following): // newroot->max_msn_applied_to_node = last_dummymsn(); // capture msn of last message injected into tree diff --git a/newbrt/tests/verify-bad-pivots.c b/newbrt/tests/verify-bad-pivots.c index f4035bc66ef..a44801b181c 100644 --- a/newbrt/tests/verify-bad-pivots.c +++ b/newbrt/tests/verify-bad-pivots.c @@ -109,12 +109,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) { BRTNODE newroot = make_tree(brt, height, fanout, nperleaf, &seq, &minkey, &maxkey); // discard the old root block - u_int32_t fullhash = 0; - CACHEKEY *rootp; - rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); - - // set the new root to point to the new tree - *rootp = newroot->thisnodename; + toku_brtheader_set_new_root_blocknum(brt->h, newroot->thisnodename); // unpin the new root toku_unpin_brtnode(brt->h, newroot); diff --git a/newbrt/tests/verify-dup-in-leaf.c b/newbrt/tests/verify-dup-in-leaf.c index c68c75d89c4..38a9b0592a6 100644 --- a/newbrt/tests/verify-dup-in-leaf.c +++ b/newbrt/tests/verify-dup-in-leaf.c @@ -63,16 +63,13 @@ test_dup_in_leaf(int do_verify) { assert(r == 0); // discard the old root block - u_int32_t fullhash = 0; - CACHEKEY *rootp; - rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); BRTNODE newroot = make_node(brt, 0); populate_leaf(newroot, htonl(2), 1); populate_leaf(newroot, htonl(2), 2); // set the new root to point to the new tree - *rootp = newroot->thisnodename; + toku_brtheader_set_new_root_blocknum(brt->h, newroot->thisnodename); // unpin the new root toku_unpin_brtnode(brt->h, newroot); diff --git a/newbrt/tests/verify-dup-pivots.c b/newbrt/tests/verify-dup-pivots.c index 70d2c18fa58..d71e8d4739c 100644 --- a/newbrt/tests/verify-dup-pivots.c +++ b/newbrt/tests/verify-dup-pivots.c @@ -109,12 +109,8 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) { BRTNODE newroot = make_tree(brt, height, fanout, nperleaf, &seq, &minkey, &maxkey); // discard the old root block - u_int32_t fullhash = 0; - CACHEKEY *rootp; - rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); - // set the new root to point to the new tree - *rootp = newroot->thisnodename; + toku_brtheader_set_new_root_blocknum(brt->h, newroot->thisnodename); // unpin the new root toku_unpin_brtnode(brt->h, newroot); diff --git a/newbrt/tests/verify-misrouted-msgs.c b/newbrt/tests/verify-misrouted-msgs.c index 3921ad95234..fa89e8b122d 100644 --- a/newbrt/tests/verify-misrouted-msgs.c +++ b/newbrt/tests/verify-misrouted-msgs.c @@ -124,12 +124,8 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) { BRTNODE newroot = make_tree(brt, height, fanout, nperleaf, &seq, &minkey, &maxkey); // discard the old root block - u_int32_t fullhash = 0; - CACHEKEY *rootp; - rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); - // set the new root to point to the new tree - *rootp = newroot->thisnodename; + toku_brtheader_set_new_root_blocknum(brt->h, newroot->thisnodename); // unpin the new root toku_unpin_brtnode(brt->h, newroot); diff --git a/newbrt/tests/verify-unsorted-leaf.c b/newbrt/tests/verify-unsorted-leaf.c index f6050bca257..4c9bc0f3248 100644 --- a/newbrt/tests/verify-unsorted-leaf.c +++ b/newbrt/tests/verify-unsorted-leaf.c @@ -63,16 +63,12 @@ test_dup_in_leaf(int do_verify) { assert(r == 0); // discard the old root block - u_int32_t fullhash = 0; - CACHEKEY *rootp; - rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); - BRTNODE newroot = make_node(brt, 0); populate_leaf(newroot, htonl(2), 1); populate_leaf(newroot, htonl(1), 2); // set the new root to point to the new tree - *rootp = newroot->thisnodename; + toku_brtheader_set_new_root_blocknum(brt->h, newroot->thisnodename); // unpin the new root toku_unpin_brtnode(brt->h, newroot); diff --git a/newbrt/tests/verify-unsorted-pivots.c b/newbrt/tests/verify-unsorted-pivots.c index 0de5d7d06e4..3eb5539115f 100644 --- a/newbrt/tests/verify-unsorted-pivots.c +++ b/newbrt/tests/verify-unsorted-pivots.c @@ -109,12 +109,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) { BRTNODE newroot = make_tree(brt, height, fanout, nperleaf, &seq, &minkey, &maxkey); // discard the old root block - u_int32_t fullhash = 0; - CACHEKEY *rootp; - rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); - - // set the new root to point to the new tree - *rootp = newroot->thisnodename; + toku_brtheader_set_new_root_blocknum(brt->h, newroot->thisnodename); // unpin the new root toku_unpin_brtnode(brt->h, newroot);