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

[t:4831], [t:4832], merge to main

git-svn-id: file:///svn/toku/tokudb@43069 c7de825b-a66e-492c-adef-691d508d4ae1
parent 69fc86d8
...@@ -221,11 +221,11 @@ toku_unpin_brtnode_off_client_thread(struct brt_header* h, BRTNODE node) ...@@ -221,11 +221,11 @@ toku_unpin_brtnode_off_client_thread(struct brt_header* h, BRTNODE node)
} }
void void
toku_unpin_brtnode(BRT brt, BRTNODE node) toku_unpin_brtnode(struct brt_header *h, BRTNODE node)
{ {
// printf("%*sUnpin %ld\n", 8-node->height, "", node->thisnodename.b); // printf("%*sUnpin %ld\n", 8-node->height, "", node->thisnodename.b);
VERIFY_NODE(brt,node); //VERIFY_NODE(brt,node);
toku_unpin_brtnode_off_client_thread(brt->h, node); toku_unpin_brtnode_off_client_thread(h, node);
} }
void void
......
...@@ -105,7 +105,7 @@ toku_unpin_brtnode_off_client_thread(struct brt_header* h, BRTNODE node); ...@@ -105,7 +105,7 @@ toku_unpin_brtnode_off_client_thread(struct brt_header* h, BRTNODE node);
* Used for nodes pinned on a client thread * Used for nodes pinned on a client thread
*/ */
void void
toku_unpin_brtnode(BRT brt, BRTNODE node); toku_unpin_brtnode(struct brt_header *h, BRTNODE node);
void void
toku_unpin_brtnode_read_only(BRT brt, BRTNODE node); toku_unpin_brtnode_read_only(BRT brt, BRTNODE node);
......
...@@ -1766,17 +1766,17 @@ static void flush_node_fun(void *fe_v) ...@@ -1766,17 +1766,17 @@ static void flush_node_fun(void *fe_v)
static void static void
place_node_and_bnc_on_background_thread( place_node_and_bnc_on_background_thread(
BRT brt, struct brt_header *h,
BRTNODE node, BRTNODE node,
NONLEAF_CHILDINFO bnc) NONLEAF_CHILDINFO bnc)
{ {
struct flusher_extra* fe = NULL; struct flusher_extra* fe = NULL;
fe = toku_xmalloc(sizeof(struct flusher_extra)); fe = toku_xmalloc(sizeof(struct flusher_extra));
assert(fe); assert(fe);
fe->h = brt->h; fe->h = h;
fe->node = node; fe->node = node;
fe->bnc = bnc; fe->bnc = bnc;
cachefile_kibbutz_enq(brt->cf, flush_node_fun, fe); cachefile_kibbutz_enq(h->cf, flush_node_fun, fe);
} }
// //
...@@ -1793,7 +1793,7 @@ place_node_and_bnc_on_background_thread( ...@@ -1793,7 +1793,7 @@ place_node_and_bnc_on_background_thread(
// The parent will be unlocked on the background thread // The parent will be unlocked on the background thread
// //
void void
flush_node_on_background_thread(BRT brt, BRTNODE parent) flush_node_on_background_thread(struct brt_header *h, BRTNODE parent)
{ {
// //
// first let's see if we can detach buffer on client thread // first let's see if we can detach buffer on client thread
...@@ -1806,9 +1806,9 @@ flush_node_on_background_thread(BRT brt, BRTNODE parent) ...@@ -1806,9 +1806,9 @@ flush_node_on_background_thread(BRT brt, BRTNODE parent)
// //
void *node_v; void *node_v;
BRTNODE child; BRTNODE child;
u_int32_t childfullhash = compute_child_fullhash(brt->cf, parent, childnum); u_int32_t childfullhash = compute_child_fullhash(h->cf, parent, childnum);
int r = toku_cachetable_maybe_get_and_pin_clean ( int r = toku_cachetable_maybe_get_and_pin_clean (
brt->cf, h->cf,
BP_BLOCKNUM(parent,childnum), BP_BLOCKNUM(parent,childnum),
childfullhash, childfullhash,
&node_v &node_v
...@@ -1817,7 +1817,7 @@ flush_node_on_background_thread(BRT brt, BRTNODE parent) ...@@ -1817,7 +1817,7 @@ flush_node_on_background_thread(BRT brt, BRTNODE parent)
// In this case, we could not lock the child, so just place the parent on the background thread // In this case, we could not lock the child, so just place the parent on the background thread
// In the callback, we will use flush_some_child, which checks to // In the callback, we will use flush_some_child, which checks to
// see if we should blow away the old basement nodes. // see if we should blow away the old basement nodes.
place_node_and_bnc_on_background_thread(brt, parent, NULL); place_node_and_bnc_on_background_thread(h, parent, NULL);
} }
else { else {
// //
...@@ -1845,17 +1845,17 @@ flush_node_on_background_thread(BRT brt, BRTNODE parent) ...@@ -1845,17 +1845,17 @@ flush_node_on_background_thread(BRT brt, BRTNODE parent)
// so, because we know for sure the child is not // so, because we know for sure the child is not
// reactive, we can unpin the parent // reactive, we can unpin the parent
// //
place_node_and_bnc_on_background_thread(brt, child, bnc); place_node_and_bnc_on_background_thread(h, child, bnc);
toku_unpin_brtnode(brt, parent); toku_unpin_brtnode(h, parent);
} }
else { else {
// because the child may be reactive, we need to // because the child may be reactive, we need to
// put parent on background thread. // put parent on background thread.
// As a result, we unlock the child here. // As a result, we unlock the child here.
toku_unpin_brtnode(brt, child); toku_unpin_brtnode(h, child);
// Again, we'll have the parent on the background thread, so // Again, we'll have the parent on the background thread, so
// we don't need to destroy the basement nodes yet. // we don't need to destroy the basement nodes yet.
place_node_and_bnc_on_background_thread(brt, parent, NULL); place_node_and_bnc_on_background_thread(h, parent, NULL);
} }
} }
} }
......
...@@ -68,7 +68,7 @@ toku_flusher_thread_set_callback( ...@@ -68,7 +68,7 @@ toku_flusher_thread_set_callback(
*/ */
void void
flush_node_on_background_thread( flush_node_on_background_thread(
BRT brt, struct brt_header *h,
BRTNODE parent BRTNODE parent
); );
......
...@@ -781,7 +781,7 @@ int toku_cmd_leafval_heaviside (OMTVALUE leafentry, void *extra) ...@@ -781,7 +781,7 @@ int toku_cmd_leafval_heaviside (OMTVALUE leafentry, void *extra)
__attribute__((__warn_unused_result__)); __attribute__((__warn_unused_result__));
// toku_brt_root_put_cmd() accepts non-constant cmd because this is where we set the msn // toku_brt_root_put_cmd() accepts non-constant cmd because this is where we set the msn
int toku_brt_root_put_cmd(BRT brt, BRT_MSG_S * cmd) int toku_brt_root_put_cmd(struct brt_header *h, BRT_MSG_S * cmd)
__attribute__((__warn_unused_result__)); __attribute__((__warn_unused_result__));
void *mempool_malloc_from_omt(OMT omt, struct mempool *mp, size_t size, void **maybe_free); void *mempool_malloc_from_omt(OMT omt, struct mempool *mp, size_t size, void **maybe_free);
......
...@@ -49,7 +49,7 @@ int toku_testsetup_leaf(BRT brt, BLOCKNUM *blocknum, int n_children, char **keys ...@@ -49,7 +49,7 @@ int toku_testsetup_leaf(BRT brt, BLOCKNUM *blocknum, int n_children, char **keys
} }
*blocknum = node->thisnodename; *blocknum = node->thisnodename;
toku_unpin_brtnode(brt, node); toku_unpin_brtnode(brt->h, node);
return 0; return 0;
} }
...@@ -71,7 +71,7 @@ int toku_testsetup_nonleaf (BRT brt, int height, BLOCKNUM *blocknum, int n_child ...@@ -71,7 +71,7 @@ int toku_testsetup_nonleaf (BRT brt, int height, BLOCKNUM *blocknum, int n_child
node->totalchildkeylens += keylens[i]; node->totalchildkeylens += keylens[i];
} }
*blocknum = node->thisnodename; *blocknum = node->thisnodename;
toku_unpin_brtnode(brt, node); toku_unpin_brtnode(brt->h, node);
return 0; return 0;
} }
...@@ -103,7 +103,7 @@ int toku_testsetup_get_sersize(BRT brt, BLOCKNUM diskoff) // Return the size on ...@@ -103,7 +103,7 @@ int toku_testsetup_get_sersize(BRT brt, BLOCKNUM diskoff) // Return the size on
); );
assert(r==0); assert(r==0);
int size = toku_serialize_brtnode_size(node_v); int size = toku_serialize_brtnode_size(node_v);
toku_unpin_brtnode(brt, node_v); toku_unpin_brtnode(brt->h, node_v);
return size; return size;
} }
...@@ -153,7 +153,7 @@ int toku_testsetup_insert_to_leaf (BRT brt, BLOCKNUM blocknum, char *key, int ke ...@@ -153,7 +153,7 @@ int toku_testsetup_insert_to_leaf (BRT brt, BLOCKNUM blocknum, char *key, int ke
toku_verify_or_set_counts(node); toku_verify_or_set_counts(node);
toku_unpin_brtnode(brt, node_v); toku_unpin_brtnode(brt->h, node_v);
return 0; return 0;
} }
...@@ -222,6 +222,6 @@ int toku_testsetup_insert_to_nonleaf (BRT brt, BLOCKNUM blocknum, enum brt_msg_t ...@@ -222,6 +222,6 @@ int toku_testsetup_insert_to_nonleaf (BRT brt, BLOCKNUM blocknum, enum brt_msg_t
node->max_msn_applied_to_node_on_disk = msn; node->max_msn_applied_to_node_on_disk = msn;
node->dirty = 1; node->dirty = 1;
toku_unpin_brtnode(brt, node_v); toku_unpin_brtnode(brt->h, node_v);
return 0; return 0;
} }
...@@ -320,8 +320,8 @@ toku_brt_nonleaf_is_gorged (BRTNODE node) { ...@@ -320,8 +320,8 @@ toku_brt_nonleaf_is_gorged (BRTNODE node) {
(!buffers_are_empty)); (!buffers_are_empty));
} }
static void brt_verify_flags(BRT brt, BRTNODE node) { static void brt_verify_flags(struct brt_header *h, BRTNODE node) {
assert(brt->flags == node->flags); assert(h->flags == node->flags);
} }
int toku_brt_debug_mode = 0; int toku_brt_debug_mode = 0;
...@@ -1465,7 +1465,7 @@ toku_initialize_empty_brtnode (BRTNODE n, BLOCKNUM nodename, int height, int num ...@@ -1465,7 +1465,7 @@ toku_initialize_empty_brtnode (BRTNODE n, BLOCKNUM nodename, int height, int num
} }
static void static void
brt_init_new_root(BRT brt, BRTNODE nodea, BRTNODE nodeb, DBT splitk, CACHEKEY *rootp, BRTNODE *newrootp) brt_init_new_root(struct brt_header *h, BRTNODE nodea, BRTNODE nodeb, DBT splitk, CACHEKEY *rootp, BRTNODE *newrootp)
// Effect: Create a new root node whose two children are NODEA and NODEB, and the pivotkey is SPLITK. // Effect: Create a new root node whose two children are NODEA and NODEB, and the pivotkey is SPLITK.
// Store the new root's identity in *ROOTP, and the node in *NEWROOTP. // Store the new root's identity in *ROOTP, and the node in *NEWROOTP.
// Unpin nodea and nodeb. // Unpin nodea and nodeb.
...@@ -1474,11 +1474,11 @@ brt_init_new_root(BRT brt, BRTNODE nodea, BRTNODE nodeb, DBT splitk, CACHEKEY *r ...@@ -1474,11 +1474,11 @@ brt_init_new_root(BRT brt, BRTNODE nodea, BRTNODE nodeb, DBT splitk, CACHEKEY *r
BRTNODE XMALLOC(newroot); BRTNODE XMALLOC(newroot);
int new_height = nodea->height+1; int new_height = nodea->height+1;
BLOCKNUM newroot_diskoff; BLOCKNUM newroot_diskoff;
toku_allocate_blocknum(brt->h->blocktable, &newroot_diskoff, brt->h); toku_allocate_blocknum(h->blocktable, &newroot_diskoff, h);
assert(newroot); assert(newroot);
*rootp=newroot_diskoff; *rootp=newroot_diskoff;
assert(new_height > 0); assert(new_height > 0);
toku_initialize_empty_brtnode (newroot, newroot_diskoff, new_height, 2, brt->h->layout_version, brt->h->nodesize, brt->flags, brt->h); toku_initialize_empty_brtnode (newroot, newroot_diskoff, new_height, 2, h->layout_version, h->nodesize, h->flags, h);
//printf("new_root %lld %d %lld %lld\n", newroot_diskoff, newroot->height, nodea->thisnodename, nodeb->thisnodename); //printf("new_root %lld %d %lld %lld\n", newroot_diskoff, newroot->height, nodea->thisnodename, nodeb->thisnodename);
//printf("%s:%d Splitkey=%p %s\n", __FILE__, __LINE__, splitkey, splitkey); //printf("%s:%d Splitkey=%p %s\n", __FILE__, __LINE__, splitkey, splitkey);
newroot->childkeys[0] = splitk.data; newroot->childkeys[0] = splitk.data;
...@@ -1494,12 +1494,12 @@ brt_init_new_root(BRT brt, BRTNODE nodea, BRTNODE nodeb, DBT splitk, CACHEKEY *r ...@@ -1494,12 +1494,12 @@ brt_init_new_root(BRT brt, BRTNODE nodea, BRTNODE nodeb, DBT splitk, CACHEKEY *r
BP_STATE(newroot,0) = PT_AVAIL; BP_STATE(newroot,0) = PT_AVAIL;
BP_STATE(newroot,1) = PT_AVAIL; BP_STATE(newroot,1) = PT_AVAIL;
toku_mark_node_dirty(newroot); toku_mark_node_dirty(newroot);
toku_unpin_brtnode(brt, nodea); toku_unpin_brtnode(h, nodea);
toku_unpin_brtnode(brt, nodeb); toku_unpin_brtnode(h, nodeb);
//printf("%s:%d put %lld\n", __FILE__, __LINE__, newroot_diskoff); //printf("%s:%d put %lld\n", __FILE__, __LINE__, newroot_diskoff);
u_int32_t fullhash = toku_cachetable_hash(brt->cf, newroot_diskoff); u_int32_t fullhash = toku_cachetable_hash(h->cf, newroot_diskoff);
newroot->fullhash = fullhash; newroot->fullhash = fullhash;
toku_cachetable_put(brt->cf, newroot_diskoff, fullhash, newroot, make_brtnode_pair_attr(newroot), get_write_callbacks_for_node(brt->h)); toku_cachetable_put(h->cf, newroot_diskoff, fullhash, newroot, make_brtnode_pair_attr(newroot), get_write_callbacks_for_node(h));
*newrootp = newroot; *newrootp = newroot;
} }
...@@ -2247,7 +2247,7 @@ brt_nonleaf_put_cmd (brt_compare_func compare_fun, DESCRIPTOR desc, BRTNODE node ...@@ -2247,7 +2247,7 @@ brt_nonleaf_put_cmd (brt_compare_func compare_fun, DESCRIPTOR desc, BRTNODE node
static void static void
brt_handle_maybe_reactive_root (BRT brt, CACHEKEY *rootp, BRTNODE *nodep) { brt_handle_maybe_reactive_root (struct brt_header *h, CACHEKEY *rootp, BRTNODE *nodep) {
BRTNODE node = *nodep; BRTNODE node = *nodep;
toku_assert_entire_node_in_memory(node); toku_assert_entire_node_in_memory(node);
enum reactivity re = get_node_reactivity(node); enum reactivity re = get_node_reactivity(node);
...@@ -2259,18 +2259,18 @@ brt_handle_maybe_reactive_root (BRT brt, CACHEKEY *rootp, BRTNODE *nodep) { ...@@ -2259,18 +2259,18 @@ brt_handle_maybe_reactive_root (BRT brt, CACHEKEY *rootp, BRTNODE *nodep) {
{ {
BRTNODE nodea,nodeb; BRTNODE nodea,nodeb;
DBT splitk; DBT splitk;
assert(brt->h->nodesize>=node->nodesize); /* otherwise we might be in trouble because the nodesize shrank. */ assert(h->nodesize>=node->nodesize); /* otherwise we might be in trouble because the nodesize shrank. */
// //
// This happens on the client thread with the ydb lock, so it is safe to // This happens on the client thread with the ydb lock, so it is safe to
// not pass in dependent nodes. Although if we wanted to, we could pass // not pass in dependent nodes. Although if we wanted to, we could pass
// in just node. That would be correct. // in just node. That would be correct.
// //
if (node->height==0) { if (node->height==0) {
brtleaf_split(brt->h, node, &nodea, &nodeb, &splitk, TRUE, 0, NULL); brtleaf_split(h, node, &nodea, &nodeb, &splitk, TRUE, 0, NULL);
} else { } else {
brt_nonleaf_split(brt->h, node, &nodea, &nodeb, &splitk, 0, NULL); brt_nonleaf_split(h, node, &nodea, &nodeb, &splitk, 0, NULL);
} }
brt_init_new_root(brt, nodea, nodeb, splitk, rootp, nodep); brt_init_new_root(h, nodea, nodeb, splitk, rootp, nodep);
return; return;
} }
case RE_FUSIBLE: case RE_FUSIBLE:
...@@ -2622,22 +2622,22 @@ void toku_apply_cmd_to_leaf( ...@@ -2622,22 +2622,22 @@ void toku_apply_cmd_to_leaf(
VERIFY_NODE(t, node); VERIFY_NODE(t, node);
} }
static void push_something_at_root (BRT brt, BRTNODE *nodep, BRT_MSG cmd) static void push_something_at_root (struct brt_header *h, BRTNODE *nodep, BRT_MSG cmd)
// Effect: Put CMD into brt's root node, and update // Effect: Put CMD into brt's root node, and update
// the value of root's max_msn_applied_to_node_on_disk // the value of root's max_msn_applied_to_node_on_disk
{ {
BRTNODE node = *nodep; BRTNODE node = *nodep;
toku_assert_entire_node_in_memory(node); toku_assert_entire_node_in_memory(node);
TOKULOGGER logger = toku_cachefile_logger(brt->cf); TOKULOGGER logger = toku_cachefile_logger(h->cf);
OMT snapshot_txnids = logger ? logger->snapshot_txnids : NULL; OMT snapshot_txnids = logger ? logger->snapshot_txnids : NULL;
OMT live_list_reverse = logger ? logger->live_list_reverse : NULL; OMT live_list_reverse = logger ? logger->live_list_reverse : NULL;
OMT live_root_txns = logger ? logger->live_root_txns : NULL; OMT live_root_txns = logger ? logger->live_root_txns : NULL;
MSN cmd_msn = cmd->msn; MSN cmd_msn = cmd->msn;
invariant(cmd_msn.msn > node->max_msn_applied_to_node_on_disk.msn); invariant(cmd_msn.msn > node->max_msn_applied_to_node_on_disk.msn);
brtnode_put_cmd( brtnode_put_cmd(
brt->compare_fun, h->compare_fun,
brt->update_fun, h->update_fun,
&brt->h->cmp_descriptor, &h->cmp_descriptor,
node, node,
cmd, cmd,
true, true,
...@@ -2673,7 +2673,7 @@ CACHEKEY* toku_calculate_root_offset_pointer (struct brt_header* h, u_int32_t *r ...@@ -2673,7 +2673,7 @@ CACHEKEY* toku_calculate_root_offset_pointer (struct brt_header* h, u_int32_t *r
} }
int int
toku_brt_root_put_cmd (BRT brt, BRT_MSG_S * cmd) toku_brt_root_put_cmd (struct brt_header *h, BRT_MSG_S * cmd)
// Effect: // Effect:
// - assign msn to cmd // - assign msn to cmd
// - push the cmd into the brt // - push the cmd into the brt
...@@ -2682,7 +2682,7 @@ toku_brt_root_put_cmd (BRT brt, BRT_MSG_S * cmd) ...@@ -2682,7 +2682,7 @@ toku_brt_root_put_cmd (BRT brt, BRT_MSG_S * cmd)
BRTNODE node; BRTNODE node;
CACHEKEY *rootp; CACHEKEY *rootp;
//assert(0==toku_cachetable_assert_all_unpinned(brt->cachetable)); //assert(0==toku_cachetable_assert_all_unpinned(brt->cachetable));
assert(brt->h); assert(h);
// //
// As of Dr. Noga, the following code is currently protected by two locks: // As of Dr. Noga, the following code is currently protected by two locks:
// - the ydb lock // - the ydb lock
...@@ -2712,16 +2712,16 @@ toku_brt_root_put_cmd (BRT brt, BRT_MSG_S * cmd) ...@@ -2712,16 +2712,16 @@ toku_brt_root_put_cmd (BRT brt, BRT_MSG_S * cmd)
// others // others
// //
{ {
toku_brtheader_grab_treelock(brt->h); toku_brtheader_grab_treelock(h);
u_int32_t fullhash; u_int32_t fullhash;
rootp = toku_calculate_root_offset_pointer(brt->h, &fullhash); rootp = toku_calculate_root_offset_pointer(h, &fullhash);
// get the root node // get the root node
struct brtnode_fetch_extra bfe; struct brtnode_fetch_extra bfe;
fill_bfe_for_full_read(&bfe, brt->h); fill_bfe_for_full_read(&bfe, h);
toku_pin_brtnode_off_client_thread( toku_pin_brtnode_off_client_thread(
brt->h, h,
*rootp, *rootp,
fullhash, fullhash,
&bfe, &bfe,
...@@ -2738,26 +2738,26 @@ toku_brt_root_put_cmd (BRT brt, BRT_MSG_S * cmd) ...@@ -2738,26 +2738,26 @@ toku_brt_root_put_cmd (BRT brt, BRT_MSG_S * cmd)
// the msn and store it in the relevant node, including the root // the msn and store it in the relevant node, including the root
// node. This is how the new msn is set in the root. // node. This is how the new msn is set in the root.
VERIFY_NODE(brt, node); //VERIFY_NODE(brt, node);
assert(node->fullhash==fullhash); assert(node->fullhash==fullhash);
brt_verify_flags(brt, node); brt_verify_flags(h, node);
// first handle a reactive root, then put in the message // first handle a reactive root, then put in the message
brt_handle_maybe_reactive_root(brt, rootp, &node); brt_handle_maybe_reactive_root(h, rootp, &node);
toku_brtheader_release_treelock(brt->h); toku_brtheader_release_treelock(h);
} }
push_something_at_root(brt, &node, cmd); push_something_at_root(h, &node, cmd);
// verify that msn of latest message was captured in root node (push_something_at_root() did not release ydb lock) // verify that msn of latest message was captured in root node (push_something_at_root() did not release ydb lock)
invariant(cmd->msn.msn == node->max_msn_applied_to_node_on_disk.msn); invariant(cmd->msn.msn == node->max_msn_applied_to_node_on_disk.msn);
// if we call flush_some_child, then that function unpins the root // if we call flush_some_child, then that function unpins the root
// otherwise, we unpin ourselves // otherwise, we unpin ourselves
if (node->height > 0 && toku_brt_nonleaf_is_gorged(node)) { if (node->height > 0 && toku_brt_nonleaf_is_gorged(node)) {
flush_node_on_background_thread(brt, node); flush_node_on_background_thread(h, node);
} }
else { else {
toku_unpin_brtnode(brt, node); // unpin root toku_unpin_brtnode(h, node); // unpin root
} }
return 0; return 0;
...@@ -2830,7 +2830,7 @@ toku_brt_optimize (BRT brt) { ...@@ -2830,7 +2830,7 @@ toku_brt_optimize (BRT brt) {
toku_init_dbt(&key); toku_init_dbt(&key);
toku_init_dbt(&val); toku_init_dbt(&val);
BRT_MSG_S brtcmd = { BRT_OPTIMIZE, ZERO_MSN, message_xids, .u.id={&key,&val}}; BRT_MSG_S brtcmd = { BRT_OPTIMIZE, ZERO_MSN, message_xids, .u.id={&key,&val}};
r = toku_brt_root_put_cmd(brt, &brtcmd); r = toku_brt_root_put_cmd(brt->h, &brtcmd);
xids_destroy(&message_xids); xids_destroy(&message_xids);
return r; return r;
} }
...@@ -2947,7 +2947,7 @@ brt_send_update_msg(BRT brt, BRT_MSG_S *msg, TOKUTXN txn) { ...@@ -2947,7 +2947,7 @@ brt_send_update_msg(BRT brt, BRT_MSG_S *msg, TOKUTXN txn) {
msg->xids = (txn msg->xids = (txn
? toku_txn_get_xids(txn) ? toku_txn_get_xids(txn)
: xids_get_root_xids()); : xids_get_root_xids());
int r = toku_brt_root_put_cmd(brt, msg); int r = toku_brt_root_put_cmd(brt->h, msg);
return r; return r;
} }
...@@ -3038,7 +3038,7 @@ cleanup: ...@@ -3038,7 +3038,7 @@ cleanup:
int int
toku_brt_send_insert(BRT brt, DBT *key, DBT *val, XIDS xids, enum brt_msg_type type) { toku_brt_send_insert(BRT brt, DBT *key, DBT *val, XIDS xids, enum brt_msg_type type) {
BRT_MSG_S brtcmd = { type, ZERO_MSN, xids, .u.id = { key, val }}; BRT_MSG_S brtcmd = { type, ZERO_MSN, xids, .u.id = { key, val }};
int r = toku_brt_root_put_cmd(brt, &brtcmd); int r = toku_brt_root_put_cmd(brt->h, &brtcmd);
return r; return r;
} }
...@@ -3046,7 +3046,7 @@ int ...@@ -3046,7 +3046,7 @@ int
toku_brt_send_commit_any(BRT brt, DBT *key, XIDS xids) { toku_brt_send_commit_any(BRT brt, DBT *key, XIDS xids) {
DBT val; DBT val;
BRT_MSG_S brtcmd = { BRT_COMMIT_ANY, ZERO_MSN, xids, .u.id = { key, toku_init_dbt(&val) }}; BRT_MSG_S brtcmd = { BRT_COMMIT_ANY, ZERO_MSN, xids, .u.id = { key, toku_init_dbt(&val) }};
int r = toku_brt_root_put_cmd(brt, &brtcmd); int r = toku_brt_root_put_cmd(brt->h, &brtcmd);
return r; return r;
} }
...@@ -3135,7 +3135,7 @@ int ...@@ -3135,7 +3135,7 @@ int
toku_brt_send_delete(BRT brt, DBT *key, XIDS xids) { toku_brt_send_delete(BRT brt, DBT *key, XIDS xids) {
DBT val; toku_init_dbt(&val); DBT val; toku_init_dbt(&val);
BRT_MSG_S brtcmd = { BRT_DELETE_ANY, ZERO_MSN, xids, .u.id = { key, &val }}; BRT_MSG_S brtcmd = { BRT_DELETE_ANY, ZERO_MSN, xids, .u.id = { key, &val }};
int result = toku_brt_root_put_cmd(brt, &brtcmd); int result = toku_brt_root_put_cmd(brt->h, &brtcmd);
return result; return result;
} }
...@@ -3229,7 +3229,7 @@ static int setup_initial_brt_root_node (BRT t, BLOCKNUM blocknum) { ...@@ -3229,7 +3229,7 @@ static int setup_initial_brt_root_node (BRT t, BLOCKNUM blocknum) {
if (r != 0) if (r != 0)
toku_free(node); toku_free(node);
else else
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
return r; return r;
} }
...@@ -5435,7 +5435,7 @@ brt_search_child(BRT brt, BRTNODE node, int childnum, brt_search_t *search, BRT_ ...@@ -5435,7 +5435,7 @@ brt_search_child(BRT brt, BRTNODE node, int childnum, brt_search_t *search, BRT_
assert(next_unlockers.locked); assert(next_unlockers.locked);
if (msgs_applied) { if (msgs_applied) {
toku_unpin_brtnode(brt, childnode); toku_unpin_brtnode(brt->h, childnode);
} }
else { else {
toku_unpin_brtnode_read_only(brt, childnode); toku_unpin_brtnode_read_only(brt, childnode);
...@@ -5451,7 +5451,7 @@ brt_search_child(BRT brt, BRTNODE node, int childnum, brt_search_t *search, BRT_ ...@@ -5451,7 +5451,7 @@ brt_search_child(BRT brt, BRTNODE node, int childnum, brt_search_t *search, BRT_
// the node was not unpinned, so we unpin it here // the node was not unpinned, so we unpin it here
if (next_unlockers.locked) { if (next_unlockers.locked) {
if (msgs_applied) { if (msgs_applied) {
toku_unpin_brtnode(brt, childnode); toku_unpin_brtnode(brt->h, childnode);
} }
else { else {
toku_unpin_brtnode_read_only(brt, childnode); toku_unpin_brtnode_read_only(brt, childnode);
...@@ -6689,7 +6689,7 @@ static BOOL is_empty_fast_iter (BRT brt, BRTNODE node) { ...@@ -6689,7 +6689,7 @@ static BOOL is_empty_fast_iter (BRT brt, BRTNODE node) {
); );
} }
int child_is_empty = is_empty_fast_iter(brt, childnode); int child_is_empty = is_empty_fast_iter(brt, childnode);
toku_unpin_brtnode(brt, childnode); toku_unpin_brtnode(brt->h, childnode);
if (!child_is_empty) return 0; if (!child_is_empty) return 0;
} }
return 1; return 1;
...@@ -6731,7 +6731,7 @@ BOOL toku_brt_is_empty_fast (BRT brt) ...@@ -6731,7 +6731,7 @@ BOOL toku_brt_is_empty_fast (BRT brt)
toku_brtheader_release_treelock(brt->h); toku_brtheader_release_treelock(brt->h);
} }
BOOL r = is_empty_fast_iter(brt, node); BOOL r = is_empty_fast_iter(brt, node);
toku_unpin_brtnode(brt, node); toku_unpin_brtnode(brt->h, node);
return r; return r;
} }
......
...@@ -214,7 +214,7 @@ static int do_insertion (enum brt_msg_type type, FILENUM filenum, BYTESTRING key ...@@ -214,7 +214,7 @@ static int do_insertion (enum brt_msg_type type, FILENUM filenum, BYTESTRING key
? toku_fill_dbt(&data_dbt, data->data, data->len) ? toku_fill_dbt(&data_dbt, data->data, data->len)
: toku_init_dbt(&data_dbt) }}; : toku_init_dbt(&data_dbt) }};
r = toku_brt_root_put_cmd(brt, &brtcmd); r = toku_brt_root_put_cmd(brt->h, &brtcmd);
if (r == 0 && reset_root_xid_that_created) { if (r == 0 && reset_root_xid_that_created) {
TXNID new_root_xid_that_created = xids_get_outermost_xid(xids); TXNID new_root_xid_that_created = xids_get_outermost_xid(xids);
toku_reset_root_xid_that_created(brt, new_root_xid_that_created); toku_reset_root_xid_that_created(brt, new_root_xid_that_created);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
TOKUROOT=../../ TOKUROOT=../../
INCLUDEDIRS=-I. -I.. -I../../include INCLUDEDIRS=-I. -I.. -I../../include
CFLAGS+=-Werror
ifeq ($(CYGWIN),) ifeq ($(CYGWIN),)
LINK_FILES += $(NEWBRT) LINK_FILES += $(NEWBRT)
else ifneq ($(CC),icc) else ifneq ($(CC),icc)
......
...@@ -89,7 +89,7 @@ make_tree(BRT brt, int height, int fanout, int nperleaf, int *seq, int *minkey, ...@@ -89,7 +89,7 @@ make_tree(BRT brt, int height, int fanout, int nperleaf, int *seq, int *minkey,
struct kv_pair *pivotkey = kv_pair_malloc(&k, sizeof k, NULL, 0); struct kv_pair *pivotkey = kv_pair_malloc(&k, sizeof k, NULL, 0);
toku_brt_nonleaf_append_child(node, child, pivotkey, sizeof k); toku_brt_nonleaf_append_child(node, child, pivotkey, sizeof k);
} }
toku_unpin_brtnode(brt, child); toku_unpin_brtnode(brt->h, child);
insert_into_child_buffer(brt, node, childnum, minkeys[childnum], maxkeys[childnum]); insert_into_child_buffer(brt, node, childnum, minkeys[childnum], maxkeys[childnum]);
} }
*minkey = minkeys[0]; *minkey = minkeys[0];
...@@ -144,7 +144,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) { ...@@ -144,7 +144,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) {
newroot->max_msn_applied_to_node_on_disk = last_dummymsn(); // capture msn of last message injected into tree newroot->max_msn_applied_to_node_on_disk = last_dummymsn(); // capture msn of last message injected into tree
// unpin the new root // unpin the new root
toku_unpin_brtnode(brt, newroot); toku_unpin_brtnode(brt->h, newroot);
if (do_verify) { if (do_verify) {
r = toku_verify_brt(brt); r = toku_verify_brt(brt);
......
...@@ -138,7 +138,7 @@ test_msnfilter(int do_verify) { ...@@ -138,7 +138,7 @@ test_msnfilter(int do_verify) {
// node and unlock it again before and after each message injection, but that requires more // node and unlock it again before and after each message injection, but that requires more
// work than it's worth (setting up dummy callbacks, etc.) // work than it's worth (setting up dummy callbacks, etc.)
// //
toku_unpin_brtnode(brt, newroot); toku_unpin_brtnode(brt->h, newroot);
populate_leaf(brt, newroot, htonl(2), 1); populate_leaf(brt, newroot, htonl(2), 1);
......
...@@ -172,7 +172,7 @@ doit (BOOL after_child_pin) { ...@@ -172,7 +172,7 @@ doit (BOOL after_child_pin) {
assert(node->height == 1); assert(node->height == 1);
assert(node->n_children == 1); assert(node->n_children == 1);
assert(toku_bnc_nbytesinbuf(BNC(node, 0)) == 0); assert(toku_bnc_nbytesinbuf(BNC(node, 0)) == 0);
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
void *ret; void *ret;
r = toku_pthread_join(checkpoint_tid, &ret); r = toku_pthread_join(checkpoint_tid, &ret);
......
...@@ -150,10 +150,10 @@ doit (int state) { ...@@ -150,10 +150,10 @@ doit (int state) {
BRTNODE node = NULL; BRTNODE node = NULL;
toku_pin_node_with_min_bfe(&node, node_leaves[0], t); toku_pin_node_with_min_bfe(&node, node_leaves[0], t);
BLB_SEQINSERT(node, node->n_children-1) = FALSE; BLB_SEQINSERT(node, node->n_children-1) = FALSE;
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
toku_pin_node_with_min_bfe(&node, node_leaves[1], t); toku_pin_node_with_min_bfe(&node, node_leaves[1], t);
BLB_SEQINSERT(node, node->n_children-1) = FALSE; BLB_SEQINSERT(node, node->n_children-1) = FALSE;
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
struct brtnode_fetch_extra bfe; struct brtnode_fetch_extra bfe;
...@@ -188,7 +188,7 @@ doit (int state) { ...@@ -188,7 +188,7 @@ doit (int state) {
); );
assert(node->height == 1); assert(node->height == 1);
assert(node->n_children == 1); assert(node->n_children == 1);
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
void *ret; void *ret;
r = toku_pthread_join(checkpoint_tid, &ret); r = toku_pthread_join(checkpoint_tid, &ret);
......
...@@ -170,10 +170,10 @@ doit (int state) { ...@@ -170,10 +170,10 @@ doit (int state) {
BRTNODE node = NULL; BRTNODE node = NULL;
toku_pin_node_with_min_bfe(&node, node_leaves[0], t); toku_pin_node_with_min_bfe(&node, node_leaves[0], t);
BLB_SEQINSERT(node, node->n_children-1) = FALSE; BLB_SEQINSERT(node, node->n_children-1) = FALSE;
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
toku_pin_node_with_min_bfe(&node, node_leaves[1], t); toku_pin_node_with_min_bfe(&node, node_leaves[1], t);
BLB_SEQINSERT(node, node->n_children-1) = FALSE; BLB_SEQINSERT(node, node->n_children-1) = FALSE;
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
struct brtnode_fetch_extra bfe; struct brtnode_fetch_extra bfe;
...@@ -208,7 +208,7 @@ doit (int state) { ...@@ -208,7 +208,7 @@ doit (int state) {
); );
assert(node->height == 1); assert(node->height == 1);
assert(node->n_children == 2); assert(node->n_children == 2);
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
void *ret; void *ret;
r = toku_pthread_join(checkpoint_tid, &ret); r = toku_pthread_join(checkpoint_tid, &ret);
......
...@@ -184,7 +184,7 @@ doit (BOOL after_split) { ...@@ -184,7 +184,7 @@ doit (BOOL after_split) {
); );
assert(node->height == 1); assert(node->height == 1);
assert(node->n_children == 2); assert(node->n_children == 2);
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
void *ret; void *ret;
r = toku_pthread_join(checkpoint_tid, &ret); r = toku_pthread_join(checkpoint_tid, &ret);
......
...@@ -143,7 +143,7 @@ doit (void) { ...@@ -143,7 +143,7 @@ doit (void) {
toku_pin_node_with_min_bfe(&node, node_leaf[1], brt); toku_pin_node_with_min_bfe(&node, node_leaf[1], brt);
// hack to get merge going // hack to get merge going
BLB_SEQINSERT(node, node->n_children-1) = FALSE; BLB_SEQINSERT(node, node->n_children-1) = FALSE;
toku_unpin_brtnode(brt, node); toku_unpin_brtnode(brt->h, node);
// now do a lookup on one of the keys, this should bring a leaf node up to date // now do a lookup on one of the keys, this should bring a leaf node up to date
DBT k; DBT k;
......
...@@ -195,7 +195,7 @@ doit (void) { ...@@ -195,7 +195,7 @@ doit (void) {
// child 1 should still have message in buffer // child 1 should still have message in buffer
assert(toku_bnc_n_entries(node->bp[0].ptr.u.nonleaf) == 0); assert(toku_bnc_n_entries(node->bp[0].ptr.u.nonleaf) == 0);
assert(toku_bnc_n_entries(node->bp[1].ptr.u.nonleaf) > 0); assert(toku_bnc_n_entries(node->bp[1].ptr.u.nonleaf) > 0);
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
r = toku_checkpoint(ct, NULL, NULL, NULL, NULL, NULL, CLIENT_CHECKPOINT); r = toku_checkpoint(ct, NULL, NULL, NULL, NULL, NULL, CLIENT_CHECKPOINT);
assert_zero(r); assert_zero(r);
toku_pin_node_with_min_bfe(&node, node_internal, t); toku_pin_node_with_min_bfe(&node, node_internal, t);
...@@ -213,7 +213,7 @@ doit (void) { ...@@ -213,7 +213,7 @@ doit (void) {
assert(toku_bnc_n_entries(node->bp[0].ptr.u.nonleaf) == 0); assert(toku_bnc_n_entries(node->bp[0].ptr.u.nonleaf) == 0);
assert(toku_bnc_n_entries(node->bp[1].ptr.u.nonleaf) == 0); assert(toku_bnc_n_entries(node->bp[1].ptr.u.nonleaf) == 0);
// now let's do a flush with an empty buffer, make sure it is ok // now let's do a flush with an empty buffer, make sure it is ok
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
r = toku_checkpoint(ct, NULL, NULL, NULL, NULL, NULL, CLIENT_CHECKPOINT); r = toku_checkpoint(ct, NULL, NULL, NULL, NULL, NULL, CLIENT_CHECKPOINT);
assert_zero(r); assert_zero(r);
toku_pin_node_with_min_bfe(&node, node_internal, t); toku_pin_node_with_min_bfe(&node, node_internal, t);
...@@ -230,7 +230,7 @@ doit (void) { ...@@ -230,7 +230,7 @@ doit (void) {
// both buffers should be empty now // both buffers should be empty now
assert(toku_bnc_n_entries(node->bp[0].ptr.u.nonleaf) == 0); assert(toku_bnc_n_entries(node->bp[0].ptr.u.nonleaf) == 0);
assert(toku_bnc_n_entries(node->bp[1].ptr.u.nonleaf) == 0); assert(toku_bnc_n_entries(node->bp[1].ptr.u.nonleaf) == 0);
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
// now let's start a flush from the root, that always recursively flushes // now let's start a flush from the root, that always recursively flushes
flusher_advice_init( flusher_advice_init(
...@@ -254,13 +254,13 @@ doit (void) { ...@@ -254,13 +254,13 @@ doit (void) {
toku_pin_node_with_min_bfe(&node, node_internal, t); toku_pin_node_with_min_bfe(&node, node_internal, t);
assert(!node->dirty); // nothing was flushed, so node better not be dirty assert(!node->dirty); // nothing was flushed, so node better not be dirty
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
toku_pin_node_with_min_bfe(&node, node_leaf[0], t); toku_pin_node_with_min_bfe(&node, node_leaf[0], t);
assert(!node->dirty); // nothing was flushed, so node better not be dirty assert(!node->dirty); // nothing was flushed, so node better not be dirty
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
toku_pin_node_with_min_bfe(&node, node_leaf[1], t); toku_pin_node_with_min_bfe(&node, node_leaf[1], t);
assert(!node->dirty); // nothing was flushed, so node better not be dirty assert(!node->dirty); // nothing was flushed, so node better not be dirty
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
} }
// now one more test to show a bug was fixed // now one more test to show a bug was fixed
...@@ -288,7 +288,7 @@ doit (void) { ...@@ -288,7 +288,7 @@ doit (void) {
toku_brtnode_pe_callback(node, make_pair_attr(0xffffffff), &attr, NULL); toku_brtnode_pe_callback(node, make_pair_attr(0xffffffff), &attr, NULL);
} }
assert(BP_STATE(node,0) == PT_COMPRESSED); assert(BP_STATE(node,0) == PT_COMPRESSED);
toku_unpin_brtnode(t, node); toku_unpin_brtnode(t->h, node);
//now let's do the same test as above //now let's do the same test as above
toku_pin_node_with_min_bfe(&node, node_root, t); toku_pin_node_with_min_bfe(&node, node_root, t);
......
...@@ -175,7 +175,7 @@ test_split_on_boundary(void) ...@@ -175,7 +175,7 @@ test_split_on_boundary(void)
verify_basement_node_msns(nodea, dummy_msn_3884); verify_basement_node_msns(nodea, dummy_msn_3884);
verify_basement_node_msns(nodeb, dummy_msn_3884); verify_basement_node_msns(nodeb, dummy_msn_3884);
toku_unpin_brtnode(brt, nodeb); toku_unpin_brtnode(brt->h, nodeb);
r = toku_close_brt_nolsn(brt, NULL); assert(r == 0); r = toku_close_brt_nolsn(brt, NULL); assert(r == 0);
r = toku_cachetable_close(&ct); assert(r == 0); r = toku_cachetable_close(&ct); assert(r == 0);
...@@ -245,7 +245,7 @@ test_split_with_everything_on_the_left(void) ...@@ -245,7 +245,7 @@ test_split_with_everything_on_the_left(void)
// if we haven't done it right, we should hit the assert in the top of move_leafentries // if we haven't done it right, we should hit the assert in the top of move_leafentries
brtleaf_split(brt->h, &sn, &nodea, &nodeb, &splitk, TRUE, 0, NULL); brtleaf_split(brt->h, &sn, &nodea, &nodeb, &splitk, TRUE, 0, NULL);
toku_unpin_brtnode(brt, nodeb); toku_unpin_brtnode(brt->h, nodeb);
r = toku_close_brt_nolsn(brt, NULL); assert(r == 0); r = toku_close_brt_nolsn(brt, NULL); assert(r == 0);
r = toku_cachetable_close(&ct); assert(r == 0); r = toku_cachetable_close(&ct); assert(r == 0);
...@@ -320,7 +320,7 @@ test_split_on_boundary_of_last_node(void) ...@@ -320,7 +320,7 @@ test_split_on_boundary_of_last_node(void)
// if we haven't done it right, we should hit the assert in the top of move_leafentries // if we haven't done it right, we should hit the assert in the top of move_leafentries
brtleaf_split(brt->h, &sn, &nodea, &nodeb, &splitk, TRUE, 0, NULL); brtleaf_split(brt->h, &sn, &nodea, &nodeb, &splitk, TRUE, 0, NULL);
toku_unpin_brtnode(brt, nodeb); toku_unpin_brtnode(brt->h, nodeb);
r = toku_close_brt_nolsn(brt, NULL); assert(r == 0); r = toku_close_brt_nolsn(brt, NULL); assert(r == 0);
r = toku_cachetable_close(&ct); assert(r == 0); r = toku_cachetable_close(&ct); assert(r == 0);
...@@ -388,7 +388,7 @@ test_split_at_begin(void) ...@@ -388,7 +388,7 @@ test_split_at_begin(void)
// if we haven't done it right, we should hit the assert in the top of move_leafentries // if we haven't done it right, we should hit the assert in the top of move_leafentries
brtleaf_split(brt->h, &sn, &nodea, &nodeb, &splitk, TRUE, 0, NULL); brtleaf_split(brt->h, &sn, &nodea, &nodeb, &splitk, TRUE, 0, NULL);
toku_unpin_brtnode(brt, nodeb); toku_unpin_brtnode(brt->h, nodeb);
r = toku_close_brt_nolsn(brt, NULL); assert(r == 0); r = toku_close_brt_nolsn(brt, NULL); assert(r == 0);
r = toku_cachetable_close(&ct); assert(r == 0); r = toku_cachetable_close(&ct); assert(r == 0);
...@@ -452,7 +452,7 @@ test_split_at_end(void) ...@@ -452,7 +452,7 @@ test_split_at_end(void)
// if we haven't done it right, we should hit the assert in the top of move_leafentries // if we haven't done it right, we should hit the assert in the top of move_leafentries
brtleaf_split(brt->h, &sn, &nodea, &nodeb, &splitk, TRUE, 0, NULL); brtleaf_split(brt->h, &sn, &nodea, &nodeb, &splitk, TRUE, 0, NULL);
toku_unpin_brtnode(brt, nodeb); toku_unpin_brtnode(brt->h, nodeb);
r = toku_close_brt_nolsn(brt, NULL); assert(r == 0); r = toku_close_brt_nolsn(brt, NULL); assert(r == 0);
r = toku_cachetable_close(&ct); assert(r == 0); r = toku_cachetable_close(&ct); assert(r == 0);
...@@ -509,7 +509,7 @@ test_split_odd_nodes(void) ...@@ -509,7 +509,7 @@ test_split_odd_nodes(void)
verify_basement_node_msns(nodea, dummy_msn_3884); verify_basement_node_msns(nodea, dummy_msn_3884);
verify_basement_node_msns(nodeb, dummy_msn_3884); verify_basement_node_msns(nodeb, dummy_msn_3884);
toku_unpin_brtnode(brt, nodeb); toku_unpin_brtnode(brt->h, nodeb);
r = toku_close_brt_nolsn(brt, NULL); assert(r == 0); r = toku_close_brt_nolsn(brt, NULL); assert(r == 0);
r = toku_cachetable_close(&ct); assert(r == 0); r = toku_cachetable_close(&ct); assert(r == 0);
......
...@@ -95,7 +95,7 @@ make_tree(BRT brt, int height, int fanout, int nperleaf, int *seq, int *minkey, ...@@ -95,7 +95,7 @@ make_tree(BRT brt, int height, int fanout, int nperleaf, int *seq, int *minkey,
struct kv_pair *pivotkey = kv_pair_malloc(&k, sizeof k, NULL, 0); struct kv_pair *pivotkey = kv_pair_malloc(&k, sizeof k, NULL, 0);
toku_brt_nonleaf_append_child(node, child, pivotkey, sizeof k); toku_brt_nonleaf_append_child(node, child, pivotkey, sizeof k);
} }
toku_unpin_brtnode(brt, child); toku_unpin_brtnode(brt->h, child);
insert_into_child_buffer(brt, node, childnum, minkeys[childnum], maxkeys[childnum]); insert_into_child_buffer(brt, node, childnum, minkeys[childnum], maxkeys[childnum]);
} }
*minkey = minkeys[0]; *minkey = minkeys[0];
...@@ -151,7 +151,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) { ...@@ -151,7 +151,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) {
// newroot->max_msn_applied_to_node = last_dummymsn(); // capture msn of last message injected into tree // newroot->max_msn_applied_to_node = last_dummymsn(); // capture msn of last message injected into tree
// unpin the new root // unpin the new root
toku_unpin_brtnode(brt, newroot); toku_unpin_brtnode(brt->h, newroot);
if (do_verify) { if (do_verify) {
r = toku_verify_brt(brt); r = toku_verify_brt(brt);
......
...@@ -66,7 +66,7 @@ make_tree(BRT brt, int height, int fanout, int nperleaf, int *seq, int *minkey, ...@@ -66,7 +66,7 @@ make_tree(BRT brt, int height, int fanout, int nperleaf, int *seq, int *minkey,
struct kv_pair *pivotkey = kv_pair_malloc(&k, sizeof k, NULL, 0); struct kv_pair *pivotkey = kv_pair_malloc(&k, sizeof k, NULL, 0);
toku_brt_nonleaf_append_child(node, child, pivotkey, sizeof k); toku_brt_nonleaf_append_child(node, child, pivotkey, sizeof k);
} }
toku_unpin_brtnode(brt, child); toku_unpin_brtnode(brt->h, child);
} }
*minkey = minkeys[0]; *minkey = minkeys[0];
*maxkey = maxkeys[0]; *maxkey = maxkeys[0];
...@@ -118,7 +118,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) { ...@@ -118,7 +118,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) {
*rootp = newroot->thisnodename; *rootp = newroot->thisnodename;
// unpin the new root // unpin the new root
toku_unpin_brtnode(brt, newroot); toku_unpin_brtnode(brt->h, newroot);
if (do_verify) { if (do_verify) {
r = toku_verify_brt(brt); r = toku_verify_brt(brt);
......
...@@ -76,7 +76,7 @@ test_dup_in_leaf(int do_verify) { ...@@ -76,7 +76,7 @@ test_dup_in_leaf(int do_verify) {
*rootp = newroot->thisnodename; *rootp = newroot->thisnodename;
// unpin the new root // unpin the new root
toku_unpin_brtnode(brt, newroot); toku_unpin_brtnode(brt->h, newroot);
if (do_verify) { if (do_verify) {
r = toku_verify_brt(brt); r = toku_verify_brt(brt);
......
...@@ -66,7 +66,7 @@ make_tree(BRT brt, int height, int fanout, int nperleaf, int *seq, int *minkey, ...@@ -66,7 +66,7 @@ make_tree(BRT brt, int height, int fanout, int nperleaf, int *seq, int *minkey,
struct kv_pair *pivotkey = kv_pair_malloc(&k, sizeof k, NULL, 0); struct kv_pair *pivotkey = kv_pair_malloc(&k, sizeof k, NULL, 0);
toku_brt_nonleaf_append_child(node, child, pivotkey, sizeof k); toku_brt_nonleaf_append_child(node, child, pivotkey, sizeof k);
} }
toku_unpin_brtnode(brt, child); toku_unpin_brtnode(brt->h, child);
} }
*minkey = minkeys[0]; *minkey = minkeys[0];
*maxkey = maxkeys[0]; *maxkey = maxkeys[0];
...@@ -118,7 +118,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) { ...@@ -118,7 +118,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) {
*rootp = newroot->thisnodename; *rootp = newroot->thisnodename;
// unpin the new root // unpin the new root
toku_unpin_brtnode(brt, newroot); toku_unpin_brtnode(brt->h, newroot);
if (do_verify) { if (do_verify) {
r = toku_verify_brt(brt); r = toku_verify_brt(brt);
......
...@@ -80,7 +80,7 @@ make_tree(BRT brt, int height, int fanout, int nperleaf, int *seq, int *minkey, ...@@ -80,7 +80,7 @@ make_tree(BRT brt, int height, int fanout, int nperleaf, int *seq, int *minkey,
struct kv_pair *pivotkey = kv_pair_malloc(&k, sizeof k, NULL, 0); struct kv_pair *pivotkey = kv_pair_malloc(&k, sizeof k, NULL, 0);
toku_brt_nonleaf_append_child(node, child, pivotkey, sizeof k); toku_brt_nonleaf_append_child(node, child, pivotkey, sizeof k);
} }
toku_unpin_brtnode(brt, child); toku_unpin_brtnode(brt->h, child);
insert_into_child_buffer(brt, node, childnum, minkeys[childnum], maxkeys[childnum]); insert_into_child_buffer(brt, node, childnum, minkeys[childnum], maxkeys[childnum]);
} }
*minkey = minkeys[0]; *minkey = minkeys[0];
...@@ -133,7 +133,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) { ...@@ -133,7 +133,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) {
*rootp = newroot->thisnodename; *rootp = newroot->thisnodename;
// unpin the new root // unpin the new root
toku_unpin_brtnode(brt, newroot); toku_unpin_brtnode(brt->h, newroot);
if (do_verify) { if (do_verify) {
r = toku_verify_brt(brt); r = toku_verify_brt(brt);
......
...@@ -76,7 +76,7 @@ test_dup_in_leaf(int do_verify) { ...@@ -76,7 +76,7 @@ test_dup_in_leaf(int do_verify) {
*rootp = newroot->thisnodename; *rootp = newroot->thisnodename;
// unpin the new root // unpin the new root
toku_unpin_brtnode(brt, newroot); toku_unpin_brtnode(brt->h, newroot);
if (do_verify) { if (do_verify) {
r = toku_verify_brt(brt); r = toku_verify_brt(brt);
......
...@@ -66,7 +66,7 @@ make_tree(BRT brt, int height, int fanout, int nperleaf, int *seq, int *minkey, ...@@ -66,7 +66,7 @@ make_tree(BRT brt, int height, int fanout, int nperleaf, int *seq, int *minkey,
struct kv_pair *pivotkey = kv_pair_malloc(&k, sizeof k, NULL, 0); struct kv_pair *pivotkey = kv_pair_malloc(&k, sizeof k, NULL, 0);
toku_brt_nonleaf_append_child(node, child, pivotkey, sizeof k); toku_brt_nonleaf_append_child(node, child, pivotkey, sizeof k);
} }
toku_unpin_brtnode(brt, child); toku_unpin_brtnode(brt->h, child);
} }
*minkey = minkeys[0]; *minkey = minkeys[0];
*maxkey = maxkeys[0]; *maxkey = maxkeys[0];
...@@ -118,7 +118,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) { ...@@ -118,7 +118,7 @@ test_make_tree(int height, int fanout, int nperleaf, int do_verify) {
*rootp = newroot->thisnodename; *rootp = newroot->thisnodename;
// unpin the new root // unpin the new root
toku_unpin_brtnode(brt, newroot); toku_unpin_brtnode(brt->h, newroot);
if (do_verify) { if (do_verify) {
r = toku_verify_brt(brt); r = toku_verify_brt(brt);
......
...@@ -40,8 +40,9 @@ struct __toku_ltm { ...@@ -40,8 +40,9 @@ struct __toku_ltm {
struct __toku_lock_tree { struct __toku_lock_tree {
/** Lock tree manager */ /** Lock tree manager */
toku_ltm* mgr; toku_ltm* mgr;
/** The database for which this locktree will be handling locks */ // for comparisons
DB* db; struct __toku_db fake_db; // dummy db used for comparisons
DESCRIPTOR_S desc_s;
#if TOKU_LT_USE_BORDERWRITE #if TOKU_LT_USE_BORDERWRITE
toku_range_tree* borderwrite; /**< See design document */ toku_range_tree* borderwrite; /**< See design document */
#endif #endif
...@@ -54,9 +55,7 @@ struct __toku_lock_tree { ...@@ -54,9 +55,7 @@ struct __toku_lock_tree {
uint32_t ref_count; uint32_t ref_count;
/** DICTIONARY_ID associated with the lock tree */ /** DICTIONARY_ID associated with the lock tree */
DICTIONARY_ID dict_id; DICTIONARY_ID dict_id;
OMT dbs; //The extant dbs using this lock tree.
OMT lock_requests; OMT lock_requests;
toku_rth* txns_to_unlock; // set of txn's that could not release their locks because there was no db for the comparison function
toku_pthread_mutex_t mutex; toku_pthread_mutex_t mutex;
bool mutex_locked; bool mutex_locked;
......
...@@ -90,7 +90,8 @@ toku_ltm_get_status(toku_ltm* mgr, LTM_STATUS statp) { ...@@ -90,7 +90,8 @@ toku_ltm_get_status(toku_ltm* mgr, LTM_STATUS statp) {
static inline int static inline int
lt_panic(toku_lock_tree *tree, int r) { lt_panic(toku_lock_tree *tree, int r) {
return tree->mgr->panic(tree->db, r); // TODO: (Zardosht) handle this panic properly
return tree->mgr->panic(NULL, r);
} }
// forward defs of lock request tree functions // forward defs of lock request tree functions
...@@ -226,7 +227,7 @@ toku_lt_point_cmp(const toku_point* x, const toku_point* y) { ...@@ -226,7 +227,7 @@ toku_lt_point_cmp(const toku_point* x, const toku_point* y) {
be the sole determinant of the comparison */ be the sole determinant of the comparison */
return infinite_compare(x->key_payload, y->key_payload); return infinite_compare(x->key_payload, y->key_payload);
} }
return x->lt->compare_fun(x->lt->db, return x->lt->compare_fun(&x->lt->fake_db,
recreate_DBT(&point_1, x->key_payload, x->key_len), recreate_DBT(&point_1, x->key_payload, x->key_len),
recreate_DBT(&point_2, y->key_payload, y->key_len)); recreate_DBT(&point_2, y->key_payload, y->key_len));
} }
...@@ -1098,21 +1099,9 @@ r_backwards(toku_interval* range) { ...@@ -1098,21 +1099,9 @@ r_backwards(toku_interval* range) {
(toku_lt_point_cmp(left, right) > 0)); (toku_lt_point_cmp(left, right) > 0));
} }
static inline void
lt_set_comparison_functions(toku_lock_tree* tree, DB* db) {
assert(!tree->db);
tree->db = db;
}
static inline void
lt_clear_comparison_functions(toku_lock_tree* tree) {
assert(tree);
tree->db = NULL;
}
/* Preprocess step for acquire functions. */ /* Preprocess step for acquire functions. */
static inline int static inline int
lt_preprocess(toku_lock_tree* tree, DB* db, lt_preprocess(toku_lock_tree* tree,
__attribute__((unused)) TXNID txn, __attribute__((unused)) TXNID txn,
const DBT* key_left, const DBT* key_left,
const DBT* key_right, const DBT* key_right,
...@@ -1131,26 +1120,15 @@ lt_preprocess(toku_lock_tree* tree, DB* db, ...@@ -1131,26 +1120,15 @@ lt_preprocess(toku_lock_tree* tree, DB* db,
init_point(right, tree, key_right); init_point(right, tree, key_right);
init_query(query, left, right); init_query(query, left, right);
lt_set_comparison_functions(tree, db);
/* Verify left <= right, otherwise return EDOM. */ /* Verify left <= right, otherwise return EDOM. */
if (r_backwards(query)) { if (r_backwards(query)) {
r = EDOM; goto cleanup; r = EDOM; goto cleanup;
} }
r = 0; r = 0;
cleanup: cleanup:
if (r == 0) {
assert(tree->db);
}
return r; return r;
} }
/* Postprocess step for acquire functions. */
static inline void
lt_postprocess(toku_lock_tree* tree) {
lt_clear_comparison_functions(tree);
}
static inline int static inline int
lt_get_border_in_selfwrite(toku_lock_tree* tree, lt_get_border_in_selfwrite(toku_lock_tree* tree,
toku_range* pred, toku_range* succ, toku_range* pred, toku_range* succ,
...@@ -1333,15 +1311,12 @@ toku_lt_create(toku_lock_tree** ptree, ...@@ -1333,15 +1311,12 @@ toku_lt_create(toku_lock_tree** ptree,
assert(r == 0); assert(r == 0);
r = toku_rth_create(&tmp_tree->rth); r = toku_rth_create(&tmp_tree->rth);
assert(r == 0); assert(r == 0);
r = toku_rth_create(&tmp_tree->txns_to_unlock);
assert(r == 0);
tmp_tree->buflen = __toku_default_buflen; tmp_tree->buflen = __toku_default_buflen;
tmp_tree->buf = (toku_range*) toku_xmalloc(tmp_tree->buflen * sizeof(toku_range)); tmp_tree->buf = (toku_range*) toku_xmalloc(tmp_tree->buflen * sizeof(toku_range));
tmp_tree->bw_buflen = __toku_default_buflen; tmp_tree->bw_buflen = __toku_default_buflen;
tmp_tree->bw_buf = (toku_range*) toku_xmalloc(tmp_tree->bw_buflen * sizeof(toku_range)); tmp_tree->bw_buf = (toku_range*) toku_xmalloc(tmp_tree->bw_buflen * sizeof(toku_range));
tmp_tree->verify_buflen = 0; tmp_tree->verify_buflen = 0;
tmp_tree->verify_buf = NULL; tmp_tree->verify_buf = NULL;
r = toku_omt_create(&tmp_tree->dbs);
assert(r == 0); assert(r == 0);
lock_request_tree_init(tmp_tree); lock_request_tree_init(tmp_tree);
toku_mutex_init(&tmp_tree->mutex, NULL); toku_mutex_init(&tmp_tree->mutex, NULL);
...@@ -1376,12 +1351,20 @@ lt_set_dict_id(toku_lock_tree* lt, DICTIONARY_ID dict_id) { ...@@ -1376,12 +1351,20 @@ lt_set_dict_id(toku_lock_tree* lt, DICTIONARY_ID dict_id) {
lt->dict_id = dict_id; lt->dict_id = dict_id;
} }
static void lt_add_db(toku_lock_tree* tree, DB *db); void
static void lt_remove_db(toku_lock_tree* tree, DB *db); toku_lt_update_descriptor(toku_lock_tree* tree, DESCRIPTOR desc) {
static void lt_unlock_deferred_txns(toku_lock_tree *tree); if (tree->desc_s.dbt.data) {
toku_free(tree->desc_s.dbt.data);
tree->desc_s.dbt.data = NULL;
}
if (desc) {
tree->desc_s.dbt.size = desc->dbt.size;
tree->desc_s.dbt.data = toku_memdup(desc->dbt.data, desc->dbt.size);
}
}
int int
toku_ltm_get_lt(toku_ltm* mgr, toku_lock_tree** ptree, DICTIONARY_ID dict_id, DB *db, toku_dbt_cmp compare_fun) { toku_ltm_get_lt(toku_ltm* mgr, toku_lock_tree** ptree, DICTIONARY_ID dict_id, DESCRIPTOR desc, toku_dbt_cmp compare_fun) {
/* first look in hash table to see if lock tree exists for that db, /* first look in hash table to see if lock tree exists for that db,
if so return it */ if so return it */
int r = ENOSYS; int r = ENOSYS;
...@@ -1389,7 +1372,6 @@ toku_ltm_get_lt(toku_ltm* mgr, toku_lock_tree** ptree, DICTIONARY_ID dict_id, DB ...@@ -1389,7 +1372,6 @@ toku_ltm_get_lt(toku_ltm* mgr, toku_lock_tree** ptree, DICTIONARY_ID dict_id, DB
toku_lock_tree* tree = NULL; toku_lock_tree* tree = NULL;
bool added_to_ltm = FALSE; bool added_to_ltm = FALSE;
bool added_to_idlth = FALSE; bool added_to_idlth = FALSE;
bool added_extant_db = FALSE;
ltm_mutex_lock(mgr); ltm_mutex_lock(mgr);
map = toku_idlth_find(mgr->idlth, dict_id); map = toku_idlth_find(mgr->idlth, dict_id);
...@@ -1398,32 +1380,34 @@ toku_ltm_get_lt(toku_ltm* mgr, toku_lock_tree** ptree, DICTIONARY_ID dict_id, DB ...@@ -1398,32 +1380,34 @@ toku_ltm_get_lt(toku_ltm* mgr, toku_lock_tree** ptree, DICTIONARY_ID dict_id, DB
tree = map->tree; tree = map->tree;
assert (tree != NULL); assert (tree != NULL);
toku_lt_add_ref(tree); toku_lt_add_ref(tree);
lt_add_db(tree, db);
lt_unlock_deferred_txns(tree);
*ptree = tree; *ptree = tree;
r = 0; r = 0;
goto cleanup; goto cleanup;
} }
/* Must create new lock tree for this dict_id*/ /* Must create new lock tree for this dict_id*/
r = toku_lt_create(&tree, mgr, compare_fun); r = toku_lt_create(&tree, mgr, compare_fun);
if (r != 0) if (r != 0) {
goto cleanup; goto cleanup;
}
lt_set_dict_id(tree, dict_id); lt_set_dict_id(tree, dict_id);
/* add tree to ltm */ /* add tree to ltm */
r = ltm_add_lt(mgr, tree); r = ltm_add_lt(mgr, tree);
if (r != 0) if (r != 0) {
goto cleanup; goto cleanup;
}
added_to_ltm = TRUE; added_to_ltm = TRUE;
toku_lt_update_descriptor(tree, desc);
tree->fake_db.cmp_descriptor = &tree->desc_s;
/* add mapping to idlth*/ /* add mapping to idlth*/
r = toku_idlth_insert(mgr->idlth, dict_id); r = toku_idlth_insert(mgr->idlth, dict_id);
if (r != 0) if (r != 0) {
goto cleanup; goto cleanup;
}
added_to_idlth = TRUE; added_to_idlth = TRUE;
lt_add_db(tree, db);
added_extant_db = TRUE;
map = toku_idlth_find(mgr->idlth, dict_id); map = toku_idlth_find(mgr->idlth, dict_id);
assert(map); assert(map);
map->tree = tree; map->tree = tree;
...@@ -1446,8 +1430,6 @@ cleanup: ...@@ -1446,8 +1430,6 @@ cleanup:
ltm_remove_lt(mgr, tree); ltm_remove_lt(mgr, tree);
if (added_to_idlth) if (added_to_idlth)
toku_idlth_delete(mgr->idlth, dict_id); toku_idlth_delete(mgr->idlth, dict_id);
if (added_extant_db)
lt_remove_db(tree, db);
toku_lt_close(tree); toku_lt_close(tree);
ltm_mutex_unlock(mgr); ltm_mutex_unlock(mgr);
} }
...@@ -1485,10 +1467,12 @@ toku_lt_close(toku_lock_tree* tree) { ...@@ -1485,10 +1467,12 @@ toku_lt_close(toku_lock_tree* tree) {
if (!first_error && r != 0) if (!first_error && r != 0)
first_error = r; first_error = r;
} }
if (tree->desc_s.dbt.data) {
toku_free(tree->desc_s.dbt.data);
tree->desc_s.dbt.data = NULL;
}
ltm_decr_locks(tree->mgr, ranges); ltm_decr_locks(tree->mgr, ranges);
toku_rth_close(tree->txns_to_unlock);
toku_rth_close(tree->rth); toku_rth_close(tree->rth);
toku_omt_destroy(&tree->dbs);
toku_mutex_destroy(&tree->mutex); toku_mutex_destroy(&tree->mutex);
toku_free(tree->buf); toku_free(tree->buf);
toku_free(tree->bw_buf); toku_free(tree->bw_buf);
...@@ -1500,7 +1484,7 @@ cleanup: ...@@ -1500,7 +1484,7 @@ cleanup:
} }
static int static int
lt_try_acquire_range_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DBT* key_left, const DBT* key_right) { lt_try_acquire_range_read_lock(toku_lock_tree* tree, TXNID txn, const DBT* key_left, const DBT* key_right) {
assert(tree && tree->mutex_locked); // locked by this thread assert(tree && tree->mutex_locked); // locked by this thread
int r; int r;
...@@ -1509,7 +1493,7 @@ lt_try_acquire_range_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DB ...@@ -1509,7 +1493,7 @@ lt_try_acquire_range_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DB
toku_interval query; toku_interval query;
bool dominated; bool dominated;
r = lt_preprocess(tree, db, txn, key_left, key_right, &left, &right, &query); r = lt_preprocess(tree, txn, key_left, key_right, &left, &right, &query);
if (r != 0) if (r != 0)
goto cleanup; goto cleanup;
...@@ -1558,8 +1542,6 @@ lt_try_acquire_range_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DB ...@@ -1558,8 +1542,6 @@ lt_try_acquire_range_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DB
r = 0; r = 0;
cleanup: cleanup:
if (tree)
lt_postprocess(tree);
return r; return r;
} }
...@@ -1755,14 +1737,6 @@ lt_do_escalation(toku_lock_tree* lt) { ...@@ -1755,14 +1737,6 @@ lt_do_escalation(toku_lock_tree* lt) {
assert(lt && lt->mutex_locked); assert(lt && lt->mutex_locked);
int r = ENOSYS; int r = ENOSYS;
DB* db; // extract db from lt
OMTVALUE dbv;
assert(toku_omt_size(lt->dbs) > 0); // there is at least one db associated with this locktree
r = toku_omt_fetch(lt->dbs, 0, &dbv);
assert_zero(r);
db = dbv;
lt_set_comparison_functions(lt, db);
if (!lt->lock_escalation_allowed) { if (!lt->lock_escalation_allowed) {
r = 0; goto cleanup; r = 0; goto cleanup;
...@@ -1783,7 +1757,6 @@ lt_do_escalation(toku_lock_tree* lt) { ...@@ -1783,7 +1757,6 @@ lt_do_escalation(toku_lock_tree* lt) {
r = 0; r = 0;
cleanup: cleanup:
lt_clear_comparison_functions(lt);
return r; return r;
} }
...@@ -1807,16 +1780,16 @@ ltm_do_escalation(toku_ltm* mgr) { ...@@ -1807,16 +1780,16 @@ ltm_do_escalation(toku_ltm* mgr) {
} }
static int static int
lt_acquire_range_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DBT* key_left, const DBT* key_right, bool do_escalation) { lt_acquire_range_read_lock(toku_lock_tree* tree, TXNID txn, const DBT* key_left, const DBT* key_right, bool do_escalation) {
int r = ENOSYS; int r = ENOSYS;
r = lt_try_acquire_range_read_lock(tree, db, txn, key_left, key_right); r = lt_try_acquire_range_read_lock(tree, txn, key_left, key_right);
if (r==TOKUDB_OUT_OF_LOCKS && do_escalation) { if (r==TOKUDB_OUT_OF_LOCKS && do_escalation) {
lt_mutex_unlock(tree); lt_mutex_unlock(tree);
r = ltm_do_escalation(tree->mgr); r = ltm_do_escalation(tree->mgr);
lt_mutex_lock(tree); lt_mutex_lock(tree);
if (r == 0) { if (r == 0) {
r = lt_try_acquire_range_read_lock(tree, db, txn, key_left, key_right); r = lt_try_acquire_range_read_lock(tree, txn, key_left, key_right);
if (r == 0) { if (r == 0) {
tree->mgr->STATUS_VALUE(LTM_LOCK_ESCALATION_SUCCESSES)++; tree->mgr->STATUS_VALUE(LTM_LOCK_ESCALATION_SUCCESSES)++;
} }
...@@ -1840,25 +1813,25 @@ lt_acquire_range_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DBT* k ...@@ -1840,25 +1813,25 @@ lt_acquire_range_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DBT* k
} }
int int
toku_lt_acquire_range_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DBT* key_left, const DBT *key_right) { toku_lt_acquire_range_read_lock(toku_lock_tree* tree, TXNID txn, const DBT* key_left, const DBT *key_right) {
int r = 0; int r = 0;
if (!tree || !db || !key_left || !key_right) if (!tree || !key_left || !key_right)
r = EINVAL; r = EINVAL;
if (r == 0) { if (r == 0) {
lt_mutex_lock(tree); lt_mutex_lock(tree);
r = lt_acquire_range_read_lock(tree, db, txn, key_left, key_right, true); r = lt_acquire_range_read_lock(tree, txn, key_left, key_right, true);
lt_mutex_unlock(tree); lt_mutex_unlock(tree);
} }
return r; return r;
} }
int int
toku_lt_acquire_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DBT* key) { toku_lt_acquire_read_lock(toku_lock_tree* tree, TXNID txn, const DBT* key) {
return toku_lt_acquire_range_read_lock(tree, db, txn, key, key); return toku_lt_acquire_range_read_lock(tree, txn, key, key);
} }
static int static int
lt_try_acquire_range_write_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DBT* key_left, const DBT* key_right) { lt_try_acquire_range_write_lock(toku_lock_tree* tree, TXNID txn, const DBT* key_left, const DBT* key_right) {
assert(tree->mutex_locked); assert(tree->mutex_locked);
int r; int r;
...@@ -1866,7 +1839,7 @@ lt_try_acquire_range_write_lock(toku_lock_tree* tree, DB* db, TXNID txn, const D ...@@ -1866,7 +1839,7 @@ lt_try_acquire_range_write_lock(toku_lock_tree* tree, DB* db, TXNID txn, const D
toku_point right; toku_point right;
toku_interval query; toku_interval query;
r = lt_preprocess(tree, db, txn, key_left, key_right, &left, &right, &query); r = lt_preprocess(tree, txn, key_left, key_right, &left, &right, &query);
if (r != 0) if (r != 0)
goto cleanup; goto cleanup;
...@@ -1940,22 +1913,20 @@ lt_try_acquire_range_write_lock(toku_lock_tree* tree, DB* db, TXNID txn, const D ...@@ -1940,22 +1913,20 @@ lt_try_acquire_range_write_lock(toku_lock_tree* tree, DB* db, TXNID txn, const D
goto cleanup; goto cleanup;
} }
cleanup: cleanup:
if (tree)
lt_postprocess(tree);
return r; return r;
} }
static int static int
lt_acquire_range_write_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DBT* key_left, const DBT* key_right, bool do_escalation) { lt_acquire_range_write_lock(toku_lock_tree* tree, TXNID txn, const DBT* key_left, const DBT* key_right, bool do_escalation) {
int r = ENOSYS; int r = ENOSYS;
r = lt_try_acquire_range_write_lock(tree, db, txn, key_left, key_right); r = lt_try_acquire_range_write_lock(tree, txn, key_left, key_right);
if (r == TOKUDB_OUT_OF_LOCKS && do_escalation) { if (r == TOKUDB_OUT_OF_LOCKS && do_escalation) {
lt_mutex_unlock(tree); lt_mutex_unlock(tree);
r = ltm_do_escalation(tree->mgr); r = ltm_do_escalation(tree->mgr);
lt_mutex_lock(tree); lt_mutex_lock(tree);
if (r == 0) { if (r == 0) {
r = lt_try_acquire_range_write_lock(tree, db, txn, key_left, key_right); r = lt_try_acquire_range_write_lock(tree, txn, key_left, key_right);
if (r == 0) { if (r == 0) {
tree->mgr->STATUS_VALUE(LTM_LOCK_ESCALATION_SUCCESSES)++; tree->mgr->STATUS_VALUE(LTM_LOCK_ESCALATION_SUCCESSES)++;
} }
...@@ -1979,21 +1950,21 @@ lt_acquire_range_write_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DBT* ...@@ -1979,21 +1950,21 @@ lt_acquire_range_write_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DBT*
} }
int int
toku_lt_acquire_range_write_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DBT* key_left, const DBT* key_right) { toku_lt_acquire_range_write_lock(toku_lock_tree* tree, TXNID txn, const DBT* key_left, const DBT* key_right) {
int r = 0; int r = 0;
if (!tree || !db || !key_left || !key_right) if (!tree || !key_left || !key_right)
r = EINVAL; r = EINVAL;
if (r == 0) { if (r == 0) {
lt_mutex_lock(tree); lt_mutex_lock(tree);
r = lt_acquire_range_write_lock(tree, db, txn, key_left, key_right, true); r = lt_acquire_range_write_lock(tree, txn, key_left, key_right, true);
lt_mutex_unlock(tree); lt_mutex_unlock(tree);
} }
return r; return r;
} }
int int
toku_lt_acquire_write_lock(toku_lock_tree* tree, DB* db, TXNID txn, const DBT* key) { toku_lt_acquire_write_lock(toku_lock_tree* tree, TXNID txn, const DBT* key) {
return toku_lt_acquire_range_write_lock(tree, db, txn, key, key); return toku_lt_acquire_range_write_lock(tree, txn, key, key);
} }
#if TOKU_LT_USE_BORDERWRITE #if TOKU_LT_USE_BORDERWRITE
...@@ -2122,14 +2093,7 @@ lt_unlock_txn(toku_lock_tree* tree, TXNID txn) { ...@@ -2122,14 +2093,7 @@ lt_unlock_txn(toku_lock_tree* tree, TXNID txn) {
if (selfwrite) { if (selfwrite) {
ranges += toku_rt_get_size(selfwrite); ranges += toku_rt_get_size(selfwrite);
assert(toku_omt_size(tree->dbs) > 0);
OMTVALUE dbv;
r = toku_omt_fetch(tree->dbs, 0, &dbv);
assert_zero(r);
DB *db = dbv;
lt_set_comparison_functions(tree, db);
r = lt_border_delete(tree, selfwrite); r = lt_border_delete(tree, selfwrite);
lt_clear_comparison_functions(tree);
if (r != 0) if (r != 0)
return lt_panic(tree, r); return lt_panic(tree, r);
...@@ -2159,31 +2123,13 @@ toku_lt_unlock_txn(toku_lock_tree* tree, TXNID txn) { ...@@ -2159,31 +2123,13 @@ toku_lt_unlock_txn(toku_lock_tree* tree, TXNID txn) {
r = EINVAL; goto cleanup; r = EINVAL; goto cleanup;
} }
lt_mutex_lock(tree); lt_mutex_lock(tree);
if (toku_omt_size(tree->dbs) > 0) {
lt_unlock_txn(tree, txn); lt_unlock_txn(tree, txn);
lt_retry_lock_requests(tree); lt_retry_lock_requests(tree);
} else {
r = toku_rth_insert(tree->txns_to_unlock, txn);
}
lt_mutex_unlock(tree); lt_mutex_unlock(tree);
cleanup: cleanup:
return r; return r;
} }
static void
lt_unlock_deferred_txns(toku_lock_tree *tree) {
lt_mutex_lock(tree);
toku_rth_start_scan(tree->txns_to_unlock);
rt_forest *forest;
while ((forest = toku_rth_next(tree->txns_to_unlock)) != NULL) {
TXNID txn = forest->hash_key;
lt_unlock_txn(tree, txn);
}
toku_rth_clear(tree->txns_to_unlock);
lt_retry_lock_requests(tree);
lt_mutex_unlock(tree);
}
void void
toku_lt_add_ref(toku_lock_tree* tree) { toku_lt_add_ref(toku_lock_tree* tree) {
assert(tree); assert(tree);
...@@ -2222,52 +2168,8 @@ cleanup: ...@@ -2222,52 +2168,8 @@ cleanup:
return r; return r;
} }
//Heaviside function to find a DB by DB (used to find the index) (just sort by pointer addr)
static int
find_db (OMTVALUE v, void *dbv) {
DB *db = v;
DB *dbfind = dbv;
if (db < dbfind)
return -1;
if (db > dbfind)
return +1;
return 0;
}
static void
lt_add_db(toku_lock_tree* tree, DB *db) {
lt_mutex_lock(tree);
if (db != NULL) {
int r;
OMTVALUE get_dbv = NULL;
uint32_t index;
r = toku_omt_find_zero(tree->dbs, find_db, db, &get_dbv, &index);
assert(r == DB_NOTFOUND);
r = toku_omt_insert_at(tree->dbs, db, index);
assert_zero(r);
}
lt_mutex_unlock(tree);
}
static void
lt_remove_db(toku_lock_tree* tree, DB *db) {
lt_mutex_lock(tree);
if (db != NULL) {
int r;
OMTVALUE get_dbv = NULL;
uint32_t index;
r = toku_omt_find_zero(tree->dbs, find_db, db, &get_dbv, &index);
assert_zero(r);
assert(db == get_dbv);
r = toku_omt_delete_at(tree->dbs, index);
assert_zero(r);
}
lt_mutex_unlock(tree);
}
void void
toku_lt_remove_db_ref(toku_lock_tree* tree, DB *db) { toku_lt_remove_db_ref(toku_lock_tree* tree) {
lt_remove_db(tree, db);
int r = toku_lt_remove_ref(tree); int r = toku_lt_remove_ref(tree);
assert_zero(r); assert_zero(r);
} }
...@@ -2290,7 +2192,6 @@ lock_request_destroy_wait(toku_lock_request *lock_request) { ...@@ -2290,7 +2192,6 @@ lock_request_destroy_wait(toku_lock_request *lock_request) {
void void
toku_lock_request_default_init(toku_lock_request *lock_request) { toku_lock_request_default_init(toku_lock_request *lock_request) {
lock_request->db = NULL;
lock_request->txnid = 0; lock_request->txnid = 0;
lock_request->key_left = lock_request->key_right = NULL; lock_request->key_left = lock_request->key_right = NULL;
lock_request->key_left_copy = (DBT) { .data = NULL, .size = 0, .flags = DB_DBT_REALLOC }; lock_request->key_left_copy = (DBT) { .data = NULL, .size = 0, .flags = DB_DBT_REALLOC };
...@@ -2303,9 +2204,8 @@ toku_lock_request_default_init(toku_lock_request *lock_request) { ...@@ -2303,9 +2204,8 @@ toku_lock_request_default_init(toku_lock_request *lock_request) {
} }
void void
toku_lock_request_set(toku_lock_request *lock_request, DB *db, TXNID txnid, const DBT *key_left, const DBT *key_right, toku_lock_type lock_type) { toku_lock_request_set(toku_lock_request *lock_request, TXNID txnid, const DBT *key_left, const DBT *key_right, toku_lock_type lock_type) {
assert(lock_request->state != LOCK_REQUEST_PENDING); assert(lock_request->state != LOCK_REQUEST_PENDING);
lock_request->db = db;
lock_request->txnid = txnid; lock_request->txnid = txnid;
lock_request->key_left = key_left; lock_request->key_left = key_left;
lock_request->key_right = key_right; lock_request->key_right = key_right;
...@@ -2314,9 +2214,9 @@ toku_lock_request_set(toku_lock_request *lock_request, DB *db, TXNID txnid, cons ...@@ -2314,9 +2214,9 @@ toku_lock_request_set(toku_lock_request *lock_request, DB *db, TXNID txnid, cons
} }
void void
toku_lock_request_init(toku_lock_request *lock_request, DB *db, TXNID txnid, const DBT *key_left, const DBT *key_right, toku_lock_type lock_type) { toku_lock_request_init(toku_lock_request *lock_request, TXNID txnid, const DBT *key_left, const DBT *key_right, toku_lock_type lock_type) {
toku_lock_request_default_init(lock_request); toku_lock_request_default_init(lock_request);
toku_lock_request_set(lock_request, db, txnid, key_left, key_right, lock_type); toku_lock_request_set(lock_request, txnid, key_left, key_right, lock_type);
} }
void void
...@@ -2502,10 +2402,10 @@ lock_request_start(toku_lock_request *lock_request, toku_lock_tree *tree, bool c ...@@ -2502,10 +2402,10 @@ lock_request_start(toku_lock_request *lock_request, toku_lock_tree *tree, bool c
int r = 0; int r = 0;
switch (lock_request->type) { switch (lock_request->type) {
case LOCK_REQUEST_READ: case LOCK_REQUEST_READ:
r = lt_acquire_range_read_lock(tree, lock_request->db, lock_request->txnid, lock_request->key_left, lock_request->key_right, do_escalation); r = lt_acquire_range_read_lock(tree, lock_request->txnid, lock_request->key_left, lock_request->key_right, do_escalation);
break; break;
case LOCK_REQUEST_WRITE: case LOCK_REQUEST_WRITE:
r = lt_acquire_range_write_lock(tree, lock_request->db, lock_request->txnid, lock_request->key_left, lock_request->key_right, do_escalation); r = lt_acquire_range_write_lock(tree, lock_request->txnid, lock_request->key_left, lock_request->key_right, do_escalation);
break; break;
case LOCK_REQUEST_UNKNOWN: case LOCK_REQUEST_UNKNOWN:
assert(0); assert(0);
...@@ -2680,7 +2580,6 @@ toku_lt_get_lock_request_conflicts(toku_lock_tree *tree, toku_lock_request *lock ...@@ -2680,7 +2580,6 @@ toku_lt_get_lock_request_conflicts(toku_lock_tree *tree, toku_lock_request *lock
toku_point left; init_point(&left, tree, lock_request->key_left); toku_point left; init_point(&left, tree, lock_request->key_left);
toku_point right; init_point(&right, tree, lock_request->key_right); toku_point right; init_point(&right, tree, lock_request->key_right);
toku_interval query; init_query(&query, &left, &right); toku_interval query; init_query(&query, &left, &right);
lt_set_comparison_functions(tree, lock_request->db);
uint32_t n_expected_ranges = 0; uint32_t n_expected_ranges = 0;
toku_range *ranges = NULL; toku_range *ranges = NULL;
...@@ -2702,7 +2601,6 @@ toku_lt_get_lock_request_conflicts(toku_lock_tree *tree, toku_lock_request *lock ...@@ -2702,7 +2601,6 @@ toku_lt_get_lock_request_conflicts(toku_lock_tree *tree, toku_lock_request *lock
if (ranges) if (ranges)
toku_free(ranges); toku_free(ranges);
lt_clear_comparison_functions(tree);
return r; return r;
} }
...@@ -2784,11 +2682,9 @@ lt_verify(toku_lock_tree *lt) { ...@@ -2784,11 +2682,9 @@ lt_verify(toku_lock_tree *lt) {
} }
void void
toku_lt_verify(toku_lock_tree *lt, DB *db) { toku_lt_verify(toku_lock_tree *lt) {
lt_mutex_lock(lt); lt_mutex_lock(lt);
lt_set_comparison_functions(lt, db);
lt_verify(lt); lt_verify(lt);
lt_clear_comparison_functions(lt);
lt_mutex_unlock(lt); lt_mutex_unlock(lt);
} }
......
...@@ -108,10 +108,14 @@ void toku_ltm_set_lock_wait_time(toku_ltm *mgr, uint64_t lock_wait_time_msec); ...@@ -108,10 +108,14 @@ void toku_ltm_set_lock_wait_time(toku_ltm *mgr, uint64_t lock_wait_time_msec);
// get the default lock timeout // get the default lock timeout
void toku_ltm_get_lock_wait_time(toku_ltm *mgr, uint64_t *lock_wait_time_msec); void toku_ltm_get_lock_wait_time(toku_ltm *mgr, uint64_t *lock_wait_time_msec);
void
toku_lt_update_descriptor(toku_lock_tree* tree, DESCRIPTOR desc);
/** /**
Gets a lock tree for a given DB with id dict_id Gets a lock tree for a given DB with id dict_id
*/ */
int toku_ltm_get_lt(toku_ltm* mgr, toku_lock_tree** ptree, DICTIONARY_ID dict_id, DB *dbp, toku_dbt_cmp compare_fun); int toku_ltm_get_lt(toku_ltm* mgr, toku_lock_tree** ptree, DICTIONARY_ID dict_id, DESCRIPTOR desc, toku_dbt_cmp compare_fun);
void toku_ltm_invalidate_lt(toku_ltm* mgr, DICTIONARY_ID dict_id); void toku_ltm_invalidate_lt(toku_ltm* mgr, DICTIONARY_ID dict_id);
...@@ -185,7 +189,7 @@ int toku_lt_close(toku_lock_tree* tree); ...@@ -185,7 +189,7 @@ int toku_lt_close(toku_lock_tree* tree);
no transactions). This can cause conflicts, nobody was able (so far) no transactions). This can cause conflicts, nobody was able (so far)
to verify that MySQL does or does not use this. to verify that MySQL does or does not use this.
*/ */
int toku_lt_acquire_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, int toku_lt_acquire_read_lock(toku_lock_tree* tree, TXNID txn,
const DBT* key); const DBT* key);
/* /*
...@@ -220,7 +224,7 @@ int toku_lt_acquire_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, ...@@ -220,7 +224,7 @@ int toku_lt_acquire_read_lock(toku_lock_tree* tree, DB* db, TXNID txn,
no transactions). This can cause conflicts, nobody was able (so far) no transactions). This can cause conflicts, nobody was able (so far)
to verify that MySQL does or does not use this. to verify that MySQL does or does not use this.
*/ */
int toku_lt_acquire_range_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, int toku_lt_acquire_range_read_lock(toku_lock_tree* tree, TXNID txn,
const DBT* key_left, const DBT* key_left,
const DBT* key_right); const DBT* key_right);
...@@ -250,7 +254,7 @@ int toku_lt_acquire_range_read_lock(toku_lock_tree* tree, DB* db, TXNID txn, ...@@ -250,7 +254,7 @@ int toku_lt_acquire_range_read_lock(toku_lock_tree* tree, DB* db, TXNID txn,
If the lock tree needs to hold onto the key or data, it will make copies If the lock tree needs to hold onto the key or data, it will make copies
to its local memory. to its local memory.
*/ */
int toku_lt_acquire_write_lock(toku_lock_tree* tree, DB* db, TXNID txn, int toku_lt_acquire_write_lock(toku_lock_tree* tree, TXNID txn,
const DBT* key); const DBT* key);
//In BDB, txn can actually be NULL (mixed operations with transactions and no transactions). //In BDB, txn can actually be NULL (mixed operations with transactions and no transactions).
...@@ -285,7 +289,7 @@ int toku_lt_acquire_write_lock(toku_lock_tree* tree, DB* db, TXNID txn, ...@@ -285,7 +289,7 @@ int toku_lt_acquire_write_lock(toku_lock_tree* tree, DB* db, TXNID txn,
* to its local memory. * to its local memory.
* *** Note that txn == NULL is not supported at this time. * *** Note that txn == NULL is not supported at this time.
*/ */
int toku_lt_acquire_range_write_lock(toku_lock_tree* tree, DB* db, TXNID txn, int toku_lt_acquire_range_write_lock(toku_lock_tree* tree, TXNID txn,
const DBT* key_left, const DBT* key_left,
const DBT* key_right); const DBT* key_right);
...@@ -311,9 +315,9 @@ void toku_lt_add_ref(toku_lock_tree* tree); ...@@ -311,9 +315,9 @@ void toku_lt_add_ref(toku_lock_tree* tree);
int toku_lt_remove_ref(toku_lock_tree* tree); int toku_lt_remove_ref(toku_lock_tree* tree);
void toku_lt_remove_db_ref(toku_lock_tree* tree, DB *db); void toku_lt_remove_db_ref(toku_lock_tree* tree);
void toku_lt_verify(toku_lock_tree *tree, DB *db); void toku_lt_verify(toku_lock_tree *tree);
typedef enum { typedef enum {
LOCK_REQUEST_INIT = 0, LOCK_REQUEST_INIT = 0,
...@@ -342,7 +346,6 @@ typedef enum { ...@@ -342,7 +346,6 @@ typedef enum {
// this is exposed so that we can allocate these as local variables. don't touch // this is exposed so that we can allocate these as local variables. don't touch
typedef struct { typedef struct {
DB *db;
TXNID txnid; TXNID txnid;
const DBT *key_left; const DBT *key_right; const DBT *key_left; const DBT *key_right;
DBT key_left_copy, key_right_copy; DBT key_left_copy, key_right_copy;
...@@ -359,10 +362,10 @@ void toku_lock_request_default_init(toku_lock_request *lock_request); ...@@ -359,10 +362,10 @@ void toku_lock_request_default_init(toku_lock_request *lock_request);
// initialize the lock request parameters. // initialize the lock request parameters.
// this API allows a lock request to be reused. // this API allows a lock request to be reused.
void toku_lock_request_set(toku_lock_request *lock_request, DB *db, TXNID txnid, const DBT *key_left, const DBT *key_right, toku_lock_type type); void toku_lock_request_set(toku_lock_request *lock_request, TXNID txnid, const DBT *key_left, const DBT *key_right, toku_lock_type type);
// initialize and set the parameters for a lock request. it is equivalent to _default_init followed by _set. // initialize and set the parameters for a lock request. it is equivalent to _default_init followed by _set.
void toku_lock_request_init(toku_lock_request *lock_request, DB *db, TXNID txnid, const DBT *key_left, const DBT *key_right, toku_lock_type type); void toku_lock_request_init(toku_lock_request *lock_request, TXNID txnid, const DBT *key_left, const DBT *key_right, toku_lock_type type);
// destroy a lock request. // destroy a lock request.
void toku_lock_request_destroy(toku_lock_request *lock_request); void toku_lock_request_destroy(toku_lock_request *lock_request);
......
...@@ -41,10 +41,8 @@ int main(int argc, const char *argv[]) { ...@@ -41,10 +41,8 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *db_a = (DB *) 2;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, db_a, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
TXNID txn_a = 1; TXNID txn_a = 1;
...@@ -52,14 +50,14 @@ int main(int argc, const char *argv[]) { ...@@ -52,14 +50,14 @@ int main(int argc, const char *argv[]) {
// acquire the locks on keys 0 .. nrows-1 // acquire the locks on keys 0 .. nrows-1
for (uint64_t k = 0; k < nrows; k++) { for (uint64_t k = 0; k < nrows; k++) {
DBT key = { .data = &k, .size = sizeof k }; DBT key = { .data = &k, .size = sizeof k };
r = toku_lt_acquire_write_lock(lt, db_a, txn_a, &key); assert(r == 0); r = toku_lt_acquire_write_lock(lt, txn_a, &key); assert(r == 0);
} }
// release the locks // release the locks
r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, db_a); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -38,7 +38,6 @@ static void release_locks(uint64_t keys[], int n, TXNID txn) { ...@@ -38,7 +38,6 @@ static void release_locks(uint64_t keys[], int n, TXNID txn) {
} }
struct test_arg { struct test_arg {
DB *db;
TXNID txn; TXNID txn;
toku_ltm *ltm; toku_ltm *ltm;
toku_lock_tree *lt; toku_lock_tree *lt;
...@@ -47,7 +46,7 @@ struct test_arg { ...@@ -47,7 +46,7 @@ struct test_arg {
uint64_t iterations; uint64_t iterations;
}; };
static void runtest(DB *db, TXNID txn, toku_ltm *ltm UU(), toku_lock_tree *lt, uint64_t locks_per_txn, uint64_t nrows, uint64_t iterations) { static void runtest(TXNID txn, toku_ltm *ltm UU(), toku_lock_tree *lt, uint64_t locks_per_txn, uint64_t nrows, uint64_t iterations) {
int r; int r;
uint64_t notgranted = 0, deadlocked = 0; uint64_t notgranted = 0, deadlocked = 0;
...@@ -59,7 +58,7 @@ static void runtest(DB *db, TXNID txn, toku_ltm *ltm UU(), toku_lock_tree *lt, u ...@@ -59,7 +58,7 @@ static void runtest(DB *db, TXNID txn, toku_ltm *ltm UU(), toku_lock_tree *lt, u
for (i = 0; i < locks_per_txn; i++) { for (i = 0; i < locks_per_txn; i++) {
DBT key = { .data = &keys[i], .size = sizeof keys[i] }; DBT key = { .data = &keys[i], .size = sizeof keys[i] };
toku_lock_request lr; toku_lock_request lr;
toku_lock_request_init(&lr, db, txn, &key, &key, LOCK_REQUEST_WRITE); toku_lock_request_init(&lr, txn, &key, &key, LOCK_REQUEST_WRITE);
r = toku_lt_acquire_lock_request_with_default_timeout(lt, &lr); r = toku_lt_acquire_lock_request_with_default_timeout(lt, &lr);
if (r == 0) { if (r == 0) {
get_lock(keys[i], txn); get_lock(keys[i], txn);
...@@ -87,7 +86,7 @@ static void runtest(DB *db, TXNID txn, toku_ltm *ltm UU(), toku_lock_tree *lt, u ...@@ -87,7 +86,7 @@ static void runtest(DB *db, TXNID txn, toku_ltm *ltm UU(), toku_lock_tree *lt, u
static void *runtest_wrapper(void *arg_wrapper) { static void *runtest_wrapper(void *arg_wrapper) {
struct test_arg *arg = (struct test_arg *) arg_wrapper; struct test_arg *arg = (struct test_arg *) arg_wrapper;
runtest(arg->db, arg->txn, arg->ltm, arg->lt, arg->locks_per_txn, arg->nrows, arg->iterations); runtest(arg->txn, arg->ltm, arg->lt, arg->locks_per_txn, arg->nrows, arg->iterations);
return arg; return arg;
} }
...@@ -142,20 +141,18 @@ int main(int argc, const char *argv[]) { ...@@ -142,20 +141,18 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
toku_pthread_t tids[nthreads]; toku_pthread_t tids[nthreads];
struct test_arg args[nthreads]; struct test_arg args[nthreads];
for (uint64_t i = 1; i < nthreads; i++) { for (uint64_t i = 1; i < nthreads; i++) {
args[i] = (struct test_arg) { fake_db, (TXNID) i, ltm, lt, locks_per_txn, nrows, iterations }; args[i] = (struct test_arg) { (TXNID) i, ltm, lt, locks_per_txn, nrows, iterations };
toku_pthread_create(&tids[i], NULL, runtest_wrapper, &args[i]); toku_pthread_create(&tids[i], NULL, runtest_wrapper, &args[i]);
} }
runtest(fake_db, (TXNID)nthreads, ltm, lt, locks_per_txn, nrows, iterations); runtest((TXNID)nthreads, ltm, lt, locks_per_txn, nrows, iterations);
for (uint64_t i = 1; i < nthreads; i++) { for (uint64_t i = 1; i < nthreads; i++) {
void *retptr; void *retptr;
...@@ -163,7 +160,7 @@ int main(int argc, const char *argv[]) { ...@@ -163,7 +160,7 @@ int main(int argc, const char *argv[]) {
} }
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -10,12 +10,11 @@ uint32_t max_locks = MAX_LT_LOCKS; ...@@ -10,12 +10,11 @@ uint32_t max_locks = MAX_LT_LOCKS;
uint64_t max_lock_memory = MAX_LT_LOCKS*64; uint64_t max_lock_memory = MAX_LT_LOCKS*64;
toku_ltm* ltm = NULL; toku_ltm* ltm = NULL;
static void do_range_test(int (*acquire)(toku_lock_tree*, DB*, TXNID, static void do_range_test(int (*acquire)(toku_lock_tree*, TXNID,
const DBT*, const DBT*,
const DBT*)) { const DBT*)) {
int r; int r;
toku_lock_tree* lt = NULL; toku_lock_tree* lt = NULL;
DB* db = (DB*)1;
TXNID txn = (TXNID)1; // Fake. TXNID txn = (TXNID)1; // Fake.
DBT _key_l = _key; DBT _key_l = _key;
DBT _key_r = _key; DBT _key_r = _key;
...@@ -27,21 +26,21 @@ static void do_range_test(int (*acquire)(toku_lock_tree*, DB*, TXNID, ...@@ -27,21 +26,21 @@ static void do_range_test(int (*acquire)(toku_lock_tree*, DB*, TXNID,
CKERR(r); CKERR(r);
assert(lt); assert(lt);
r = acquire(NULL, db, txn, key_l, key_r); r = acquire(NULL, txn, key_l, key_r);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = acquire(lt, db, txn, NULL, key_r); r = acquire(lt, txn, NULL, key_r);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = acquire(lt, db, txn, key_l, NULL); r = acquire(lt, txn, key_l, NULL);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
/* left > right tests. */ /* left > right tests. */
const DBT* inf = toku_lt_infinity; const DBT* inf = toku_lt_infinity;
const DBT* ninf = toku_lt_neg_infinity; const DBT* ninf = toku_lt_neg_infinity;
r = acquire(lt, db, txn, inf, key_r); r = acquire(lt, txn, inf, key_r);
CKERR2(r, EDOM); CKERR2(r, EDOM);
r = acquire(lt, db, txn, key_l, ninf); r = acquire(lt, txn, key_l, ninf);
CKERR2(r, EDOM); CKERR2(r, EDOM);
r = acquire(lt, db, txn, inf, ninf); r = acquire(lt, txn, inf, ninf);
CKERR2(r, EDOM); CKERR2(r, EDOM);
/* Cleanup. */ /* Cleanup. */
...@@ -52,12 +51,11 @@ static void do_range_test(int (*acquire)(toku_lock_tree*, DB*, TXNID, ...@@ -52,12 +51,11 @@ static void do_range_test(int (*acquire)(toku_lock_tree*, DB*, TXNID,
} }
} }
static void do_point_test(int (*acquire)(toku_lock_tree*, DB*, TXNID, static void do_point_test(int (*acquire)(toku_lock_tree*, TXNID,
const DBT*)) { const DBT*)) {
int r; int r;
toku_lock_tree* lt = NULL; toku_lock_tree* lt = NULL;
TXNID txn = (TXNID)1; // Fake. TXNID txn = (TXNID)1; // Fake.
DB* db = (DB*)0x1;
lt = NULL; lt = NULL;
...@@ -71,10 +69,10 @@ static void do_point_test(int (*acquire)(toku_lock_tree*, DB*, TXNID, ...@@ -71,10 +69,10 @@ static void do_point_test(int (*acquire)(toku_lock_tree*, DB*, TXNID,
r = toku_lt_unlock_txn(NULL, (TXNID)1); r = toku_lt_unlock_txn(NULL, (TXNID)1);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = acquire(NULL, db, txn, key); r = acquire(NULL, txn, key);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = acquire(lt, db, txn, NULL); r = acquire(lt, txn, NULL);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
/* Cleanup. */ /* Cleanup. */
......
...@@ -40,14 +40,12 @@ static void init_query(void) { ...@@ -40,14 +40,12 @@ static void init_query(void) {
query.right = &qright; query.right = &qright;
} }
static DB *fake_db = (DB *) 1;
static void setup_tree(void) { static void setup_tree(void) {
assert(!lt && !ltm); assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
CKERR(r); CKERR(r);
assert(ltm); assert(ltm);
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
init_query(); init_query();
...@@ -56,7 +54,7 @@ static void setup_tree(void) { ...@@ -56,7 +54,7 @@ static void setup_tree(void) {
static void close_tree(void) { static void close_tree(void) {
r = toku_lt_unlock_txn(lt, txn); CKERR(r); r = toku_lt_unlock_txn(lt, txn); CKERR(r);
assert(lt && ltm); assert(lt && ltm);
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); CKERR(r); r = toku_ltm_close(ltm); CKERR(r);
lt = NULL; lt = NULL;
ltm = NULL; ltm = NULL;
...@@ -84,9 +82,9 @@ static void lt_insert(int key_l, int key_r) { ...@@ -84,9 +82,9 @@ static void lt_insert(int key_l, int key_r) {
assert(key_left); assert(key_left);
assert(key_right); assert(key_right);
r = toku_lt_acquire_range_read_lock(lt, db, txn, key_left, key_right); r = toku_lt_acquire_range_read_lock(lt, txn, key_left, key_right);
CKERR(r); CKERR(r);
toku_lt_verify(lt, db); toku_lt_verify(lt);
} }
static void setup_payload_len(void** payload, uint32_t* len, int val) { static void setup_payload_len(void** payload, uint32_t* len, int val) {
...@@ -142,11 +140,11 @@ static void insert_1(int key_l, int key_r, ...@@ -142,11 +140,11 @@ static void insert_1(int key_l, int key_r,
setup_tree(); setup_tree();
r = toku_lt_acquire_range_read_lock(lt, db, txn, key_left, key_right); CKERR(r); r = toku_lt_acquire_range_read_lock(lt, txn, key_left, key_right); CKERR(r);
close_tree(); close_tree();
setup_tree(); setup_tree();
r = toku_lt_acquire_read_lock(lt, db, txn, key_left); CKERR(r); r = toku_lt_acquire_read_lock(lt, txn, key_left); CKERR(r);
close_tree(); close_tree();
} }
......
...@@ -34,14 +34,12 @@ static void init_query(void) { ...@@ -34,14 +34,12 @@ static void init_query(void) {
query.right = &qright; query.right = &qright;
} }
static DB *fake_db = (DB *) 1;
static void setup_tree(void) { static void setup_tree(void) {
assert(!lt && !ltm); assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
CKERR(r); CKERR(r);
assert(ltm); assert(ltm);
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
init_query(); init_query();
...@@ -49,7 +47,7 @@ static void setup_tree(void) { ...@@ -49,7 +47,7 @@ static void setup_tree(void) {
static void close_tree(void) { static void close_tree(void) {
assert(lt && ltm); assert(lt && ltm);
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); r = toku_ltm_close(ltm);
CKERR(r); CKERR(r);
lt = NULL; lt = NULL;
...@@ -84,11 +82,11 @@ static void lt_insert(int r_expect, char txn, int key_l, ...@@ -84,11 +82,11 @@ static void lt_insert(int r_expect, char txn, int key_l,
TXNID local_txn = (TXNID) (size_t) txn; TXNID local_txn = (TXNID) (size_t) txn;
if (read_flag) if (read_flag)
r = toku_lt_acquire_range_read_lock(lt, db, local_txn, r = toku_lt_acquire_range_read_lock(lt, local_txn,
key_left, key_left,
key_right); key_right);
else else
r = toku_lt_acquire_write_lock(lt, db, local_txn, key_left); r = toku_lt_acquire_write_lock(lt, local_txn, key_left);
CKERR2(r, r_expect); CKERR2(r, r_expect);
} }
...@@ -110,13 +108,13 @@ static void lt_unlock(char ctxn) { ...@@ -110,13 +108,13 @@ static void lt_unlock(char ctxn) {
static void runtest(void) { static void runtest(void) {
setup_tree(); setup_tree();
lt_insert_write(0, 'a', 1); lt_insert_write(0, 'a', 1);
toku_lt_verify(lt, NULL); toku_lt_verify(lt);
lt_insert_write(0, 'a', 5); lt_insert_write(0, 'a', 5);
toku_lt_verify(lt, NULL); toku_lt_verify(lt);
lt_insert_write(0, 'a', 20); lt_insert_write(0, 'a', 20);
toku_lt_verify(lt, NULL); toku_lt_verify(lt);
lt_insert_write(0, 'b', 10); lt_insert_write(0, 'b', 10);
toku_lt_verify(lt, NULL); toku_lt_verify(lt);
lt_unlock('a'); lt_unlock('a');
lt_unlock('b'); lt_unlock('b');
close_tree(); close_tree();
......
...@@ -42,7 +42,7 @@ static void setup_tree(void) { ...@@ -42,7 +42,7 @@ static void setup_tree(void) {
assert(ltm); assert(ltm);
//ask ltm for lock tree //ask ltm for lock tree
DICTIONARY_ID dict_id = {0x1234}; DICTIONARY_ID dict_id = {0x1234};
r = toku_ltm_get_lt(ltm, &lt, dict_id, db, intcmp); r = toku_ltm_get_lt(ltm, &lt, dict_id, NULL, intcmp);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
...@@ -52,7 +52,7 @@ static void setup_tree(void) { ...@@ -52,7 +52,7 @@ static void setup_tree(void) {
static void close_tree(void) { static void close_tree(void) {
assert(lt && ltm); assert(lt && ltm);
toku_lt_remove_db_ref(lt, db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); r = toku_ltm_close(ltm);
CKERR(r); CKERR(r);
lt = NULL; lt = NULL;
...@@ -86,16 +86,16 @@ static void lt_insert(int r_expect, char txn, int key_l, int key_r, bool read_fl ...@@ -86,16 +86,16 @@ static void lt_insert(int r_expect, char txn, int key_l, int key_r, bool read_fl
TXNID local_txn = (TXNID) (size_t) txn; TXNID local_txn = (TXNID) (size_t) txn;
if (read_flag) if (read_flag)
r = toku_lt_acquire_range_read_lock(lt, db, local_txn, key_left, key_right); r = toku_lt_acquire_range_read_lock(lt, local_txn, key_left, key_right);
else else
r = toku_lt_acquire_write_lock(lt, db, local_txn, key_left); r = toku_lt_acquire_write_lock(lt, local_txn, key_left);
CKERR2(r, r_expect); CKERR2(r, r_expect);
} }
static int lt_insert_write_no_check(char txn, int key_p) { static int lt_insert_write_no_check(char txn, int key_p) {
DBT key; DBT key;
TXNID local_txn = (TXNID) (size_t) txn; TXNID local_txn = (TXNID) (size_t) txn;
r = toku_lt_acquire_write_lock(lt, db, local_txn, dbt_init(&key, &nums[key_p], sizeof(nums[0]))); r = toku_lt_acquire_write_lock(lt, local_txn, dbt_init(&key, &nums[key_p], sizeof(nums[0])));
return r; return r;
} }
......
...@@ -34,14 +34,12 @@ static void init_query(void) { ...@@ -34,14 +34,12 @@ static void init_query(void) {
query.right = &qright; query.right = &qright;
} }
static DB *fake_db = (DB *) 1;
static void setup_tree(void) { static void setup_tree(void) {
assert(!lt && !ltm); assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
CKERR(r); CKERR(r);
assert(ltm); assert(ltm);
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
init_query(); init_query();
...@@ -49,7 +47,7 @@ static void setup_tree(void) { ...@@ -49,7 +47,7 @@ static void setup_tree(void) {
static void close_tree(void) { static void close_tree(void) {
assert(lt && ltm); assert(lt && ltm);
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); CKERR(r); r = toku_ltm_close(ltm); CKERR(r);
lt = NULL; lt = NULL;
ltm = NULL; ltm = NULL;
...@@ -69,7 +67,7 @@ static DBT* set_to_infty(DBT *dbt, int value) { ...@@ -69,7 +67,7 @@ static DBT* set_to_infty(DBT *dbt, int value) {
} }
static void lt_verify(void) { static void lt_verify(void) {
toku_lt_verify(lt, NULL); toku_lt_verify(lt);
} }
static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r) { static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r) {
...@@ -83,7 +81,7 @@ static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r) ...@@ -83,7 +81,7 @@ static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r)
TXNID local_txn = (TXNID) (size_t) txn; TXNID local_txn = (TXNID) (size_t) txn;
r = toku_lt_acquire_range_write_lock(lt, db, local_txn, key_left, key_right); r = toku_lt_acquire_range_write_lock(lt, local_txn, key_left, key_right);
CKERR2(r, r_expect); CKERR2(r, r_expect);
lt_verify(); lt_verify();
} }
......
...@@ -41,10 +41,9 @@ int main(int argc, const char *argv[]) { ...@@ -41,10 +41,9 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
...@@ -54,32 +53,32 @@ int main(int argc, const char *argv[]) { ...@@ -54,32 +53,32 @@ int main(int argc, const char *argv[]) {
DBT key_m = { .data = "M", .size = 1 }; DBT key_m = { .data = "M", .size = 1 };
// txn_a gets W(L) // txn_a gets W(L)
toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0);
assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0); assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0);
toku_lock_request_destroy(&a_w_l); toku_lock_request_destroy(&a_w_l);
toku_lt_add_ref(lt); toku_lt_add_ref(lt);
// txn_b gets W(M) // txn_b gets W(M)
toku_lock_request b_w_m; toku_lock_request_init(&b_w_m, fake_db, txn_b, &key_m, &key_m, LOCK_REQUEST_WRITE); toku_lock_request b_w_m; toku_lock_request_init(&b_w_m, txn_b, &key_m, &key_m, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&b_w_m, lt, false); assert(r == 0); r = toku_lock_request_start(&b_w_m, lt, false); assert(r == 0);
assert(b_w_m.state == LOCK_REQUEST_COMPLETE && b_w_m.complete_r == 0); assert(b_w_m.state == LOCK_REQUEST_COMPLETE && b_w_m.complete_r == 0);
toku_lock_request_destroy(&b_w_m); toku_lock_request_destroy(&b_w_m);
toku_lt_add_ref(lt); toku_lt_add_ref(lt);
// start closing the lock tree // start closing the lock tree
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
// txn_a unlocks // txn_a unlocks
r = toku_lt_unlock_txn(lt, txn_a); r = toku_lt_unlock_txn(lt, txn_a);
toku_lt_remove_ref(lt); toku_lt_remove_ref(lt);
// reopen the lock tree // reopen the lock tree
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
// txn_b gets W(L) // txn_b gets W(L)
toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, txn_b, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&b_w_l, lt, false); assert(r == 0); r = toku_lock_request_start(&b_w_l, lt, false); assert(r == 0);
assert(b_w_l.state == LOCK_REQUEST_COMPLETE && b_w_l.complete_r == 0); assert(b_w_l.state == LOCK_REQUEST_COMPLETE && b_w_l.complete_r == 0);
toku_lock_request_destroy(&b_w_l); toku_lock_request_destroy(&b_w_l);
......
...@@ -46,10 +46,9 @@ int main(int argc, const char *argv[]) { ...@@ -46,10 +46,9 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
DBT key_l; dbt_init(&key_l, "L", 1); DBT key_l; dbt_init(&key_l, "L", 1);
...@@ -57,7 +56,7 @@ int main(int argc, const char *argv[]) { ...@@ -57,7 +56,7 @@ int main(int argc, const char *argv[]) {
txnid_set conflicts; txnid_set conflicts;
const TXNID txn_a = 1; const TXNID txn_a = 1;
toku_lock_request a_r_t; toku_lock_request_init(&a_r_t, fake_db, txn_a, toku_lt_neg_infinity, toku_lt_infinity, LOCK_REQUEST_READ); toku_lock_request a_r_t; toku_lock_request_init(&a_r_t, txn_a, toku_lt_neg_infinity, toku_lt_infinity, LOCK_REQUEST_READ);
r = toku_lock_request_start(&a_r_t, lt, false); assert(r == 0); r = toku_lock_request_start(&a_r_t, lt, false); assert(r == 0);
assert(a_r_t.state == LOCK_REQUEST_COMPLETE && a_r_t.complete_r == 0); assert(a_r_t.state == LOCK_REQUEST_COMPLETE && a_r_t.complete_r == 0);
txnid_set_init(&conflicts); txnid_set_init(&conflicts);
...@@ -68,7 +67,7 @@ int main(int argc, const char *argv[]) { ...@@ -68,7 +67,7 @@ int main(int argc, const char *argv[]) {
toku_lock_request_destroy(&a_r_t); toku_lock_request_destroy(&a_r_t);
const TXNID txn_b = 2; const TXNID txn_b = 2;
toku_lock_request b_r_l; toku_lock_request_init(&b_r_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request b_r_l; toku_lock_request_init(&b_r_l, txn_b, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&b_r_l, lt, false); assert(r == 0); r = toku_lock_request_start(&b_r_l, lt, false); assert(r == 0);
assert(b_r_l.state == LOCK_REQUEST_COMPLETE && b_r_l.complete_r == 0); assert(b_r_l.state == LOCK_REQUEST_COMPLETE && b_r_l.complete_r == 0);
txnid_set_init(&conflicts); txnid_set_init(&conflicts);
...@@ -79,7 +78,7 @@ int main(int argc, const char *argv[]) { ...@@ -79,7 +78,7 @@ int main(int argc, const char *argv[]) {
toku_lock_request_destroy(&b_r_l); toku_lock_request_destroy(&b_r_l);
const TXNID txn_c = 3; const TXNID txn_c = 3;
toku_lock_request c_w_l; toku_lock_request_init(&c_w_l, fake_db, txn_c, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request c_w_l; toku_lock_request_init(&c_w_l, txn_c, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&c_w_l, lt, false); assert(r != 0); r = toku_lock_request_start(&c_w_l, lt, false); assert(r != 0);
assert(c_w_l.state == LOCK_REQUEST_PENDING); assert(c_w_l.state == LOCK_REQUEST_PENDING);
...@@ -107,7 +106,7 @@ int main(int argc, const char *argv[]) { ...@@ -107,7 +106,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_c); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_c); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -46,10 +46,8 @@ int main(int argc, const char *argv[]) { ...@@ -46,10 +46,8 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
DBT key_l; dbt_init(&key_l, "L", 1); DBT key_l; dbt_init(&key_l, "L", 1);
...@@ -57,7 +55,7 @@ int main(int argc, const char *argv[]) { ...@@ -57,7 +55,7 @@ int main(int argc, const char *argv[]) {
txnid_set conflicts; txnid_set conflicts;
const TXNID txn_a = 1; const TXNID txn_a = 1;
toku_lock_request a_r_l; toku_lock_request_init(&a_r_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request a_r_l; toku_lock_request_init(&a_r_l, txn_a, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&a_r_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_r_l, lt, false); assert(r == 0);
assert(a_r_l.state == LOCK_REQUEST_COMPLETE && a_r_l.complete_r == 0); assert(a_r_l.state == LOCK_REQUEST_COMPLETE && a_r_l.complete_r == 0);
txnid_set_init(&conflicts); txnid_set_init(&conflicts);
...@@ -68,7 +66,7 @@ int main(int argc, const char *argv[]) { ...@@ -68,7 +66,7 @@ int main(int argc, const char *argv[]) {
toku_lock_request_destroy(&a_r_l); toku_lock_request_destroy(&a_r_l);
const TXNID txn_b = 2; const TXNID txn_b = 2;
toku_lock_request b_r_l; toku_lock_request_init(&b_r_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request b_r_l; toku_lock_request_init(&b_r_l, txn_b, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&b_r_l, lt, false); assert(r == 0); r = toku_lock_request_start(&b_r_l, lt, false); assert(r == 0);
assert(b_r_l.state == LOCK_REQUEST_COMPLETE && b_r_l.complete_r == 0 assert(b_r_l.state == LOCK_REQUEST_COMPLETE && b_r_l.complete_r == 0
); );
...@@ -80,7 +78,7 @@ int main(int argc, const char *argv[]) { ...@@ -80,7 +78,7 @@ int main(int argc, const char *argv[]) {
toku_lock_request_destroy(&b_r_l); toku_lock_request_destroy(&b_r_l);
const TXNID txn_c = 3; const TXNID txn_c = 3;
toku_lock_request c_w_l; toku_lock_request_init(&c_w_l, fake_db, txn_c, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request c_w_l; toku_lock_request_init(&c_w_l, txn_c, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&c_w_l, lt, false); assert(r != 0); r = toku_lock_request_start(&c_w_l, lt, false); assert(r != 0);
assert(c_w_l.state == LOCK_REQUEST_PENDING); assert(c_w_l.state == LOCK_REQUEST_PENDING);
...@@ -108,7 +106,7 @@ int main(int argc, const char *argv[]) { ...@@ -108,7 +106,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_c); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_c); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -36,15 +36,13 @@ int main(int argc, const char *argv[]) { ...@@ -36,15 +36,13 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
DBT key_l; dbt_init(&key_l, "L", 1); DBT key_l; dbt_init(&key_l, "L", 1);
toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0);
assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0); assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0);
...@@ -59,7 +57,7 @@ int main(int argc, const char *argv[]) { ...@@ -59,7 +57,7 @@ int main(int argc, const char *argv[]) {
toku_lock_request_destroy(&a_w_l); toku_lock_request_destroy(&a_w_l);
const TXNID txn_b = 2; const TXNID txn_b = 2;
toku_lock_request b_r_l; toku_lock_request_init(&b_r_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request b_r_l; toku_lock_request_init(&b_r_l, txn_b, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&b_r_l, lt, false); assert(r != 0); r = toku_lock_request_start(&b_r_l, lt, false); assert(r != 0);
assert(b_r_l.state == LOCK_REQUEST_PENDING); assert(b_r_l.state == LOCK_REQUEST_PENDING);
...@@ -76,7 +74,7 @@ int main(int argc, const char *argv[]) { ...@@ -76,7 +74,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_b); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_b); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -36,16 +36,14 @@ int main(int argc, const char *argv[]) { ...@@ -36,16 +36,14 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
DBT key_l; dbt_init(&key_l, "L", 1); DBT key_l; dbt_init(&key_l, "L", 1);
const TXNID txn_a = 1; const TXNID txn_a = 1;
toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, fake_db, txn_a, toku_lt_neg_infinity, toku_lt_infinity, LOCK_REQUEST_WRITE); toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, txn_a, toku_lt_neg_infinity, toku_lt_infinity, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0);
assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0); assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0);
...@@ -60,7 +58,7 @@ int main(int argc, const char *argv[]) { ...@@ -60,7 +58,7 @@ int main(int argc, const char *argv[]) {
toku_lock_request_destroy(&a_w_l); toku_lock_request_destroy(&a_w_l);
const TXNID txn_b = 2; const TXNID txn_b = 2;
toku_lock_request b_r_l; toku_lock_request_init(&b_r_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request b_r_l; toku_lock_request_init(&b_r_l, txn_b, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&b_r_l, lt, false); assert(r != 0); r = toku_lock_request_start(&b_r_l, lt, false); assert(r != 0);
assert(b_r_l.state == LOCK_REQUEST_PENDING); assert(b_r_l.state == LOCK_REQUEST_PENDING);
...@@ -76,7 +74,7 @@ int main(int argc, const char *argv[]) { ...@@ -76,7 +74,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_b); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_b); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -36,16 +36,14 @@ int main(int argc, const char *argv[]) { ...@@ -36,16 +36,14 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
DBT key_l; dbt_init(&key_l, "L", 1); DBT key_l; dbt_init(&key_l, "L", 1);
const TXNID txn_a = 1; const TXNID txn_a = 1;
toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0);
assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0); assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0);
...@@ -60,7 +58,7 @@ int main(int argc, const char *argv[]) { ...@@ -60,7 +58,7 @@ int main(int argc, const char *argv[]) {
toku_lock_request_destroy(&a_w_l); toku_lock_request_destroy(&a_w_l);
const TXNID txn_b = 2; const TXNID txn_b = 2;
toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, txn_b, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&b_w_l, lt, false); assert(r != 0); r = toku_lock_request_start(&b_w_l, lt, false); assert(r != 0);
assert(b_w_l.state == LOCK_REQUEST_PENDING); assert(b_w_l.state == LOCK_REQUEST_PENDING);
...@@ -76,7 +74,7 @@ int main(int argc, const char *argv[]) { ...@@ -76,7 +74,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
static int read_lock(toku_lock_tree *lt, TXNID txnid, char *k) { static int read_lock(toku_lock_tree *lt, TXNID txnid, char *k) {
DBT key; dbt_init(&key, k, strlen(k)); DBT key; dbt_init(&key, k, strlen(k));
toku_lock_request lr; toku_lock_request lr;
toku_lock_request_init(&lr, (DB*)1, txnid, &key, &key, LOCK_REQUEST_READ); toku_lock_request_init(&lr, txnid, &key, &key, LOCK_REQUEST_READ);
int r = toku_lt_acquire_lock_request_with_default_timeout(lt, &lr); int r = toku_lt_acquire_lock_request_with_default_timeout(lt, &lr);
toku_lock_request_destroy(&lr); toku_lock_request_destroy(&lr);
return r; return r;
...@@ -16,7 +16,7 @@ static int read_lock(toku_lock_tree *lt, TXNID txnid, char *k) { ...@@ -16,7 +16,7 @@ static int read_lock(toku_lock_tree *lt, TXNID txnid, char *k) {
static int write_lock(toku_lock_tree *lt, TXNID txnid, char *k) { static int write_lock(toku_lock_tree *lt, TXNID txnid, char *k) {
DBT key; dbt_init(&key, k, strlen(k)); DBT key; dbt_init(&key, k, strlen(k));
toku_lock_request lr; toku_lock_request lr;
toku_lock_request_init(&lr, (DB*)1, txnid, &key, &key, LOCK_REQUEST_WRITE); toku_lock_request_init(&lr, txnid, &key, &key, LOCK_REQUEST_WRITE);
int r = toku_lt_acquire_lock_request_with_default_timeout(lt, &lr); int r = toku_lt_acquire_lock_request_with_default_timeout(lt, &lr);
toku_lock_request_destroy(&lr); toku_lock_request_destroy(&lr);
return r; return r;
...@@ -53,10 +53,8 @@ int main(int argc, const char *argv[]) { ...@@ -53,10 +53,8 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
...@@ -73,7 +71,7 @@ int main(int argc, const char *argv[]) { ...@@ -73,7 +71,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -104,10 +104,8 @@ int main(int argc, const char *argv[]) { ...@@ -104,10 +104,8 @@ int main(int argc, const char *argv[]) {
assert(s.max_lock_memory == max_lock_memory); assert(s.max_lock_memory == max_lock_memory);
assert(s.curr_lock_memory == 0); assert(s.curr_lock_memory == 0);
DB *db_a = (DB *) 2;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, db_a, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
TXNID txn_a = 1; TXNID txn_a = 1;
...@@ -116,7 +114,7 @@ int main(int argc, const char *argv[]) { ...@@ -116,7 +114,7 @@ int main(int argc, const char *argv[]) {
for (uint64_t i = 1; i <= nrows; i++) { for (uint64_t i = 1; i <= nrows; i++) {
uint64_t k = htonl64(i); uint64_t k = htonl64(i);
DBT key = { .data = &k, .size = sizeof k }; DBT key = { .data = &k, .size = sizeof k };
r = toku_lt_acquire_write_lock(lt, db_a, txn_a, &key); r = toku_lt_acquire_write_lock(lt, txn_a, &key);
if (r != 0) { if (r != 0) {
assert(r == TOKUDB_OUT_OF_LOCKS); assert(r == TOKUDB_OUT_OF_LOCKS);
break; break;
...@@ -143,7 +141,7 @@ int main(int argc, const char *argv[]) { ...@@ -143,7 +141,7 @@ int main(int argc, const char *argv[]) {
assert(s.curr_locks == 0); assert(s.curr_locks == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, db_a); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -106,10 +106,8 @@ int main(int argc, const char *argv[]) { ...@@ -106,10 +106,8 @@ int main(int argc, const char *argv[]) {
assert(s.max_lock_memory == max_lock_memory); assert(s.max_lock_memory == max_lock_memory);
assert(s.curr_lock_memory == 0); assert(s.curr_lock_memory == 0);
DB *db_a = (DB *) 2;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, db_a, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
TXNID txn_a = 1; TXNID txn_a = 1;
...@@ -120,7 +118,7 @@ int main(int argc, const char *argv[]) { ...@@ -120,7 +118,7 @@ int main(int argc, const char *argv[]) {
uint64_t k_right = htonl64(2*i+1); uint64_t k_right = htonl64(2*i+1);
DBT key_left = { .data = &k_left, .size = sizeof k_left }; DBT key_left = { .data = &k_left, .size = sizeof k_left };
DBT key_right = { .data = &k_right, .size = sizeof k_right }; DBT key_right = { .data = &k_right, .size = sizeof k_right };
r = toku_lt_acquire_range_write_lock(lt, db_a, txn_a, &key_left, &key_right); r = toku_lt_acquire_range_write_lock(lt, txn_a, &key_left, &key_right);
if (r != 0) { if (r != 0) {
assert(r == TOKUDB_OUT_OF_LOCKS); assert(r == TOKUDB_OUT_OF_LOCKS);
break; break;
...@@ -147,7 +145,7 @@ int main(int argc, const char *argv[]) { ...@@ -147,7 +145,7 @@ int main(int argc, const char *argv[]) {
assert(s.curr_locks == 0); assert(s.curr_locks == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, db_a); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -34,14 +34,12 @@ static void init_query(void) { ...@@ -34,14 +34,12 @@ static void init_query(void) {
query.right = &qright; query.right = &qright;
} }
static DB *fake_db = (DB *) 1;
static void setup_tree(void) { static void setup_tree(void) {
assert(!lt && !ltm); assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
CKERR(r); CKERR(r);
assert(ltm); assert(ltm);
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
init_query(); init_query();
...@@ -49,7 +47,7 @@ static void setup_tree(void) { ...@@ -49,7 +47,7 @@ static void setup_tree(void) {
static void close_tree(void) { static void close_tree(void) {
assert(lt && ltm); assert(lt && ltm);
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); CKERR(r); r = toku_ltm_close(ltm); CKERR(r);
lt = NULL; lt = NULL;
ltm = NULL; ltm = NULL;
...@@ -69,7 +67,7 @@ static DBT* set_to_infty(DBT *dbt, int value) { ...@@ -69,7 +67,7 @@ static DBT* set_to_infty(DBT *dbt, int value) {
} }
static void lt_verify(void) { static void lt_verify(void) {
toku_lt_verify(lt, NULL); toku_lt_verify(lt);
} }
static void lt_insert_read_range(int r_expect, char txn, int key_l, int key_r) { static void lt_insert_read_range(int r_expect, char txn, int key_l, int key_r) {
...@@ -83,7 +81,7 @@ static void lt_insert_read_range(int r_expect, char txn, int key_l, int key_r) { ...@@ -83,7 +81,7 @@ static void lt_insert_read_range(int r_expect, char txn, int key_l, int key_r) {
TXNID local_txn = (TXNID) (size_t) txn; TXNID local_txn = (TXNID) (size_t) txn;
r = toku_lt_acquire_range_read_lock(lt, db, local_txn, key_left, key_right); r = toku_lt_acquire_range_read_lock(lt, local_txn, key_left, key_right);
CKERR2(r, r_expect); CKERR2(r, r_expect);
lt_verify(); lt_verify();
} }
...@@ -99,7 +97,7 @@ static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r) ...@@ -99,7 +97,7 @@ static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r)
TXNID local_txn = (TXNID) (size_t) txn; TXNID local_txn = (TXNID) (size_t) txn;
r = toku_lt_acquire_range_write_lock(lt, db, local_txn, key_left, key_right); r = toku_lt_acquire_range_write_lock(lt, local_txn, key_left, key_right);
CKERR2(r, r_expect); CKERR2(r, r_expect);
lt_verify(); lt_verify();
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
static int read_lock(toku_lock_tree *lt, TXNID txnid, char *k, struct timeval *wait_time) { static int read_lock(toku_lock_tree *lt, TXNID txnid, char *k, struct timeval *wait_time) {
DBT key; dbt_init(&key, k, strlen(k)); DBT key; dbt_init(&key, k, strlen(k));
toku_lock_request lr; toku_lock_request lr;
toku_lock_request_init(&lr, (DB*)1, txnid, &key, &key, LOCK_REQUEST_READ); toku_lock_request_init(&lr, txnid, &key, &key, LOCK_REQUEST_READ);
int r = toku_lt_acquire_lock_request_with_timeout(lt, &lr, wait_time); int r = toku_lt_acquire_lock_request_with_timeout(lt, &lr, wait_time);
toku_lock_request_destroy(&lr); toku_lock_request_destroy(&lr);
return r; return r;
...@@ -16,7 +16,7 @@ static int read_lock(toku_lock_tree *lt, TXNID txnid, char *k, struct timeval *w ...@@ -16,7 +16,7 @@ static int read_lock(toku_lock_tree *lt, TXNID txnid, char *k, struct timeval *w
static int write_lock(toku_lock_tree *lt, TXNID txnid, char *k, struct timeval *wait_time) { static int write_lock(toku_lock_tree *lt, TXNID txnid, char *k, struct timeval *wait_time) {
DBT key; dbt_init(&key, k, strlen(k)); DBT key; dbt_init(&key, k, strlen(k));
toku_lock_request lr; toku_lock_request lr;
toku_lock_request_init(&lr, (DB*)1, txnid, &key, &key, LOCK_REQUEST_WRITE); toku_lock_request_init(&lr, txnid, &key, &key, LOCK_REQUEST_WRITE);
int r = toku_lt_acquire_lock_request_with_timeout(lt, &lr, wait_time); int r = toku_lt_acquire_lock_request_with_timeout(lt, &lr, wait_time);
toku_lock_request_destroy(&lr); toku_lock_request_destroy(&lr);
return r; return r;
...@@ -53,10 +53,8 @@ int main(int argc, const char *argv[]) { ...@@ -53,10 +53,8 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
...@@ -73,7 +71,7 @@ int main(int argc, const char *argv[]) { ...@@ -73,7 +71,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
#include <string.h>
#include <stdbool.h>
#include "test.h"
// verify that updating a lock tree's descriptor works properly.
static toku_ltm *ltm;
static toku_lock_tree *tree;
enum { MAX_LOCKS = 1000, MAX_LOCK_MEMORY = MAX_LOCKS * 64 };
#define verbose_printf(...) \
do { \
if (verbose) { \
printf(__VA_ARGS__);\
} \
} while (0)
#define MAKE_DESCRIPTOR(buf) \
{ .dbt = { .data = buf, .size = sizeof(buf) } }
static DESCRIPTOR_S descriptors[] = {
MAKE_DESCRIPTOR("cats"),
MAKE_DESCRIPTOR("elephants"),
MAKE_DESCRIPTOR("snakes"),
MAKE_DESCRIPTOR("catsarecute"),
MAKE_DESCRIPTOR("elephantsarelarge"),
MAKE_DESCRIPTOR("snakesonaplane")
};
static const int num_descriptors = sizeof(descriptors) / sizeof(DESCRIPTOR_S);
static DESCRIPTOR current_descriptor;
static bool same_descriptor(DESCRIPTOR a, DESCRIPTOR b)
{
verbose_printf("a %p b %p\n", a, b);
if (a == NULL && b == NULL) {
return true;
}
if (a != NULL && b != NULL) {
verbose_printf("a.size %d b.size %d\n", a->dbt.size, b->dbt.size);
verbose_printf("a.data %s b.data %s\n", (char*)a->dbt.data, (char*)b->dbt.data);
return a->dbt.size == b->dbt.size &&
memcmp(a->dbt.data, b->dbt.data, a->dbt.size) == 0;
}
return false;
}
static int cmp_function(DB * db, const DBT * a, const DBT * b)
{
// clearly the db should not be null.
assert(db);
// the descriptor in the DB should be the descriptor we expect
assert(same_descriptor(current_descriptor, db->cmp_descriptor));
// doesn't really matter what we return here
(void) a; (void) b;
return 0;
}
int main(int argc, const char *argv[])
{
int r;
parse_args(argc, argv);
// get a lock manager and a lock tree.
r = toku_ltm_create(&ltm, MAX_LOCKS, MAX_LOCK_MEMORY, dbpanic);
CKERR(r);
current_descriptor = NULL;
toku_ltm_get_lt(ltm, &tree, (DICTIONARY_ID) {1}, current_descriptor, cmp_function);
CKERR(r);
for (int d = 0; d < num_descriptors; d++) {
current_descriptor = &descriptors[d];
toku_lt_update_descriptor(tree, current_descriptor);
// check that we can call this point comparison a couple
// of times and pass the comparison function's assertion
for (int i = 0; i < 10; i++) {
const toku_point x = { .lt = tree, .key_payload = "" };
const toku_point y = { .lt = tree, .key_payload = "" };
toku_lt_point_cmp(&x, &y);
}
}
// cleanup
toku_ltm_close(ltm);
return 0;
}
...@@ -11,13 +11,13 @@ ...@@ -11,13 +11,13 @@
static int read_lock(toku_lock_tree *lt, TXNID txnid, char *k) { static int read_lock(toku_lock_tree *lt, TXNID txnid, char *k) {
DBT key; dbt_init(&key, k, strlen(k)); DBT key; dbt_init(&key, k, strlen(k));
int r = toku_lt_acquire_read_lock(lt, (DB*)1, txnid, &key); int r = toku_lt_acquire_read_lock(lt, txnid, &key);
return r; return r;
} }
static int write_lock(toku_lock_tree *lt, TXNID txnid, char *k) { static int write_lock(toku_lock_tree *lt, TXNID txnid, char *k) {
DBT key; dbt_init(&key, k, strlen(k)); DBT key; dbt_init(&key, k, strlen(k));
int r = toku_lt_acquire_write_lock(lt, (DB*)1, txnid, &key); int r = toku_lt_acquire_write_lock(lt, txnid, &key);
return r; return r;
} }
...@@ -52,10 +52,8 @@ int main(int argc, const char *argv[]) { ...@@ -52,10 +52,8 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
...@@ -74,7 +72,7 @@ int main(int argc, const char *argv[]) { ...@@ -74,7 +72,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_c); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_c); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -41,26 +41,24 @@ int main(int argc, const char *argv[]) { ...@@ -41,26 +41,24 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
DBT key_l; dbt_init(&key_l, "L", 1); DBT key_l; dbt_init(&key_l, "L", 1);
toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0);
assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0); assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0);
toku_lock_request_destroy(&a_w_l); toku_lock_request_destroy(&a_w_l);
const TXNID txn_b = 2; const TXNID txn_b = 2;
toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, txn_b, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&b_w_l, lt, false); assert(r != 0); r = toku_lock_request_start(&b_w_l, lt, false); assert(r != 0);
assert(b_w_l.state == LOCK_REQUEST_PENDING); assert(b_w_l.state == LOCK_REQUEST_PENDING);
const TXNID txn_c = 3; const TXNID txn_c = 3;
toku_lock_request c_w_l; toku_lock_request_init(&c_w_l, fake_db, txn_c, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request c_w_l; toku_lock_request_init(&c_w_l, txn_c, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&c_w_l, lt, false); assert(r != 0); r = toku_lock_request_start(&c_w_l, lt, false); assert(r != 0);
assert(c_w_l.state == LOCK_REQUEST_PENDING); assert(c_w_l.state == LOCK_REQUEST_PENDING);
...@@ -73,7 +71,7 @@ int main(int argc, const char *argv[]) { ...@@ -73,7 +71,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_c); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_c); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -40,26 +40,24 @@ int main(int argc, const char *argv[]) { ...@@ -40,26 +40,24 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
DBT key_l; dbt_init(&key_l, "L", 1); DBT key_l; dbt_init(&key_l, "L", 1);
toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0);
assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0); assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0);
toku_lock_request_destroy(&a_w_l); toku_lock_request_destroy(&a_w_l);
const TXNID txn_b = 2; const TXNID txn_b = 2;
toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, txn_b, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&b_w_l, lt, false); assert(r != 0); r = toku_lock_request_start(&b_w_l, lt, false); assert(r != 0);
assert(b_w_l.state == LOCK_REQUEST_PENDING); assert(b_w_l.state == LOCK_REQUEST_PENDING);
const TXNID txn_c = 3; const TXNID txn_c = 3;
toku_lock_request c_w_l; toku_lock_request_init(&c_w_l, fake_db, txn_c, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request c_w_l; toku_lock_request_init(&c_w_l, txn_c, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&c_w_l, lt, false); assert(r != 0); r = toku_lock_request_start(&c_w_l, lt, false); assert(r != 0);
assert(c_w_l.state == LOCK_REQUEST_PENDING); assert(c_w_l.state == LOCK_REQUEST_PENDING);
...@@ -72,7 +70,7 @@ int main(int argc, const char *argv[]) { ...@@ -72,7 +70,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_c); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_c); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -39,31 +39,29 @@ int main(int argc, const char *argv[]) { ...@@ -39,31 +39,29 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
DBT key_l; dbt_init(&key_l, "L", 1); DBT key_l; dbt_init(&key_l, "L", 1);
toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0);
assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0); assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0);
toku_lock_request_destroy(&a_w_l); toku_lock_request_destroy(&a_w_l);
const TXNID txn_b = 2; const TXNID txn_b = 2;
DBT key_m; dbt_init(&key_m, "M", 1); DBT key_m; dbt_init(&key_m, "M", 1);
toku_lock_request b_w_m; toku_lock_request_init(&b_w_m, fake_db, txn_b, &key_m, &key_m, LOCK_REQUEST_WRITE); toku_lock_request b_w_m; toku_lock_request_init(&b_w_m, txn_b, &key_m, &key_m, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&b_w_m, lt, false); assert(r == 0); r = toku_lock_request_start(&b_w_m, lt, false); assert(r == 0);
assert(b_w_m.state == LOCK_REQUEST_COMPLETE && b_w_m.complete_r == 0); assert(b_w_m.state == LOCK_REQUEST_COMPLETE && b_w_m.complete_r == 0);
toku_lock_request_destroy(&b_w_m); toku_lock_request_destroy(&b_w_m);
toku_lock_request a_w_m; toku_lock_request_init(&a_w_m, fake_db, txn_a, &key_m, &key_m, LOCK_REQUEST_WRITE); toku_lock_request a_w_m; toku_lock_request_init(&a_w_m, txn_a, &key_m, &key_m, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_m, lt, false); assert(r == DB_LOCK_NOTGRANTED); r = toku_lock_request_start(&a_w_m, lt, false); assert(r == DB_LOCK_NOTGRANTED);
assert(a_w_m.state == LOCK_REQUEST_PENDING); assert(a_w_m.state == LOCK_REQUEST_PENDING);
toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, txn_b, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&b_w_l, lt, false); assert(r == DB_LOCK_DEADLOCK); r = toku_lock_request_start(&b_w_l, lt, false); assert(r == DB_LOCK_DEADLOCK);
assert(b_w_l.state == LOCK_REQUEST_COMPLETE && b_w_l.complete_r == DB_LOCK_DEADLOCK); assert(b_w_l.state == LOCK_REQUEST_COMPLETE && b_w_l.complete_r == DB_LOCK_DEADLOCK);
...@@ -77,7 +75,7 @@ int main(int argc, const char *argv[]) { ...@@ -77,7 +75,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -37,16 +37,14 @@ int main(int argc, const char *argv[]) { ...@@ -37,16 +37,14 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
// add a lock for a transaction // add a lock for a transaction
const TXNID txn_a = 1; const TXNID txn_a = 1;
DBT key_l; dbt_init(&key_l, "L", 1); DBT key_l; dbt_init(&key_l, "L", 1);
toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0);
assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0); assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0);
toku_lock_request_destroy(&a_w_l); toku_lock_request_destroy(&a_w_l);
...@@ -55,7 +53,7 @@ int main(int argc, const char *argv[]) { ...@@ -55,7 +53,7 @@ int main(int argc, const char *argv[]) {
toku_lt_add_ref(lt); toku_lt_add_ref(lt);
// start closing the lock tree // start closing the lock tree
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
// release all locks for the transaction // release all locks for the transaction
r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0);
......
...@@ -39,30 +39,28 @@ int main(int argc, const char *argv[]) { ...@@ -39,30 +39,28 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
DBT key_l; dbt_init(&key_l, "L", 1); DBT key_l; dbt_init(&key_l, "L", 1);
toku_lock_request a_r_l; toku_lock_request_init(&a_r_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request a_r_l; toku_lock_request_init(&a_r_l, txn_a, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&a_r_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_r_l, lt, false); assert(r == 0);
assert(a_r_l.state == LOCK_REQUEST_COMPLETE && a_r_l.complete_r == 0); assert(a_r_l.state == LOCK_REQUEST_COMPLETE && a_r_l.complete_r == 0);
toku_lock_request_destroy(&a_r_l); toku_lock_request_destroy(&a_r_l);
const TXNID txn_b = 2; const TXNID txn_b = 2;
toku_lock_request b_r_l; toku_lock_request_init(&b_r_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request b_r_l; toku_lock_request_init(&b_r_l, txn_b, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&b_r_l, lt, false); assert(r == 0); r = toku_lock_request_start(&b_r_l, lt, false); assert(r == 0);
assert(b_r_l.state == LOCK_REQUEST_COMPLETE && b_r_l.complete_r == 0); assert(b_r_l.state == LOCK_REQUEST_COMPLETE && b_r_l.complete_r == 0);
toku_lock_request_destroy(&b_r_l); toku_lock_request_destroy(&b_r_l);
toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_l, lt, false); assert(r == DB_LOCK_NOTGRANTED); r = toku_lock_request_start(&a_w_l, lt, false); assert(r == DB_LOCK_NOTGRANTED);
assert(a_w_l.state == LOCK_REQUEST_PENDING); assert(a_w_l.state == LOCK_REQUEST_PENDING);
toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, txn_b, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&b_w_l, lt, false); assert(r == DB_LOCK_DEADLOCK); r = toku_lock_request_start(&b_w_l, lt, false); assert(r == DB_LOCK_DEADLOCK);
assert(b_w_l.state == LOCK_REQUEST_COMPLETE && b_w_l.complete_r == DB_LOCK_DEADLOCK); assert(b_w_l.state == LOCK_REQUEST_COMPLETE && b_w_l.complete_r == DB_LOCK_DEADLOCK);
...@@ -75,7 +73,7 @@ int main(int argc, const char *argv[]) { ...@@ -75,7 +73,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -39,30 +39,28 @@ int main(int argc, const char *argv[]) { ...@@ -39,30 +39,28 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
DBT key_l; dbt_init(&key_l, "L", 1); DBT key_l; dbt_init(&key_l, "L", 1);
toku_lock_request a_r_l; toku_lock_request_init(&a_r_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request a_r_l; toku_lock_request_init(&a_r_l, txn_a, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&a_r_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_r_l, lt, false); assert(r == 0);
assert(a_r_l.state == LOCK_REQUEST_COMPLETE && a_r_l.complete_r == 0); assert(a_r_l.state == LOCK_REQUEST_COMPLETE && a_r_l.complete_r == 0);
toku_lock_request_destroy(&a_r_l); toku_lock_request_destroy(&a_r_l);
const TXNID txn_b = 2; const TXNID txn_b = 2;
toku_lock_request b_r_l; toku_lock_request_init(&b_r_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request b_r_l; toku_lock_request_init(&b_r_l, txn_b, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&b_r_l, lt, true); assert(r == 0); r = toku_lock_request_start(&b_r_l, lt, true); assert(r == 0);
assert(b_r_l.state == LOCK_REQUEST_COMPLETE && b_r_l.complete_r == 0); assert(b_r_l.state == LOCK_REQUEST_COMPLETE && b_r_l.complete_r == 0);
toku_lock_request_destroy(&b_r_l); toku_lock_request_destroy(&b_r_l);
toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_l, lt, true); assert(r == DB_LOCK_NOTGRANTED); r = toku_lock_request_start(&a_w_l, lt, true); assert(r == DB_LOCK_NOTGRANTED);
assert(a_w_l.state == LOCK_REQUEST_PENDING); assert(a_w_l.state == LOCK_REQUEST_PENDING);
toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, txn_b, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&b_w_l, lt, true); assert(r == DB_LOCK_DEADLOCK); r = toku_lock_request_start(&b_w_l, lt, true); assert(r == DB_LOCK_DEADLOCK);
assert(b_w_l.state == LOCK_REQUEST_COMPLETE && b_w_l.complete_r == DB_LOCK_DEADLOCK); assert(b_w_l.state == LOCK_REQUEST_COMPLETE && b_w_l.complete_r == DB_LOCK_DEADLOCK);
...@@ -75,7 +73,7 @@ int main(int argc, const char *argv[]) { ...@@ -75,7 +73,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
static int write_lock(toku_lock_tree *lt, TXNID txnid, char *k) { static int write_lock(toku_lock_tree *lt, TXNID txnid, char *k) {
DBT key; dbt_init(&key, k, strlen(k)); DBT key; dbt_init(&key, k, strlen(k));
toku_lock_request lr; toku_lock_request lr;
toku_lock_request_init(&lr, (DB*)1, txnid, &key, &key, LOCK_REQUEST_WRITE); toku_lock_request_init(&lr, txnid, &key, &key, LOCK_REQUEST_WRITE);
int r; int r;
if (0) { if (0) {
r = toku_lt_acquire_lock_request_with_timeout(lt, &lr, NULL); r = toku_lt_acquire_lock_request_with_timeout(lt, &lr, NULL);
...@@ -76,10 +76,8 @@ int main(int argc, const char *argv[]) { ...@@ -76,10 +76,8 @@ int main(int argc, const char *argv[]) {
assert(r == 0 && ltm); assert(r == 0 && ltm);
toku_ltm_set_lock_wait_time(ltm, UINT64_MAX); toku_ltm_set_lock_wait_time(ltm, UINT64_MAX);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
...@@ -104,7 +102,7 @@ int main(int argc, const char *argv[]) { ...@@ -104,7 +102,7 @@ int main(int argc, const char *argv[]) {
} }
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
static int write_lock(toku_lock_tree *lt, TXNID txnid, char *k) { static int write_lock(toku_lock_tree *lt, TXNID txnid, char *k) {
DBT key; dbt_init(&key, k, strlen(k)); DBT key; dbt_init(&key, k, strlen(k));
int r = toku_lt_acquire_write_lock(lt, (DB*)1, txnid, &key); int r = toku_lt_acquire_write_lock(lt, txnid, &key);
return r; return r;
} }
...@@ -43,10 +43,8 @@ int main(int argc, const char *argv[]) { ...@@ -43,10 +43,8 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
...@@ -59,7 +57,7 @@ int main(int argc, const char *argv[]) { ...@@ -59,7 +57,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_b); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_b); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -34,14 +34,12 @@ static void init_query(void) { ...@@ -34,14 +34,12 @@ static void init_query(void) {
query.right = &qright; query.right = &qright;
} }
static DB *fake_db = (DB *) 1;
static void setup_tree(void) { static void setup_tree(void) {
assert(!lt && !ltm); assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
CKERR(r); CKERR(r);
assert(ltm); assert(ltm);
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
init_query(); init_query();
...@@ -49,14 +47,14 @@ static void setup_tree(void) { ...@@ -49,14 +47,14 @@ static void setup_tree(void) {
static void close_tree(void) { static void close_tree(void) {
assert(lt && ltm); assert(lt && ltm);
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); CKERR(r); r = toku_ltm_close(ltm); CKERR(r);
lt = NULL; lt = NULL;
ltm = NULL; ltm = NULL;
} }
static void lt_verify(void) { static void lt_verify(void) {
toku_lt_verify(lt, NULL); toku_lt_verify(lt);
} }
typedef enum { null = -1, infinite = -2, neg_infinite = -3 } lt_infty; typedef enum { null = -1, infinite = -2, neg_infinite = -3 } lt_infty;
...@@ -89,11 +87,11 @@ static void lt_insert(int r_expect, char txn, int key_l, ...@@ -89,11 +87,11 @@ static void lt_insert(int r_expect, char txn, int key_l,
TXNID local_txn = (TXNID) (size_t) txn; TXNID local_txn = (TXNID) (size_t) txn;
if (read_flag) if (read_flag)
r = toku_lt_acquire_range_read_lock(lt, db, local_txn, r = toku_lt_acquire_range_read_lock(lt, local_txn,
key_left, key_left,
key_right); key_right);
else else
r = toku_lt_acquire_write_lock(lt, db, local_txn, key_left); r = toku_lt_acquire_write_lock(lt, local_txn, key_left);
CKERR2(r, r_expect); CKERR2(r, r_expect);
lt_verify(); lt_verify();
} }
...@@ -119,7 +117,7 @@ static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r) ...@@ -119,7 +117,7 @@ static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r)
TXNID local_txn = (TXNID) (size_t) txn; TXNID local_txn = (TXNID) (size_t) txn;
r = toku_lt_acquire_range_write_lock(lt, db, local_txn, key_left, key_right); r = toku_lt_acquire_range_write_lock(lt, local_txn, key_left, key_right);
CKERR2(r, r_expect); CKERR2(r, r_expect);
lt_verify(); lt_verify();
} }
......
...@@ -34,14 +34,12 @@ static void init_query(void) { ...@@ -34,14 +34,12 @@ static void init_query(void) {
query.right = &qright; query.right = &qright;
} }
static DB *fake_db = (DB *) 1;
static void setup_tree(void) { static void setup_tree(void) {
assert(!lt && !ltm); assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
CKERR(r); CKERR(r);
assert(ltm); assert(ltm);
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
init_query(); init_query();
...@@ -49,7 +47,7 @@ static void setup_tree(void) { ...@@ -49,7 +47,7 @@ static void setup_tree(void) {
static void close_tree(void) { static void close_tree(void) {
assert(lt && ltm); assert(lt && ltm);
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); CKERR(r); r = toku_ltm_close(ltm); CKERR(r);
lt = NULL; lt = NULL;
ltm = NULL; ltm = NULL;
...@@ -79,7 +77,7 @@ static void lt_insert_read_range(int r_expect, char txn, int key_l, int key_r) { ...@@ -79,7 +77,7 @@ static void lt_insert_read_range(int r_expect, char txn, int key_l, int key_r) {
TXNID local_txn = (TXNID) (size_t) txn; TXNID local_txn = (TXNID) (size_t) txn;
r = toku_lt_acquire_range_read_lock(lt, db, local_txn, r = toku_lt_acquire_range_read_lock(lt, local_txn,
key_left, key_left,
key_right); key_right);
CKERR2(r, r_expect); CKERR2(r, r_expect);
...@@ -96,7 +94,7 @@ static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r) ...@@ -96,7 +94,7 @@ static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r)
TXNID local_txn = (TXNID) (size_t) txn; TXNID local_txn = (TXNID) (size_t) txn;
r = toku_lt_acquire_range_write_lock(lt, db, local_txn, key_left, key_right); r = toku_lt_acquire_range_write_lock(lt, local_txn, key_left, key_right);
CKERR2(r, r_expect); CKERR2(r, r_expect);
} }
......
...@@ -34,14 +34,12 @@ static void init_query(void) { ...@@ -34,14 +34,12 @@ static void init_query(void) {
query.right = &qright; query.right = &qright;
} }
static DB *fake_db = (DB *) 1;
static void setup_tree(void) { static void setup_tree(void) {
assert(!lt && !ltm); assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
CKERR(r); CKERR(r);
assert(ltm); assert(ltm);
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
init_query(); init_query();
...@@ -49,7 +47,7 @@ static void setup_tree(void) { ...@@ -49,7 +47,7 @@ static void setup_tree(void) {
static void close_tree(void) { static void close_tree(void) {
assert(lt && ltm); assert(lt && ltm);
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); CKERR(r); r = toku_ltm_close(ltm); CKERR(r);
lt = NULL; lt = NULL;
ltm = NULL; ltm = NULL;
...@@ -80,7 +78,7 @@ static void lt_insert_read_range(int r_expect, char txn, int key_l, int key_r) { ...@@ -80,7 +78,7 @@ static void lt_insert_read_range(int r_expect, char txn, int key_l, int key_r) {
TXNID local_txn = (TXNID) (size_t) txn; TXNID local_txn = (TXNID) (size_t) txn;
r = toku_lt_acquire_range_read_lock(lt, db, local_txn, r = toku_lt_acquire_range_read_lock(lt, local_txn,
key_left, key_left,
key_right); key_right);
CKERR2(r, r_expect); CKERR2(r, r_expect);
...@@ -97,7 +95,7 @@ static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r) ...@@ -97,7 +95,7 @@ static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r)
TXNID local_txn = (TXNID) (size_t) txn; TXNID local_txn = (TXNID) (size_t) txn;
r = toku_lt_acquire_range_write_lock(lt, db, local_txn, key_left, key_right); r = toku_lt_acquire_range_write_lock(lt, local_txn, key_left, key_right);
CKERR2(r, r_expect); CKERR2(r, r_expect);
} }
......
...@@ -37,22 +37,20 @@ int main(int argc, const char *argv[]) { ...@@ -37,22 +37,20 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *)1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
const TXNID txn_b = 2; const TXNID txn_b = 2;
DBT key_l; dbt_init(&key_l, "L", 1); DBT key_l; dbt_init(&key_l, "L", 1);
toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0);
assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0); assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0);
toku_lock_request_destroy(&a_w_l); toku_lock_request_destroy(&a_w_l);
toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, fake_db, txn_b, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request b_w_l; toku_lock_request_init(&b_w_l, txn_b, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&b_w_l, lt, false); assert(r != 0); r = toku_lock_request_start(&b_w_l, lt, false); assert(r != 0);
assert(b_w_l.state == LOCK_REQUEST_PENDING); assert(b_w_l.state == LOCK_REQUEST_PENDING);
...@@ -62,7 +60,7 @@ int main(int argc, const char *argv[]) { ...@@ -62,7 +60,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_b); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_b); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -36,25 +36,23 @@ int main(int argc, const char *argv[]) { ...@@ -36,25 +36,23 @@ int main(int argc, const char *argv[]) {
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic); r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic);
assert(r == 0 && ltm); assert(r == 0 && ltm);
DB *fake_db = (DB *) 1;
toku_lock_tree *lt = NULL; toku_lock_tree *lt = NULL;
r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, fake_db, dbcmp); r = toku_ltm_get_lt(ltm, &lt, (DICTIONARY_ID){1}, NULL, dbcmp);
assert(r == 0 && lt); assert(r == 0 && lt);
const TXNID txn_a = 1; const TXNID txn_a = 1;
DBT key_l; dbt_init(&key_l, "L", 1); DBT key_l; dbt_init(&key_l, "L", 1);
toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request a_w_l; toku_lock_request_init(&a_w_l, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_w_l, lt, false); assert(r == 0);
assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0); assert(a_w_l.state == LOCK_REQUEST_COMPLETE && a_w_l.complete_r == 0);
toku_lock_request_destroy(&a_w_l); toku_lock_request_destroy(&a_w_l);
toku_lock_request a_r_l; toku_lock_request_init(&a_r_l, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_READ); toku_lock_request a_r_l; toku_lock_request_init(&a_r_l, txn_a, &key_l, &key_l, LOCK_REQUEST_READ);
r = toku_lock_request_start(&a_r_l, lt, false); assert(r == 0); r = toku_lock_request_start(&a_r_l, lt, false); assert(r == 0);
assert(a_r_l.state == LOCK_REQUEST_COMPLETE && a_r_l.complete_r == 0); assert(a_r_l.state == LOCK_REQUEST_COMPLETE && a_r_l.complete_r == 0);
toku_lock_request_destroy(&a_r_l); toku_lock_request_destroy(&a_r_l);
toku_lock_request a_w_l_2; toku_lock_request_init(&a_w_l_2, fake_db, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE); toku_lock_request a_w_l_2; toku_lock_request_init(&a_w_l_2, txn_a, &key_l, &key_l, LOCK_REQUEST_WRITE);
r = toku_lock_request_start(&a_w_l_2, lt, false); assert(r == 0); r = toku_lock_request_start(&a_w_l_2, lt, false); assert(r == 0);
assert(a_w_l_2.state == LOCK_REQUEST_COMPLETE && a_w_l_2.complete_r == 0); assert(a_w_l_2.state == LOCK_REQUEST_COMPLETE && a_w_l_2.complete_r == 0);
toku_lock_request_destroy(&a_w_l_2); toku_lock_request_destroy(&a_w_l_2);
...@@ -62,7 +60,7 @@ int main(int argc, const char *argv[]) { ...@@ -62,7 +60,7 @@ int main(int argc, const char *argv[]) {
r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0); r = toku_lt_unlock_txn(lt, txn_a); assert(r == 0);
// shutdown // shutdown
toku_lt_remove_db_ref(lt, fake_db); toku_lt_remove_db_ref(lt);
r = toku_ltm_close(ltm); assert(r == 0); r = toku_ltm_close(ltm); assert(r == 0);
return 0; return 0;
......
...@@ -203,6 +203,19 @@ static void run_test(void) { ...@@ -203,6 +203,19 @@ static void run_test(void) {
do_inserts_and_queries(db); do_inserts_and_queries(db);
CHK(db->close(db, 0)); CHK(db->close(db, 0));
cmp_desc_is_four = TRUE;
CHK(db_create(&db, env, 0));
CHK(db->open(db, NULL, "foo.db", NULL, DB_BTREE, DB_AUTO_COMMIT, 0666));
IN_TXN_COMMIT(env, NULL, txn_1, 0, {
CHK(db->change_descriptor(db, txn_1, &orig_desc, DB_UPDATE_CMP_DESCRIPTOR));
assert_desc_four(db);
assert_cmp_desc_valid(db);
});
assert_desc_four(db);
assert_cmp_desc_valid(db);
do_inserts_and_queries(db);
CHK(db->close(db, 0));
} }
int test_main (int argc, char * const argv[]) { int test_main (int argc, char * const argv[]) {
......
...@@ -137,7 +137,7 @@ db_close_before_brt(DB *db, u_int32_t UU(flags), bool oplsn_valid, LSN oplsn) ...@@ -137,7 +137,7 @@ db_close_before_brt(DB *db, u_int32_t UU(flags), bool oplsn_valid, LSN oplsn)
} }
else { else {
if (db->i->lt) { if (db->i->lt) {
toku_lt_remove_db_ref(db->i->lt, db); toku_lt_remove_db_ref(db->i->lt);
} }
// printf("%s:%d %d=__toku_db_close(%p)\n", __FILE__, __LINE__, r, db); // printf("%s:%d %d=__toku_db_close(%p)\n", __FILE__, __LINE__, r, db);
toku_sdbt_cleanup(&db->i->skey); toku_sdbt_cleanup(&db->i->skey);
...@@ -429,7 +429,7 @@ db_open_iname(DB * db, DB_TXN * txn, const char *iname_in_env, u_int32_t flags, ...@@ -429,7 +429,7 @@ db_open_iname(DB * db, DB_TXN * txn, const char *iname_in_env, u_int32_t flags,
db->i->opened = 1; db->i->opened = 1;
if (need_locktree) { if (need_locktree) {
db->i->dict_id = toku_brt_get_dictionary_id(db->i->brt); db->i->dict_id = toku_brt_get_dictionary_id(db->i->brt);
r = toku_ltm_get_lt(db->dbenv->i->ltm, &db->i->lt, db->i->dict_id, db, toku_brt_get_bt_compare(db->i->brt)); r = toku_ltm_get_lt(db->dbenv->i->ltm, &db->i->lt, db->i->dict_id, db->cmp_descriptor, toku_brt_get_bt_compare(db->i->brt));
if (r!=0) { goto error_cleanup; } if (r!=0) { goto error_cleanup; }
} }
//Add to transaction's list of 'must close' if necessary. //Add to transaction's list of 'must close' if necessary.
...@@ -445,7 +445,7 @@ error_cleanup: ...@@ -445,7 +445,7 @@ error_cleanup:
db->i->dict_id = DICTIONARY_ID_NONE; db->i->dict_id = DICTIONARY_ID_NONE;
db->i->opened = 0; db->i->opened = 0;
if (db->i->lt) { if (db->i->lt) {
toku_lt_remove_db_ref(db->i->lt, db); toku_lt_remove_db_ref(db->i->lt);
db->i->lt = NULL; db->i->lt = NULL;
} }
return r; return r;
...@@ -540,6 +540,14 @@ toku_db_change_descriptor(DB *db, DB_TXN* txn, const DBT* descriptor, u_int32_t ...@@ -540,6 +540,14 @@ toku_db_change_descriptor(DB *db, DB_TXN* txn, const DBT* descriptor, u_int32_t
ttxn, ttxn,
update_cmp_descriptor update_cmp_descriptor
); );
if (r != 0) { goto cleanup; }
// the lock tree uses a copy of the header's descriptor for comparisons.
// if we need to update the cmp descriptor, we need to make sure the lock
// tree can get a copy of the new descriptor.
if (update_cmp_descriptor) {
toku_lt_update_descriptor(db->i->lt, db->cmp_descriptor);
}
cleanup: cleanup:
if (old_descriptor.data) toku_free(old_descriptor.data); if (old_descriptor.data) toku_free(old_descriptor.data);
return r; return r;
......
...@@ -63,7 +63,7 @@ get_range_lock(DB *db, DB_TXN *txn, const DBT *left_key, const DBT *right_key, t ...@@ -63,7 +63,7 @@ get_range_lock(DB *db, DB_TXN *txn, const DBT *left_key, const DBT *right_key, t
if (r == 0) { if (r == 0) {
TXNID txn_anc_id = toku_txn_get_txnid(db_txn_struct_i(txn_anc)->tokutxn); TXNID txn_anc_id = toku_txn_get_txnid(db_txn_struct_i(txn_anc)->tokutxn);
toku_lock_request lock_request; toku_lock_request lock_request;
toku_lock_request_init(&lock_request, db, txn_anc_id, left_key, right_key, lock_type); toku_lock_request_init(&lock_request, txn_anc_id, left_key, right_key, lock_type);
r = toku_lt_acquire_lock_request_with_default_timeout(db->i->lt, &lock_request); r = toku_lt_acquire_lock_request_with_default_timeout(db->i->lt, &lock_request);
toku_lock_request_destroy(&lock_request); toku_lock_request_destroy(&lock_request);
} }
...@@ -78,7 +78,7 @@ start_range_lock(DB *db, DB_TXN *txn, const DBT *left_key, const DBT *right_key, ...@@ -78,7 +78,7 @@ start_range_lock(DB *db, DB_TXN *txn, const DBT *left_key, const DBT *right_key,
r = toku_txn_add_lt(txn_anc, db->i->lt); r = toku_txn_add_lt(txn_anc, db->i->lt);
if (r == 0) { if (r == 0) {
TXNID txn_anc_id = toku_txn_get_txnid(db_txn_struct_i(txn_anc)->tokutxn); TXNID txn_anc_id = toku_txn_get_txnid(db_txn_struct_i(txn_anc)->tokutxn);
toku_lock_request_set(lock_request, db, txn_anc_id, left_key, right_key, lock_type); toku_lock_request_set(lock_request, txn_anc_id, left_key, right_key, lock_type);
r = toku_lock_request_start(lock_request, db->i->lt, true); r = toku_lock_request_start(lock_request, db->i->lt, true);
} }
return r; return r;
...@@ -99,7 +99,7 @@ toku_grab_write_lock (DB *db, DBT *key, TOKUTXN tokutxn) { ...@@ -99,7 +99,7 @@ toku_grab_write_lock (DB *db, DBT *key, TOKUTXN tokutxn) {
int r = toku_txn_add_lt(txn_anc, db->i->lt); int r = toku_txn_add_lt(txn_anc, db->i->lt);
if (r == 0) { if (r == 0) {
TXNID txn_anc_id = toku_txn_get_txnid(db_txn_struct_i(txn_anc)->tokutxn); TXNID txn_anc_id = toku_txn_get_txnid(db_txn_struct_i(txn_anc)->tokutxn);
r = toku_lt_acquire_write_lock(db->i->lt, db, txn_anc_id, key); r = toku_lt_acquire_write_lock(db->i->lt, txn_anc_id, key);
} }
return r; return 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