Commit 09bbe6dd authored by Yoni Fogel's avatar Yoni Fogel

Addresses #293

Checkpoint in lock tree implementation

git-svn-id: file:///svn/tokudb@1806 c7de825b-a66e-492c-adef-691d508d4ae1
parent e4b54630
......@@ -77,15 +77,17 @@ static toku_range_tree* __toku_lt_ifexist_selfread(toku_lock_tree* tree,
/* Provides access to a selfwrite tree for a particular transaction.
Creates it if it does not exist. */
static toku_range_tree* __toku_lt_selfwrite(toku_lock_tree* tree, DB_TXN* txn) {
assert(tree && txn);
static int __toku_lt_selfwrite(toku_lock_tree* tree, DB_TXN* txn,
toku_range_tree** pselfwrite) {
assert(tree && txn && pselfwrite);
assert(FALSE); //Not Implemented.
}
/* Provides access to a selfread tree for a particular transaction.
Creates it if it does not exist. */
static toku_range_tree* __toku_lt_selfread(toku_lock_tree* tree, DB_TXN* txn) {
assert(tree && txn);
static int __toku_lt_selfread(toku_lock_tree* tree, DB_TXN* txn,
toku_range_tree** pselfread) {
assert(tree && txn && pselfread);
assert(FALSE); //Not Implemented.
}
......@@ -155,6 +157,14 @@ static void __toku_init_query(toku_range* query,
query->data = NULL;
}
static void __toku_init_insert(toku_range* to_insert,
toku_point* left, toku_point* right,
DB_TXN* txn) {
to_insert->left = left;
to_insert->right = right;
to_insert->data = txn;
}
static BOOL __toku_db_is_dupsort(DB* db) {
unsigned int brtflags;
toku_brt_get_flags(db->i->brt, &brtflags);
......@@ -186,10 +196,18 @@ int toku_lt_create(toku_lock_tree** ptree, DB* db) {
r = toku_rt_create(&temp_tree->borderwrite,
__toku_lt_point_cmp, __toku_lt_txn_cmp, FALSE);
if (0) {
died3:
toku_rt_close(temp_tree->borderwrite);
goto died2;
}
if (r!=0) goto died2;
temp_tree->buflen = __toku_default_buflen;
temp_tree->buf = (toku_range*)
malloc(temp_tree->buflen * sizeof(toku_range));
if (!temp_tree->buf) {
r = errno;
goto died3;
}
//TODO: Create list of selfreads
//TODO: Create list of selfwrites
assert(FALSE); //Not implemented yet.
......@@ -200,6 +218,7 @@ int toku_lt_close(toku_lock_tree* tree) {
//TODO: Free all memory held by things inside of trees!
//TODO: Close mainread, borderwrite, all selfreads, all selfwrites,
//TODO: remove selfreads and selfwrites from txns.
//TODO: Free buf;
assert(FALSE); //Not implemented yet.
}
......@@ -237,6 +256,7 @@ int toku_lt_acquire_range_read_lock(toku_lock_tree* tree, DB_TXN* txn,
toku_range_tree* selfread;
toku_range_tree* borderwrite;
toku_range_tree* peer_selfwrite;
DB_TXN* peer;
__toku_init_point(&left, tree, key_left, data_left);
__toku_init_point(&right, tree, key_right, data_right);
......@@ -267,17 +287,39 @@ int toku_lt_acquire_range_read_lock(toku_lock_tree* tree, DB_TXN* txn,
}
}
/* Now need to merge, copy the memory and insert. */
//Function that takes the query, finds everything in selfread,
//Loops througth each of them, extending the query points, and deleting
//from mainread.
//Either point that is extended gets marked as NOT NEEDING NEW MEMORY
//We need to free (after removing from mainread) all memory
//Except any that extends our range. (if we reextend, free the old one).
//Finally we insert.
r = __toku_lt_selfread_merge(tree, &query, selfread, &newleft, &newright);
BOOL alloc_left = TRUE;
BOOL alloc_right = TRUE;
toku_range to_insert;
__toku_init_insert(&to_insert, &left, &right, txn);
if (selfread) {
//TODO: Find all that overlap in here.
//TODO: extend range to that, delete from selfread and mainread
//TODO: If left (or right) is extended/equal, copy the pointer
// and unset alloc_left (or right).
}
if (alloc_left && alloc_right && __toku_lt_point_cmp(&left, &right) == 0) {
alloc_right = FALSE;
}
if (alloc_left) {
r = __toku_p_makecopy(&left);
assert(r==0); //TODO: Error Handling instead of assert
}
if (alloc_right) {
r = __toku_p_makecopy(&right);
assert(r==0); //TODO: Error Handling instead of assert
}
if (!selfread) {
r = __toku_lt_selfread(tree, txn, &selfread);
assert(r==0); //TODO: Error Handling instead of assert
assert(selfread);
}
r = toku_rt_insert(selfread, &to_insert);
assert(r==0); //TODO: Error Handling instead of assert
assert(tree->mainread);
r = toku_rt_insert(tree->mainread, &to_insert);
assert(r==0); //TODO: Error Handling instead of assert
assert(FALSE); //Not implemented yet.
}
......
......@@ -13,11 +13,16 @@ typedef struct {
BOOL duplicates;
toku_range_tree* mainread;
toku_range_tree* borderwrite;
toku_range* buf;
unsigned buflen;
BOOL panicked;
} toku_lock_tree;
#warning TODO: Handle 'panicked' variable in every api call.
extern DBT* toku_lt_infinity;
extern DBT* toku_lt_neg_infinity;
const unsigned __toku_default_buflen = 2;
/*
* key_data = (void*)toku_lt_infinity is how we refer to the infinities.
*/
......
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