Commit 5ff1a025 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:4875], fix setting of a header's root_blocknum to go through brt_header

git-svn-id: file:///svn/toku/tokudb@43461 c7de825b-a66e-492c-adef-691d508d4ae1
parent 676654a1
......@@ -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);
......
......@@ -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,
......
......@@ -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);
}
......
......@@ -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
......
......@@ -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;
}
......@@ -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
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
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