Commit c0f791cb authored by John Esmet's avatar John Esmet Committed by Yoni Fogel

refs #5779 rebalance on the way down in treenode::insert(), add a test that...

refs #5779 rebalance on the way down in treenode::insert(), add a test that makes sure the concurrent tree can survive 128k serial key insertions.


git-svn-id: file:///svn/toku/tokudb@50986 c7de825b-a66e-492c-adef-691d508d4ae1
parent e64cd1ca
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id: concurrent_tree_lkr_insert_remove.cc 49862 2012-11-12 14:33:14Z leifwalsh $"
#ident "Copyright (c) 2007-2012 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <portability/toku_pthread.h>
#include "concurrent_tree_unit_test.h"
namespace toku {
// This is intended to be a black-box test for the concurrent_tree's
// ability to rebalance in the face of many serial insertions.
// If the code survives many inserts, it is considered successful.
void concurrent_tree_unit_test::test_lkr_insert_serial_large(void) {
comparator cmp;
cmp.create(compare_dbts, nullptr);
concurrent_tree tree;
tree.create(&cmp);
// prepare and acquire the infinte range
concurrent_tree::locked_keyrange lkr;
lkr.prepare(&tree);
lkr.acquire(keyrange::get_infinite_range());
// 128k keys should be fairly stressful.
// a bad tree will flatten and die way earlier than 128k inserts.
// a good tree will rebalance and reach height logn(128k) ~= 17,
// survival the onslaught of inserts.
const uint64_t num_keys = 128 * 1024;
// populate the tree with all the keys
for (uint64_t i = 0; i < num_keys; i++) {
DBT k;
toku_fill_dbt(&k, &i, sizeof(i));
keyrange range;
range.create(&k, &k);
lkr.insert(range, i);
}
// remove all of the keys
for (uint64_t i = 0; i < num_keys; i++) {
DBT k;
toku_fill_dbt(&k, &i, sizeof(i));
keyrange range;
range.create(&k, &k);
lkr.remove(range);
}
lkr.release();
tree.destroy();
}
} /* namespace toku */
int main(void) {
toku::concurrent_tree_unit_test test;
test.test_lkr_insert_serial_large();
return 0;
}
......@@ -29,6 +29,10 @@ public:
// whether keys exist using iterate()
void test_lkr_insert_remove(void);
// test that the concurrent tree can survive many serial inserts
// this is a blackbox test for tree rotations.
void test_lkr_insert_serial_large(void);
private:
// populate the given concurrent tree with elements from min..max but
......
......@@ -174,7 +174,7 @@ void treenode::insert(const keyrange &range, TXNID txnid) {
// otherwise recur down that child's subtree
keyrange::comparison c = range.compare(m_cmp, m_range);
if (c == keyrange::comparison::LESS_THAN) {
treenode *left_child = m_left_child.get_locked();
treenode *left_child = lock_and_rebalance_left();
if (left_child == nullptr) {
left_child = treenode::alloc(m_cmp, range, txnid);
m_left_child.set(left_child);
......@@ -184,7 +184,7 @@ void treenode::insert(const keyrange &range, TXNID txnid) {
}
} else {
invariant(c == keyrange::comparison::GREATER_THAN);
treenode *right_child = m_right_child.get_locked();
treenode *right_child = lock_and_rebalance_right();
if (right_child == nullptr) {
right_child = treenode::alloc(m_cmp, range, txnid);
m_right_child.set(right_child);
......
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