Commit 70de046e authored by Vincenzo Liberatore's avatar Vincenzo Liberatore

Addresses #311

Start the documentation of lock trees, at this point, mostly for 
our own education and understanding

git-svn-id: file:///svn/tokudb@1912 c7de825b-a66e-492c-adef-691d508d4ae1
parent fecbbf64
...@@ -3,24 +3,43 @@ ...@@ -3,24 +3,43 @@
#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." #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."
/**
\file locktree.h
\brief Lock trees: header and comments
Lock trees are toku-struct's for granting long-lived locks to transactions.
See more details on the design document.
*/
#include <assert.h> #include <assert.h>
#include <db.h> #include <db.h>
#include <brttypes.h> #include <brttypes.h>
#include <rangetree.h> #include <rangetree.h>
/** The lock tree structure */
typedef struct { typedef struct {
/** The database for which this locktree will be handling locks */
DB* db; DB* db;
/** Whether the db supports duplicate */
BOOL duplicates; BOOL duplicates;
toku_range_tree* mainread; toku_range_tree* mainread; /**< See design document */
toku_range_tree* borderwrite; toku_range_tree* borderwrite; /**< See design document */
//TODO: Remove this tree and have one per transaction. //TODO: Remove this tree and have one per transaction.
toku_range_tree* selfread; toku_range_tree* selfread;
//TODO: Remove this tree and have one per transaction. //TODO: Remove this tree and have one per transaction.
toku_range_tree* selfwrite; toku_range_tree* selfwrite;
toku_range* buf; /** A temporary area where we store the results of various find on
unsigned buflen; the range trees that this lock tree owns */
BOOL panicked; toku_range* buf;
unsigned buflen; /**< The length of buf */
/** It is true only if the various range trees are inconsistent with
each other, due to some system error like failed malloc.
If the lock tree implementation panicks, it defers to the db
panic handler */
BOOL panicked;
/** The key compare function */
int (*compare_fun)(DB*,const DBT*,const DBT*); int (*compare_fun)(DB*,const DBT*,const DBT*);
/** The data compare function */
int (*dup_compare)(DB*,const DBT*,const DBT*); int (*dup_compare)(DB*,const DBT*,const DBT*);
/** The user malloc function */ /** The user malloc function */
void* (*malloc) (size_t); void* (*malloc) (size_t);
...@@ -31,49 +50,60 @@ typedef struct { ...@@ -31,49 +50,60 @@ typedef struct {
} toku_lock_tree; } toku_lock_tree;
extern const DBT* const toku_lt_infinity; extern const DBT* const toku_lt_infinity; /**< Special value denoting
extern const DBT* const toku_lt_neg_infinity; +infty */
extern const DBT* const toku_lt_neg_infinity; /**< Special value denoting
-infty */
/* /**
* key_data = (void*)toku_lt_infinity is how we refer to the infinities. Observe the toku_point, and marvel!
It makes the pair (key, data) into a 1-dimensional point,
on which a total order is defined by toku_lt_point_cmp.
Additionally, we have points at +infty and -infty as
key_payload = (void*) toku_lt_infinity or
key_payload = (void*) toku_lt_neg infinity
*/ */
typedef struct { typedef struct {
toku_lock_tree* lt; toku_lock_tree* lt; /**< The lock tree, where toku_lt_point_cmp
void* key_payload; is defined */
u_int32_t key_len; void* key_payload; /**< The key ... */
void* data_payload; u_int32_t key_len; /**< and its length */
u_int32_t data_len; void* data_payload; /**< The data ... */
u_int32_t data_len; /**< and its length */
} toku_point; } toku_point;
/* /**
* Wrapper of db compare and dup_compare functions. A comparison function between toku_point's.
* In addition, also uses toku_lt_infinity and toku_lt_neg_infinity. It is implemented as a wrapper of db compare and dup_compare functions,
* Parameters are of type toku_point. but it checks whether the point is +/- infty.
* Parameters are of type toku_point.
* Return values conform to cmp from quicksort(3). Return values conform to cmp from qsort(3).
*/ */
int toku_lt_point_cmp(void* a, void* b); int toku_lt_point_cmp(void* a, void* b);
/* /**
* Create a lock tree. Should be called only inside DB->open. Create a lock tree. Should be called only inside DB->open.
* Params:
* ptree: We set *ptree to the newly allocated tree. \param ptree: We set *ptree to the newly allocated tree.
* db: This is the db that the lock tree will be performing locking for. \param db: This is the db that the lock tree will be performing
* duplicates whether the db supports duplicates. locking for.
* compare_fun the key compare function. \param duplicates Whether the db supports duplicates.
* dup_compare the data compare function. \param compare_fun The key compare function.
\param user_malloc A user provided malloc(3) function. \param dup_compare The data compare function.
\param user_free A user provided free(3) function. \param user_malloc A user provided malloc(3) function.
\param user_realloc A user provided realloc(3) function. \param user_free A user provided free(3) function.
* Returns: \param user_realloc A user provided realloc(3) function.
* 0: Success
* EINVAL: If any pointer parameter is NULL. \return
* FutureChecks: Try to return EINVAL for already opened db, - 0: Success
* or already closed db. - May return other errors due to system calls.
* May return other errors due to system calls.
* Asserts: A pre-condition is that no pointer parameter can be NULL;
* The EINVAL cases described will use assert to abort instead of returning errors. this pre-condition is assert(3)'ed.
* If this library is ever exported to users, we will use error datas instead. A future check is that it should return EINVAL for already opened db
or already closed db.
If this library is ever exported to users, we will use error datas
instead.
*/ */
int toku_lt_create(toku_lock_tree** ptree, DB* db, BOOL duplicates, int toku_lt_create(toku_lock_tree** ptree, DB* db, BOOL duplicates,
int (*compare_fun)(DB*,const DBT*,const DBT*), int (*compare_fun)(DB*,const DBT*,const DBT*),
...@@ -83,26 +113,25 @@ int toku_lt_create(toku_lock_tree** ptree, DB* db, BOOL duplicates, ...@@ -83,26 +113,25 @@ int toku_lt_create(toku_lock_tree** ptree, DB* db, BOOL duplicates,
void* (*user_realloc)(void*, size_t)); void* (*user_realloc)(void*, size_t));
/* /**
* Closes/Frees a lock tree. Closes and frees a lock tree.
* Params: It will free memory used by the tree, and all keys/datas
* tree: The tree to free. from all internal structures.
* Returns: It handles the case of transactions that are still active
* 0: Success. when lt_close is invoked: it can throw away other tables, but
* EINVAL: If (tree == NULL) it keeps lists of selfread and selfwrite, and frees the memory
* Asserts: pointed to by the DBTs contained in the selfread and selfwrite.
* The EINVAL cases described will use assert to abort instead of returning errors.
* If this library is ever exported to users, we will use error datas instead. \param tree: The tree to free.
* Memory:
* This will free memory used by the tree, and all keys/datas \return
* from all internal structures. - 0: Success.
*/
It asserts that the tree != NULL.
If this library is ever exported to users, we will use error datas instead.
*/
int toku_lt_close(toku_lock_tree* tree); int toku_lt_close(toku_lock_tree* tree);
//NOTE: Must handle case of transactions still active.
//Need to keep lists of selfread and selfwrite.
//can throw away other tables, but must go through each
//of the selfread and selfwrite tables and free the memory
//pointed to by the DBTs contained.
/* /*
* Acquires a read lock on a single key (or key/data). * Acquires a read lock on a single key (or key/data).
......
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