Commit 35a46f2e authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

#3853 make the lock tree memory accounting more accurate refs[t:3853]

git-svn-id: file:///svn/toku/tokudb@36278 c7de825b-a66e-492c-adef-691d508d4ae1
parent d69063c8
......@@ -1262,8 +1262,6 @@ test_serialize_nonleaf(enum brtnode_verify_type bft) {
int
test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) {
toku_memory_check = 1;
test_serialize_leaf(read_none);
test_serialize_leaf(read_all);
test_serialize_leaf(read_compressed);
......
......@@ -14,7 +14,7 @@ static void test_dump_empty_db (void) {
BRT t;
CACHETABLE ct;
int r;
toku_memory_check=1;
r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
unlink(fname);
......@@ -1219,7 +1219,7 @@ static void test_new_brt_cursors(void) {
}
static void brt_blackbox_test (void) {
toku_memory_check = 1;
test_wrongendian_compare(0, 2);
test_wrongendian_compare(1, 2);
test_wrongendian_compare(1, 257);
......@@ -1236,8 +1236,6 @@ static void brt_blackbox_test (void) {
if (verbose) printf("test_multiple_files\n");
test_multiple_files();
toku_memory_check = 1;
test_brt_limits();
test_brt_delete();
......
......@@ -14,7 +14,6 @@ static void test0 (void) {
CACHETABLE ct;
char fname[]= __FILE__ "0.brt";
if (verbose) printf("%s:%d test0\n", __FILE__, __LINE__);
toku_memory_check=1;
r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
......
......@@ -14,7 +14,6 @@ static void test1 (void) {
CACHETABLE ct;
char fname[]= __FILE__ "1.brt";
DBT k,v;
toku_memory_check=1;
r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
......
......@@ -8,13 +8,12 @@
static TOKUTXN const null_txn = 0;
static DB * const null_db = 0;
static void test2 (int memcheck, int limit) {
static void test2 (int limit) {
BRT t;
int r;
int i;
CACHETABLE ct;
char fname[]= __FILE__ "2.brt";
toku_memory_check=memcheck;
if (verbose) printf("%s:%d checking\n", __FILE__, __LINE__);
r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
......@@ -47,13 +46,11 @@ static void test2 (int memcheck, int limit) {
int
test_main (int argc , const char *argv[]) {
default_parse_args(argc, argv);
// if (verbose) printf("test2 checking memory\n");
// test2(1);
if (verbose) printf("test2 faster\n");
test2(0, 2);
test2(0, 27);
test2(0, 212);
test2(0, 4096);
test2(2);
test2(27);
test2(212);
test2(4096);
if (verbose) printf("test1 ok\n");
return 0;
......
......@@ -11,13 +11,12 @@ static const char fname[]= __FILE__ ".brt";
static TOKUTXN const null_txn = 0;
static DB * const null_db = 0;
static void test3 (int nodesize, int basementnodesize, int count, int memcheck) {
static void test3 (int nodesize, int basementnodesize, int count) {
BRT t;
int r;
struct timeval t0,t1;
int i;
CACHETABLE ct;
toku_memory_check=memcheck;
r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
gettimeofday(&t0, 0);
......@@ -45,26 +44,25 @@ static void test3 (int nodesize, int basementnodesize, int count, int memcheck)
static void brt_blackbox_test (void) {
if (verbose) printf("test3 slow\n");
toku_memory_check=0;
test3(2048, 512, 1<<15, 1);
test3(2048, 512, 1<<15);
if (verbose) printf("test3 fast\n");
//if (verbose) toku_pma_show_stats();
test3(1<<15, 1<<12, 1024, 1);
test3(1<<15, 1<<12, 1024);
if (verbose) printf("test3 fast\n");
test3(1<<18, 1<<15, 1<<20, 0);
test3(1<<18, 1<<15, 1<<20);
toku_memory_check = 1;
// test3(1<<19, 1<<16, 1<<20, 0);
// test3(1<<19, 1<<16, 1<<20);
// test3(1<<20, 1<<17, 1<<20, 0);
// test3(1<<20, 1<<17, 1<<20);
// test3(1<<20, 1<<17, 1<<21, 0);
// test3(1<<20, 1<<17, 1<<21);
// test3(1<<20, 1<<17, 1<<22, 0);
// test3(1<<20, 1<<17, 1<<22);
}
......
......@@ -11,7 +11,7 @@ static const char fname[]= __FILE__ ".brt";
static TOKUTXN const null_txn = 0;
static DB * const null_db = 0;
static void test4 (int nodesize, int count, int memcheck) {
static void test4 (int nodesize, int count) {
BRT t;
int r;
struct timeval t0,t1;
......@@ -19,7 +19,6 @@ static void test4 (int nodesize, int count, int memcheck) {
CACHETABLE ct;
gettimeofday(&t0, 0);
unlink(fname);
toku_memory_check=memcheck;
r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = toku_open_brt(fname, 1, &t, nodesize, nodesize / 8, ct, null_txn, toku_builtin_compare_fun, null_db); assert(r==0);
......@@ -44,21 +43,21 @@ static void test4 (int nodesize, int count, int memcheck) {
}
static void brt_blackbox_test (void) {
test4(2048, 1<<14, 1);
test4(2048, 1<<14);
if (0) {
if (verbose) printf("test4 slow\n");
test4(2048, 1<<15, 1);
test4(2048, 1<<15);
//if (verbose) toku_pma_show_stats();
test4(1<<15, 1024, 1);
test4(1<<15, 1024);
test4(1<<18, 1<<20, 0);
test4(1<<18, 1<<20);
// Once upon a time srandom(8) caused this test to fail.
srandom(8); test4(2048, 1<<15, 1);
srandom(8); test4(2048, 1<<15);
}
}
......
......@@ -1069,7 +1069,6 @@ parse_args(int argc, const char *argv[]) {
int
test_main (int argc, const char *argv[]) {
toku_memory_check = 1;
parse_args(argc, argv);
int r;
......
......@@ -32,7 +32,6 @@ found(ITEMLEN UU(keylen), bytevec key, ITEMLEN UU(vallen), bytevec UU(val), void
int
test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) {
toku_memory_check = 1;
CACHETABLE ct;
BRT t;
......
......@@ -501,7 +501,6 @@ test_split_at_end(void)
int
test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) {
toku_memory_check = 1;
test_split_on_boundary();
test_split_with_everything_on_the_left();
......
......@@ -10,6 +10,7 @@
*/
#include <toku_portability.h>
#include "memory.h"
#include <idlth.h>
#include <toku_assert.h>
#include <errno.h>
......@@ -28,23 +29,17 @@ static inline void toku__invalidate_scan(toku_idlth* idlth) {
idlth->iter_is_valid = FALSE;
}
int toku_idlth_create(toku_idlth** pidlth,
void* (*user_malloc) (size_t),
void (*user_free) (void*),
void* (*user_realloc)(void*, size_t)) {
int toku_idlth_create(toku_idlth** pidlth) {
int r = ENOSYS;
assert(pidlth && user_malloc && user_free && user_realloc);
assert(pidlth);
toku_idlth* tmp = NULL;
tmp = (toku_idlth*)user_malloc(sizeof(*tmp));
tmp = (toku_idlth*) toku_malloc(sizeof(*tmp));
if (!tmp) { r = ENOMEM; goto cleanup; }
memset(tmp, 0, sizeof(*tmp));
tmp->malloc = user_malloc;
tmp->free = user_free;
tmp->realloc = user_realloc;
tmp->num_buckets = __toku_idlth_init_size;
tmp->buckets = (toku_idlth_elt*)
tmp->malloc(tmp->num_buckets * sizeof(*tmp->buckets));
toku_malloc(tmp->num_buckets * sizeof(*tmp->buckets));
if (!tmp->buckets) { r = ENOMEM; goto cleanup; }
memset(tmp->buckets, 0, tmp->num_buckets * sizeof(*tmp->buckets));
toku__invalidate_scan(tmp);
......@@ -56,8 +51,8 @@ int toku_idlth_create(toku_idlth** pidlth,
cleanup:
if (r != 0) {
if (tmp) {
if (tmp->buckets) { user_free(tmp->buckets); }
user_free(tmp);
if (tmp->buckets) { toku_free(tmp->buckets); }
toku_free(tmp);
}
}
return r;
......@@ -87,7 +82,7 @@ static inline toku_idlth_elt* toku__idlth_next(toku_idlth* idlth) {
assert(idlth->iter_is_valid);
idlth->iter_curr = idlth->iter_curr->next_in_iteration;
idlth->iter_is_valid = (BOOL)(idlth->iter_curr != &idlth->iter_head);
idlth->iter_is_valid = (idlth->iter_curr != &idlth->iter_head);
return idlth->iter_curr;
}
......@@ -120,7 +115,7 @@ void toku_idlth_delete(toku_idlth* idlth, DICTIONARY_ID dict_id) {
current->prev_in_iteration->next_in_iteration = current->next_in_iteration;
current->next_in_iteration->prev_in_iteration = current->prev_in_iteration;
prev->next_in_bucket = current->next_in_bucket;
idlth->free(current);
toku_free(current);
idlth->num_keys--;
return;
}
......@@ -134,7 +129,7 @@ int toku_idlth_insert(toku_idlth* idlth, DICTIONARY_ID dict_id) {
uint32_t index = toku__idlth_hash(idlth, dict_id);
/* Allocate a new one. */
toku_idlth_elt* element = (toku_idlth_elt*)idlth->malloc(sizeof(*element));
toku_idlth_elt* element = (toku_idlth_elt*) toku_malloc(sizeof(*element));
if (!element) { r = ENOMEM; goto cleanup; }
memset(element, 0, sizeof(*element));
element->value.dict_id = dict_id;
......@@ -153,7 +148,7 @@ cleanup:
return r;
}
static inline void toku__idlth_clear(toku_idlth* idlth, BOOL clean) {
static inline void toku__idlth_clear(toku_idlth* idlth, bool clean) {
assert(idlth);
toku_idlth_elt* element;
......@@ -164,7 +159,7 @@ static inline void toku__idlth_clear(toku_idlth* idlth, BOOL clean) {
while (next != head) {
element = next;
next = toku__idlth_next(idlth);
idlth->free(element);
toku_free(element);
}
/* If clean is true, then we want to restore it to 'just created' status.
If we are closing the tree, we don't need to do that restoration. */
......@@ -184,16 +179,16 @@ void toku_idlth_close(toku_idlth* idlth) {
assert(idlth);
toku__idlth_clear(idlth, FALSE);
idlth->free(idlth->buckets);
idlth->free(idlth);
toku_free(idlth->buckets);
toku_free(idlth);
}
BOOL toku_idlth_is_empty(toku_idlth* idlth) {
bool toku_idlth_is_empty(toku_idlth* idlth) {
assert(idlth);
/* Verify consistency. */
assert((idlth->num_keys == 0) ==
(idlth->iter_head.next_in_iteration == &idlth->iter_head));
assert((idlth->num_keys == 0) ==
(idlth->iter_head.prev_in_iteration == &idlth->iter_head));
return (BOOL)(idlth->num_keys == 0);
return (idlth->num_keys == 0);
}
......@@ -11,7 +11,7 @@
*/
//Defines BOOL data type.
//Defines bool data type.
#include <db.h>
#include <brttypes.h>
#include <rangetree.h>
......@@ -46,19 +46,10 @@ struct __toku_idlth {
uint32_t num_keys;
toku_idlth_elt iter_head;
toku_idlth_elt* iter_curr;
BOOL iter_is_valid;
/** The user malloc function */
void* (*malloc) (size_t);
/** The user free function */
void (*free) (void*);
/** The user realloc function */
void* (*realloc)(void*, size_t);
bool iter_is_valid;
};
int toku_idlth_create(toku_idlth** ptable,
void* (*user_malloc) (size_t),
void (*user_free) (void*),
void* (*user_realloc)(void*, size_t));
int toku_idlth_create(toku_idlth** ptable);
toku_lt_map* toku_idlth_find (toku_idlth* table, DICTIONARY_ID dict_id);
......@@ -74,7 +65,7 @@ int toku_idlth_insert (toku_idlth* table, DICTIONARY_ID dict_id)
void toku_idlth_clear (toku_idlth* idlth);
BOOL toku_idlth_is_empty (toku_idlth* idlth);
bool toku_idlth_is_empty (toku_idlth* idlth);
#if defined(__cplusplus)
}
......
This diff is collapsed.
......@@ -97,7 +97,7 @@ struct __toku_lock_tree {
toku_range* bw_buf;
uint32_t bw_buflen;
/** Whether lock escalation is allowed. */
BOOL lock_escalation_allowed;
bool lock_escalation_allowed;
/** Lock tree manager */
toku_ltm* mgr;
/** Function to retrieve the key compare function from the database. */
......@@ -106,12 +106,6 @@ struct __toku_lock_tree {
int (*compare_fun)(DB*,const DBT*,const DBT*);
/** The panic function */
int (*panic)(DB*, int);
/** The user malloc function */
void* (*malloc) (size_t);
/** The user free function */
void (*free) (void*);
/** The user realloc function */
void* (*realloc)(void*, size_t);
/** The number of references held by DB instances and transactions to this lock tree*/
uint32_t ref_count;
/** DICTIONARY_ID associated with the lock tree */
......@@ -158,12 +152,6 @@ struct __toku_ltm {
toku_dbt_cmp (*get_compare_fun_from_db)(DB*);
/** The panic function */
int (*panic)(DB*, int);
/** The user malloc function */
void* (*malloc) (size_t);
/** The user free function */
void (*free) (void*);
/** The user realloc function */
void* (*realloc)(void*, size_t);
toku_pthread_mutex_t lock;
toku_pthread_mutex_t *use_lock;
......@@ -205,9 +193,6 @@ typedef struct __toku_point toku_point;
\param panic The function to cause the db to panic.
i.e., godzilla_rampage()
\param payload_capacity The maximum amount of memory to use for dbt payloads.
\param user_malloc A user provided malloc(3) function.
\param user_free A user provided free(3) function.
\param user_realloc A user provided realloc(3) function.
\return
- 0 Success
......@@ -225,10 +210,7 @@ typedef struct __toku_point toku_point;
int toku_lt_create(toku_lock_tree** ptree,
int (*panic)(DB*, int),
toku_ltm* mgr,
toku_dbt_cmp (*get_compare_fun_from_db)(DB*),
void* (*user_malloc) (size_t),
void (*user_free) (void*),
void* (*user_realloc)(void*, size_t));
toku_dbt_cmp (*get_compare_fun_from_db)(DB*));
/**
Gets a lock tree for a given DB with id dict_id
......@@ -410,9 +392,6 @@ int toku_lt_unlock(toku_lock_tree* tree, TXNID txn);
\param pmgr A buffer for the new lock tree manager.
\param max_locks The maximum number of locks.
\param user_malloc A user provided malloc(3) function.
\param user_free A user provided free(3) function.
\param user_realloc A user provided realloc(3) function.
\return
- 0 on success.
......@@ -423,10 +402,7 @@ int toku_ltm_create(toku_ltm** pmgr,
uint32_t max_locks,
uint64_t max_lock_memory,
int (*panic)(DB*, int),
toku_dbt_cmp (*get_compare_fun_from_db)(DB*),
void* (*user_malloc) (size_t),
void (*user_free) (void*),
void* (*user_realloc)(void*, size_t));
toku_dbt_cmp (*get_compare_fun_from_db)(DB*));
/**
Closes and frees a lock tree manager..
......@@ -464,6 +440,9 @@ void toku_ltm_get_status(toku_ltm* mgr, uint32_t * max_locks, uint32_t * curr_lo
int toku_ltm_get_max_locks(toku_ltm* mgr, uint32_t* max_locks);
void toku_ltm_incr_lock_memory(void *extra, size_t s);
void toku_ltm_decr_lock_memory(void *extra, size_t s);
void toku_lt_add_ref(toku_lock_tree* tree);
int toku_lt_remove_ref(toku_lock_tree* tree);
......
......@@ -10,6 +10,7 @@
*/
#include <toku_portability.h>
#include "memory.h"
#include "lth.h"
#include <toku_assert.h>
#include <errno.h>
......@@ -27,23 +28,17 @@ static inline void toku__invalidate_scan(toku_lth* lth) {
lth->iter_is_valid = FALSE;
}
int toku_lth_create(toku_lth** plth,
void* (*user_malloc) (size_t),
void (*user_free) (void*),
void* (*user_realloc)(void*, size_t)) {
int toku_lth_create(toku_lth** plth) {
int r = ENOSYS;
assert(plth && user_malloc && user_free && user_realloc);
assert(plth);
toku_lth* tmp = NULL;
tmp = (toku_lth*)user_malloc(sizeof(*tmp));
tmp = (toku_lth*) toku_malloc(sizeof(*tmp));
if (!tmp) { r = ENOMEM; goto cleanup; }
memset(tmp, 0, sizeof(*tmp));
tmp->malloc = user_malloc;
tmp->free = user_free;
tmp->realloc = user_realloc;
tmp->num_buckets = __toku_lth_init_size;
tmp->buckets = (toku_lth_elt*)
tmp->malloc(tmp->num_buckets * sizeof(*tmp->buckets));
toku_malloc(tmp->num_buckets * sizeof(*tmp->buckets));
if (!tmp->buckets) { r = ENOMEM; goto cleanup; }
memset(tmp->buckets, 0, tmp->num_buckets * sizeof(*tmp->buckets));
toku__invalidate_scan(tmp);
......@@ -55,8 +50,8 @@ int toku_lth_create(toku_lth** plth,
cleanup:
if (r != 0) {
if (tmp) {
if (tmp->buckets) { user_free(tmp->buckets); }
user_free(tmp);
if (tmp->buckets) { toku_free(tmp->buckets); }
toku_free(tmp);
}
}
return r;
......@@ -86,7 +81,7 @@ static inline toku_lth_elt* toku__lth_next(toku_lth* lth) {
assert(lth->iter_is_valid);
lth->iter_curr = lth->iter_curr->next_in_iteration;
lth->iter_is_valid = (BOOL)(lth->iter_curr != &lth->iter_head);
lth->iter_is_valid = (bool)(lth->iter_curr != &lth->iter_head);
return lth->iter_curr;
}
......@@ -119,7 +114,7 @@ void toku_lth_delete(toku_lth* lth, toku_lock_tree* key) {
current->prev_in_iteration->next_in_iteration = current->next_in_iteration;
current->next_in_iteration->prev_in_iteration = current->prev_in_iteration;
prev->next_in_bucket = current->next_in_bucket;
lth->free(current);
toku_free(current);
lth->num_keys--;
return;
}
......@@ -133,7 +128,7 @@ int toku_lth_insert(toku_lth* lth, toku_lock_tree* key) {
uint32_t index = toku__lth_hash(lth, key);
/* Allocate a new one. */
toku_lth_elt* element = (toku_lth_elt*)lth->malloc(sizeof(*element));
toku_lth_elt* element = (toku_lth_elt*) toku_malloc(sizeof(*element));
if (!element) { r = ENOMEM; goto cleanup; }
memset(element, 0, sizeof(*element));
element->value.hash_key = key;
......@@ -162,9 +157,9 @@ void toku_lth_close(toku_lth* lth) {
while (next != head) {
element = next;
next = toku__lth_next(lth);
lth->free(element);
toku_free(element);
}
lth->free(lth->buckets);
lth->free(lth);
toku_free(lth->buckets);
toku_free(lth);
}
......@@ -12,7 +12,7 @@
*/
//Defines BOOL data type.
//Defines bool data type.
#include <db.h>
#include <brttypes.h>
#include <locktree.h>
......@@ -51,20 +51,11 @@ struct __toku_lth {
uint32_t num_keys;
toku_lth_elt iter_head;
toku_lth_elt* iter_curr;
BOOL iter_is_valid;
/** The user malloc function */
void* (*malloc) (size_t);
/** The user free function */
void (*free) (void*);
/** The user realloc function */
void* (*realloc)(void*, size_t);
bool iter_is_valid;
};
int toku_lth_create(toku_lth** ptable,
void* (*user_malloc) (size_t),
void (*user_free) (void*),
void* (*user_realloc)(void*, size_t));
int toku_lth_create(toku_lth** ptable);
toku_lock_tree* toku_lth_find (toku_lth* table, toku_lock_tree* key);
......
......@@ -10,6 +10,7 @@
*/
#include <toku_portability.h>
#include "memory.h"
#include "rth.h"
#include <toku_assert.h>
#include <errno.h>
......@@ -27,23 +28,17 @@ static inline void toku__invalidate_scan(toku_rth* rth) {
rth->iter_is_valid = FALSE;
}
int toku_rth_create(toku_rth** prth,
void* (*user_malloc) (size_t),
void (*user_free) (void*),
void* (*user_realloc)(void*, size_t)) {
int toku_rth_create(toku_rth** prth) {
int r = ENOSYS;
assert(prth && user_malloc && user_free && user_realloc);
assert(prth);
toku_rth* tmp = NULL;
tmp = (toku_rth*)user_malloc(sizeof(*tmp));
tmp = (toku_rth*) toku_malloc(sizeof(*tmp));
if (!tmp) { r = ENOMEM; goto cleanup; }
memset(tmp, 0, sizeof(*tmp));
tmp->malloc = user_malloc;
tmp->free = user_free;
tmp->realloc = user_realloc;
tmp->num_buckets = __toku_rth_init_size;
tmp->buckets = (toku_rth_elt*)
tmp->malloc(tmp->num_buckets * sizeof(*tmp->buckets));
toku_malloc(tmp->num_buckets * sizeof(*tmp->buckets));
if (!tmp->buckets) { r = ENOMEM; goto cleanup; }
memset(tmp->buckets, 0, tmp->num_buckets * sizeof(*tmp->buckets));
toku__invalidate_scan(tmp);
......@@ -55,8 +50,8 @@ int toku_rth_create(toku_rth** prth,
cleanup:
if (r != 0) {
if (tmp) {
if (tmp->buckets) { user_free(tmp->buckets); }
user_free(tmp);
if (tmp->buckets) { toku_free(tmp->buckets); }
toku_free(tmp);
}
}
return r;
......@@ -86,7 +81,7 @@ static inline toku_rth_elt* toku__rth_next(toku_rth* rth) {
assert(rth->iter_is_valid);
rth->iter_curr = rth->iter_curr->next_in_iteration;
rth->iter_is_valid = (BOOL)(rth->iter_curr != &rth->iter_head);
rth->iter_is_valid = (rth->iter_curr != &rth->iter_head);
return rth->iter_curr;
}
......@@ -119,7 +114,7 @@ void toku_rth_delete(toku_rth* rth, TXNID key) {
current->prev_in_iteration->next_in_iteration = current->next_in_iteration;
current->next_in_iteration->prev_in_iteration = current->prev_in_iteration;
prev->next_in_bucket = current->next_in_bucket;
rth->free(current);
toku_free(current);
rth->num_keys--;
return;
}
......@@ -133,7 +128,7 @@ int toku_rth_insert(toku_rth* rth, TXNID key) {
uint32_t index = toku__rth_hash(rth, key);
/* Allocate a new one. */
toku_rth_elt* element = (toku_rth_elt*)rth->malloc(sizeof(*element));
toku_rth_elt* element = (toku_rth_elt*) toku_malloc(sizeof(*element));
if (!element) { r = ENOMEM; goto cleanup; }
memset(element, 0, sizeof(*element));
element->value.hash_key = key;
......@@ -151,7 +146,7 @@ cleanup:
return r;
}
static inline void toku__rth_clear(toku_rth* rth, BOOL clean) {
static inline void toku__rth_clear(toku_rth* rth, bool clean) {
assert(rth);
toku_rth_elt* element;
......@@ -162,7 +157,7 @@ static inline void toku__rth_clear(toku_rth* rth, BOOL clean) {
while (next != head) {
element = next;
next = toku__rth_next(rth);
rth->free(element);
toku_free(element);
}
/* If clean is true, then we want to restore it to 'just created' status.
If we are closing the tree, we don't need to do that restoration. */
......@@ -182,16 +177,16 @@ void toku_rth_close(toku_rth* rth) {
assert(rth);
toku__rth_clear(rth, FALSE);
rth->free(rth->buckets);
rth->free(rth);
toku_free(rth->buckets);
toku_free(rth);
}
BOOL toku_rth_is_empty(toku_rth* rth) {
bool toku_rth_is_empty(toku_rth* rth) {
assert(rth);
/* Verify consistency. */
assert((rth->num_keys == 0) ==
(rth->iter_head.next_in_iteration == &rth->iter_head));
assert((rth->num_keys == 0) ==
(rth->iter_head.prev_in_iteration == &rth->iter_head));
return (BOOL)(rth->num_keys == 0);
return (rth->num_keys == 0);
}
......@@ -11,7 +11,6 @@
*/
//Defines BOOL data type.
#include <db.h>
#include <brttypes.h>
#include <rangetree.h>
......@@ -42,19 +41,10 @@ struct __toku_rth {
uint32_t num_keys;
toku_rth_elt iter_head;
toku_rth_elt* iter_curr;
BOOL iter_is_valid;
/** The user malloc function */
void* (*malloc) (size_t);
/** The user free function */
void (*free) (void*);
/** The user realloc function */
void* (*realloc)(void*, size_t);
bool iter_is_valid;
};
int toku_rth_create(toku_rth** ptable,
void* (*user_malloc) (size_t),
void (*user_free) (void*),
void* (*user_realloc)(void*, size_t));
int toku_rth_create(toku_rth** ptable);
rt_forest* toku_rth_find (toku_rth* table, TXNID key);
......@@ -70,7 +60,7 @@ int toku_rth_insert (toku_rth* table, TXNID key);
void toku_rth_clear (toku_rth* rth);
BOOL toku_rth_is_empty (toku_rth* rth);
bool toku_rth_is_empty (toku_rth* rth);
#if defined(__cplusplus)
}
......
......@@ -75,3 +75,37 @@ clean:
rm -f $(ALL_TESTS)
rm -rf dir.*.lin dir.*.tlog dir.*.log
check_footprint.linrun: check_footprint_point.linrun check_footprint_range.linrun
true
check_footprint_point.linrun: test_footprint_point_write.lin
$(VGRIND) ./$< -v --nrows 1 && \
$(VGRIND) ./$< -v --nrows 2 && \
$(VGRIND) ./$< -v --nrows 10 --max_locks 1000 && \
$(VGRIND) ./$< -v --nrows 100 --max_locks 1000 && \
$(VGRIND) ./$< -v --nrows 1000 --max_locks 1000
check_footprint_range.linrun: test_footprint_range_write.lin
$(VGRIND) ./$< -v --nrows 1 && \
$(VGRIND) ./$< -v --nrows 2 && \
$(VGRIND) ./$< -v --nrows 10 --max_locks 1000 && \
$(VGRIND) ./$< -v --nrows 100 --max_locks 1000 && \
$(VGRIND) ./$< -v --nrows 1000 --max_locks 1000
check_footprint.tlogrun: check_footprint_point.tlogrun check_footprint_range.tlogrun
true
check_footprint_point.tlogrun: test_footprint_point_write.tlog
$(VGRIND) ./$< -v --nrows 1 && \
$(VGRIND) ./$< -v --nrows 2 && \
$(VGRIND) ./$< -v --nrows 10 --max_locks 1000 && \
$(VGRIND) ./$< -v --nrows 100 --max_locks 1000 && \
$(VGRIND) ./$< -v --nrows 1000 --max_locks 1000
check_footprint_range.tlogrun: test_footprint_range_write.tlog
$(VGRIND) ./$< -v --nrows 1 && \
$(VGRIND) ./$< -v --nrows 2 && \
$(VGRIND) ./$< -v --nrows 10 --max_locks 1000 && \
$(VGRIND) ./$< -v --nrows 100 --max_locks 1000 && \
$(VGRIND) ./$< -v --nrows 1000 --max_locks 1000
......@@ -38,11 +38,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
DB *db_a = (DB *) 2;
......
......@@ -17,7 +17,7 @@ int verbose=0;
#include <key.h>
BOOL want_panic = FALSE;
bool want_panic = false;
static inline int intcmp(DB *db __attribute__((__unused__)), const DBT* a, const DBT* b) {
int x = *(int*)a->data;
......@@ -39,11 +39,11 @@ static inline toku_dbt_cmp get_compare_fun_from_db(__attribute__((unused)) DB* d
return compare_fun;
}
BOOL panicked = FALSE;
bool panicked = false;
static inline int dbpanic(DB* db, int r) {
if (verbose) printf("AHH!!!! %d is rampaging! Run away %p!!!\n", r, db);
panicked = TRUE;
panicked = true;
assert(want_panic);
return EINVAL;
}
......@@ -107,13 +107,3 @@ static inline void init_point(toku_point* point, toku_lock_tree* tree) {
point->lt = tree;
}
int mallocced = 0;
int failon = -1;
static inline void* fail_malloc(size_t size) {
if (++mallocced == failon) {
errno = ENOMEM;
return NULL;
}
return toku_malloc(size);
}
......@@ -8,14 +8,12 @@ int main(void) {
uint64_t max_lock_memory = max_locks*64;
r = toku_ltm_create(&mgr, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
get_compare_fun_from_db);
CKERR(r);
{
r = toku_lt_create(&lt, dbpanic, mgr,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
get_compare_fun_from_db);
CKERR(r);
assert(lt);
r = toku_lt_close(lt);
......
......@@ -22,9 +22,8 @@ static void do_range_test(int (*acquire)(toku_lock_tree*, DB*, TXNID,
DBT* key_l = &_key_l;
DBT* key_r = &_key_r;
{
r = toku_lt_create(&lt, dbpanic, ltm,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
CKERR(r);
assert(lt);
......@@ -65,9 +64,7 @@ static void do_point_test(int (*acquire)(toku_lock_tree*, DB*, TXNID,
/* Point read tests. */
key = &_key;
{
r = toku_lt_create(&lt, dbpanic, ltm,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
CKERR(r);
assert(lt);
......@@ -94,113 +91,69 @@ int main(int argc, const char *argv[]) {
int r;
toku_lock_tree* lt = NULL;
r = toku_ltm_create(NULL, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
assert(ltm == NULL);
r = toku_ltm_create(&ltm, 0, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
assert(ltm == NULL);
r = toku_ltm_create(&ltm, max_locks, 0, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
assert(ltm == NULL);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
NULL, toku_free, toku_realloc);
CKERR2(r, EINVAL);
assert(ltm == NULL);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, NULL, toku_realloc);
CKERR2(r, EINVAL);
assert(ltm == NULL);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, NULL);
CKERR2(r, EINVAL);
assert(ltm == NULL);
r = toku_ltm_create(NULL, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
CKERR2(r, EINVAL);
assert(ltm == NULL);
r = toku_ltm_create(&ltm, 0, max_lock_memory, dbpanic, get_compare_fun_from_db);
CKERR2(r, EINVAL);
assert(ltm == NULL);
r = toku_ltm_create(&ltm, max_locks, 0, dbpanic, get_compare_fun_from_db);
CKERR2(r, EINVAL);
assert(ltm == NULL);
/* Actually create it. */
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
CKERR(r);
assert(ltm);
r = toku_ltm_set_max_locks(NULL, max_locks);
CKERR2(r, EINVAL);
CKERR2(r, EINVAL);
r = toku_ltm_set_max_locks(ltm, 0);
CKERR2(r, EINVAL);
CKERR2(r, EINVAL);
r = toku_ltm_set_max_locks(ltm, max_locks);
CKERR(r);
CKERR(r);
uint32_t get_max = 73; //Some random number that isn't 0.
r = toku_ltm_get_max_locks(NULL, &get_max);
CKERR2(r, EINVAL);
assert(get_max == 73);
CKERR2(r, EINVAL);
assert(get_max == 73);
r = toku_ltm_get_max_locks(ltm, NULL);
CKERR2(r, EINVAL);
assert(get_max == 73);
CKERR2(r, EINVAL);
assert(get_max == 73);
r = toku_ltm_get_max_locks(ltm, &get_max);
CKERR(r);
assert(get_max == max_locks);
CKERR(r);
assert(get_max == max_locks);
r = toku_ltm_set_max_lock_memory(NULL, max_lock_memory);
CKERR2(r, EINVAL);
CKERR2(r, EINVAL);
r = toku_ltm_set_max_lock_memory(ltm, 0);
CKERR2(r, EINVAL);
CKERR2(r, EINVAL);
r = toku_ltm_set_max_lock_memory(ltm, max_lock_memory);
CKERR(r);
CKERR(r);
uint64_t get_max_memory = 73; //Some random number that isn't 0.
r = toku_ltm_get_max_lock_memory(NULL, &get_max_memory);
CKERR2(r, EINVAL);
assert(get_max_memory == 73);
CKERR2(r, EINVAL);
assert(get_max_memory == 73);
r = toku_ltm_get_max_lock_memory(ltm, NULL);
CKERR2(r, EINVAL);
assert(get_max_memory == 73);
CKERR2(r, EINVAL);
assert(get_max_memory == 73);
r = toku_ltm_get_max_lock_memory(ltm, &get_max_memory);
CKERR(r);
assert(get_max_memory == max_lock_memory);
CKERR(r);
assert(get_max_memory == max_lock_memory);
/* create tests. */
{
r = toku_lt_create(NULL, dbpanic, ltm,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(NULL, dbpanic, ltm, get_compare_fun_from_db);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, NULL, ltm,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, NULL, ltm, get_compare_fun_from_db);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, dbpanic, NULL,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, NULL, get_compare_fun_from_db);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, dbpanic, ltm,
NULL,
toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, dbpanic, ltm,
get_compare_fun_from_db,
NULL, toku_free, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, dbpanic, ltm,
get_compare_fun_from_db,
toku_malloc, NULL, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, dbpanic, ltm,
get_compare_fun_from_db,
toku_malloc, toku_free, NULL);
r = toku_lt_create(&lt, dbpanic, ltm, NULL);
CKERR2(r, EINVAL);
}
......
......@@ -10,7 +10,7 @@ TXNID txn = (TXNID)1;
enum { MAX_LT_LOCKS = 1000 };
uint32_t max_locks = MAX_LT_LOCKS;
uint64_t max_lock_memory = MAX_LT_LOCKS*64;
BOOL duplicates = FALSE;
bool duplicates = false;
int nums[100];
DBT _keys_left[2];
......@@ -42,25 +42,20 @@ static void init_query(void) {
static void setup_tree(void) {
assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
CKERR(r);
assert(ltm);
r = toku_lt_create(&lt, dbpanic, ltm,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
CKERR(r);
assert(lt);
init_query();
}
static void close_tree(void) {
r = toku_lt_unlock(lt, txn); CKERR(r);
assert(lt && ltm);
r = toku_lt_close(lt);
CKERR(r);
r = toku_ltm_close(ltm);
CKERR(r);
r = toku_lt_close(lt); CKERR(r);
r = toku_ltm_close(ltm); CKERR(r);
lt = NULL;
ltm = NULL;
}
......@@ -139,7 +134,7 @@ temporarily_fake_comparison_functions();
toku_lt_point_cmp(buf[i].ends.right, &right) == 0 &&
buf[i].data == find_txn) { goto cleanup; }
}
assert(FALSE); //Crash since we didn't find it.
assert(false); //Crash since we didn't find it.
cleanup:
stop_fake_comparison_functions();
}
......@@ -159,13 +154,11 @@ static void insert_1(int key_l, int key_r,
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, db, txn, key_left, key_right); CKERR(r);
close_tree();
setup_tree();
r = toku_lt_acquire_read_lock(lt, db, txn, key_left);
CKERR(r);
r = toku_lt_acquire_read_lock(lt, db, txn, key_left); CKERR(r);
close_tree();
}
......
......@@ -8,27 +8,11 @@ int main(int argc, const char *argv[]) {
int r;
parse_args(argc, argv);
/* ********************************************************************** */
rth = NULL;
for (failon = 1; failon <= 2; failon++) {
mallocced = 0;
r = toku_rth_create(&rth, fail_malloc, toku_free, toku_realloc);
CKERR2(r, ENOMEM);
assert(rth==NULL);
}
r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
CKERR(r);
assert(rth);
toku_rth_close(rth);
rth = NULL;
/* ********************************************************************** */
size_t i;
size_t iterations = 512 << 2;
r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
r = toku_rth_create(&rth);
CKERR(r);
assert(rth);
for (i = 1; i < iterations; i++) {
......@@ -50,7 +34,7 @@ int main(int argc, const char *argv[]) {
/* ********************************************************************** */
r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
r = toku_rth_create(&rth);
CKERR(r);
assert(rth);
for (i = 1; i < iterations; i++) {
......@@ -65,7 +49,7 @@ int main(int argc, const char *argv[]) {
/* ********************************************************************** */
r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
r = toku_rth_create(&rth);
CKERR(r);
assert(rth);
for (i = iterations - 1; i >= 1; i--) {
......@@ -75,19 +59,9 @@ int main(int argc, const char *argv[]) {
toku_rth_close(rth);
rth = NULL;
failon = 3;
mallocced = 0;
r = toku_rth_create(&rth, fail_malloc, toku_free, toku_realloc);
CKERR(r);
assert(rth);
r = toku_rth_insert(rth, (TXNID)1);
CKERR2(r, ENOMEM);
toku_rth_close(rth);
rth = NULL;
/* ********************************************************************** */
r = toku_rth_create(&rth, toku_malloc, toku_free, toku_realloc);
r = toku_rth_create(&rth);
CKERR(r);
assert(rth);
for (i = iterations - 1; i >= 1; i--) {
......
......@@ -36,14 +36,10 @@ static void init_query(void) {
static void setup_tree(void) {
assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
CKERR(r);
assert(ltm);
r = toku_lt_create(&lt, dbpanic, ltm,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
CKERR(r);
assert(lt);
init_query();
......@@ -71,7 +67,7 @@ static DBT* set_to_infty(DBT *dbt, int value) {
static void lt_insert(int r_expect, char txn, int key_l,
int key_r, BOOL read_flag) {
int key_r, bool read_flag) {
DBT _key_left;
DBT _key_right;
DBT* key_left = &_key_left;
......@@ -96,11 +92,11 @@ static void lt_insert(int r_expect, char txn, int key_l,
}
static void lt_insert_read(int r_expect, char txn, int key_l, int key_r) {
lt_insert(r_expect, txn, key_l, key_r, TRUE);
lt_insert(r_expect, txn, key_l, key_r, true);
}
static void lt_insert_write(int r_expect, char txn, int key_l) {
lt_insert(r_expect, txn, key_l, 0, FALSE);
lt_insert(r_expect, txn, key_l, 0, false);
}
......@@ -120,37 +116,45 @@ static void runtest(void) {
toku_lt_verify(lt, NULL);
lt_insert_write(0, 'b', 10);
toku_lt_verify(lt, NULL);
lt_unlock('a');
lt_unlock('b');
close_tree();
/* ********************* */
setup_tree();
lt_insert_write(0, 'a', 1);
lt_unlock('a');
close_tree();
/* ********************* */
setup_tree();
lt_insert_write(0, 'a', 2);
lt_insert_write(0, 'a', 1);
lt_unlock('a');
close_tree();
/* ********************* */
setup_tree();
lt_insert_write(0, 'a', 1);
lt_insert_write(0, 'a', 2);
lt_insert_write(0, 'a', 1);
lt_unlock('a');
close_tree();
/* ********************* */
setup_tree();
lt_insert_write(0, 'a', 1);
lt_insert_read (0, 'a', 1, 1);
lt_unlock('a');
close_tree();
/* ********************* */
setup_tree();
lt_insert_write(0, 'a', 1);
lt_insert_read (DB_LOCK_NOTGRANTED, 'b', 1, 1);
lt_unlock('a');
close_tree();
/* ********************* */
setup_tree();
lt_insert_read (0, 'b', 1, 1);
lt_insert_write(DB_LOCK_NOTGRANTED, 'a', 1);
lt_unlock('b');
close_tree();
/* ********************* */
setup_tree();
......@@ -160,6 +164,7 @@ static void runtest(void) {
lt_insert_write(0, 'a', 4);
lt_insert_write(0, 'a', 5);
lt_insert_read (DB_LOCK_NOTGRANTED, 'b', 2, 4);
lt_unlock('a');
close_tree();
/* ********************* */
setup_tree();
......@@ -169,6 +174,7 @@ static void runtest(void) {
lt_insert_write(0, 'a', 4);
lt_insert_write(0, 'a', 5);
lt_insert_write (DB_LOCK_NOTGRANTED, 'b', 2);
lt_unlock('a');
close_tree();
/* ********************* */
setup_tree();
......@@ -177,6 +183,8 @@ static void runtest(void) {
lt_insert_write(0, 'a', 4);
lt_insert_write(0, 'a', 5);
lt_insert_read (0, 'b', 3, 3);
lt_unlock('a');
lt_unlock('b');
close_tree();
/* ********************* */
setup_tree();
......@@ -185,6 +193,8 @@ static void runtest(void) {
lt_insert_write(0, 'a', 4);
lt_insert_write(0, 'a', 5);
lt_insert_read (0, 'b', 3, 3);
lt_unlock('a');
lt_unlock('b');
close_tree();
/* ********************* */
setup_tree();
......@@ -198,6 +208,8 @@ static void runtest(void) {
lt_insert_write(0, 'a', 8);
lt_insert_write(0, 'a', 9);
lt_insert_read (DB_LOCK_NOTGRANTED, 'a', 3, 7);
lt_unlock('a');
lt_unlock('b');
close_tree();
/* ********************* */
setup_tree();
......@@ -211,6 +223,7 @@ static void runtest(void) {
lt_insert_write(0, 'b', 8);
lt_insert_write(0, 'b', 9);
lt_insert_read (DB_LOCK_NOTGRANTED, 'a', 3, 7);
lt_unlock('b');
close_tree();
/* ********************* */
setup_tree();
......@@ -219,6 +232,7 @@ static void runtest(void) {
lt_insert_write(0, 'a', 3);
lt_insert_write(0, 'a', 4);
lt_insert_read (0, 'a', 3, 7);
lt_unlock('a');
close_tree();
/* ********************* */
setup_tree();
......@@ -227,6 +241,7 @@ static void runtest(void) {
lt_insert_write(0, 'b', 3);
lt_insert_write(0, 'b', 4);
lt_insert_read (DB_LOCK_NOTGRANTED, 'a', 3, 7);
lt_unlock('b');
close_tree();
/* ********************* */
setup_tree();
......@@ -235,6 +250,7 @@ static void runtest(void) {
lt_insert_write(0, 'a', 4);
lt_insert_write(0, 'a', 5);
lt_insert_write(0, 'a', 3);
lt_unlock('a');
close_tree();
/* ********************* */
setup_tree();
......@@ -243,6 +259,8 @@ static void runtest(void) {
lt_insert_write(0, 'b', 4);
lt_insert_write(0, 'b', 5);
lt_insert_write(0, 'a', 3);
lt_unlock('a');
lt_unlock('b');
close_tree();
/* ********************* */
setup_tree();
......@@ -256,6 +274,7 @@ static void runtest(void) {
lt_insert_read (DB_LOCK_NOTGRANTED, 'a', 3, 3);
lt_unlock('b');
lt_insert_read (0, 'a', 3, 3);
lt_unlock('a');
close_tree();
/* ********************* */
setup_tree();
......@@ -263,6 +282,7 @@ static void runtest(void) {
lt_insert_write(0, 'a', 3);
lt_insert_write(0, 'b', 2);
lt_unlock('b');
lt_unlock('a');
close_tree();
/* ********************* */
}
......
......@@ -8,15 +8,8 @@ int main(int argc, const char *argv[]) {
int r;
parse_args(argc, argv);
lth = NULL;
for (failon = 1; failon <= 2; failon++) {
mallocced = 0;
r = toku_lth_create(&lth, fail_malloc, toku_free, toku_realloc);
CKERR2(r, ENOMEM);
assert(lth==NULL);
}
r = toku_lth_create(&lth, toku_malloc, toku_free, toku_realloc);
r = toku_lth_create(&lth);
CKERR(r);
assert(lth);
toku_lth_close(lth);
......@@ -25,7 +18,7 @@ int main(int argc, const char *argv[]) {
size_t i;
size_t iterations = 512 << 2;
r = toku_lth_create(&lth, toku_malloc, toku_free, toku_realloc);
r = toku_lth_create(&lth);
CKERR(r);
assert(lth);
for (i = 1; i < iterations; i++) {
......@@ -54,7 +47,7 @@ int main(int argc, const char *argv[]) {
toku_lth_close(lth);
lth = NULL;
r = toku_lth_create(&lth, toku_malloc, toku_free, toku_realloc);
r = toku_lth_create(&lth);
CKERR(r);
assert(lth);
for (i = 1; i < iterations; i++) {
......@@ -68,7 +61,7 @@ int main(int argc, const char *argv[]) {
lth = NULL;
r = toku_lth_create(&lth, toku_malloc, toku_free, toku_realloc);
r = toku_lth_create(&lth);
CKERR(r);
assert(lth);
for (i = iterations - 1; i >= 1; i--) {
......@@ -78,14 +71,5 @@ int main(int argc, const char *argv[]) {
toku_lth_close(lth);
lth = NULL;
failon = 3;
mallocced = 0;
r = toku_lth_create(&lth, fail_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lth);
r = toku_lth_insert(lth, (toku_lock_tree*)1);
CKERR2(r, ENOMEM);
toku_lth_close(lth);
lth = NULL;
return 0;
}
......@@ -8,8 +8,8 @@ toku_ltm* ltm = NULL;
DB* db = (DB*)1;
enum { MAX_LT_LOCKS = 10 };
uint32_t max_locks = MAX_LT_LOCKS;
uint64_t max_lock_memory = MAX_LT_LOCKS*64;
BOOL duplicates = FALSE;
uint64_t max_lock_memory = MAX_LT_LOCKS*256;
bool duplicates = false;
int nums[10000];
DBT _keys_left[2];
......@@ -37,9 +37,7 @@ static void init_query(void) {
static void setup_tree(void) {
assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
CKERR(r);
assert(ltm);
//ask ltm for lock tree
......@@ -67,12 +65,12 @@ static DBT* set_to_infty(DBT *dbt, int value) {
if (value == infinite) return (DBT*)toku_lt_infinity;
if (value == neg_infinite) return (DBT*)toku_lt_neg_infinity;
if (value == null) return dbt_init(dbt, NULL, 0);
assert(value >= 0);
assert(0 <= value && (unsigned) value < sizeof nums / sizeof nums[0]);
return dbt_init(dbt, &nums[value], sizeof(nums[0]));
}
static void lt_insert(int r_expect, char txn, int key_l, int key_r, BOOL read_flag) {
static void lt_insert(int r_expect, char txn, int key_l, int key_r, bool read_flag) {
DBT _key_left;
DBT _key_right;
DBT* key_left = &_key_left;
......@@ -88,26 +86,29 @@ 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;
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, db, local_txn, key_left, key_right);
else
r = toku_lt_acquire_write_lock(lt, db, local_txn, key_left);
CKERR2(r, r_expect);
}
static int lt_insert_write_no_check(char txn, int key_p) {
DBT key;
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])));
return r;
}
static void lt_insert_read(int r_expect, char txn, int key_l, int key_r) {
lt_insert(r_expect, txn, key_l, key_r, TRUE);
lt_insert(r_expect, txn, key_l, key_r, true);
}
static void lt_insert_write(int r_expect, char txn, int key_l) {
lt_insert(r_expect, txn, key_l, 0, FALSE);
lt_insert(r_expect, txn, key_l, 0, false);
}
static void lt_unlock(char ctxn) {
int retval;
retval = toku_lt_unlock(lt, (TXNID) (size_t) ctxn);
CKERR(retval);
int retval = toku_lt_unlock(lt, (TXNID) (size_t) ctxn); CKERR(retval);
}
static void run_escalation_test(void) {
......@@ -120,6 +121,7 @@ static void run_escalation_test(void) {
lt_insert_write(0, 'a', i);
assert(lt->lock_escalation_allowed);
}
lt_unlock('a');
close_tree();
/* ******************** */
/* interleaving transactions,
......@@ -128,17 +130,19 @@ static void run_escalation_test(void) {
make sure lock escalation fails, and that we run out of locks */
setup_tree();
// this should grab ten locks successfully
for (i = 1; i < 10; i+=2) {
lt_insert_write(0, 'a', i);
lt_insert_write(0, 'b', i+1);
for (i = 1; i < 20; i++) {
r = lt_insert_write_no_check(i&1 ? 'a' : 'b', i);
if (r != 0)
break;
}
lt_insert_write(TOKUDB_OUT_OF_LOCKS, 'a', 100);
lt_insert_write(TOKUDB_OUT_OF_LOCKS, 'b', 100);
lt_insert_write(TOKUDB_OUT_OF_LOCKS, 'c', 100);
lt_unlock('a'); lt_unlock('b');
close_tree();
/* ******************** */
/*
test that escalation allowed flag goes from FALSE->TRUE->FALSE
test that escalation allowed flag goes from false->true->FALSE
TXN A grabs 1 3 5 7 9
TXN B grabs 2 4 6 8 10
try to grab another lock, fail, lock escalation should be disabled
......@@ -150,9 +154,10 @@ static void run_escalation_test(void) {
setup_tree();
assert(lt->lock_escalation_allowed);
// this should grab ten locks successfully
for (i = 1; i < 10; i+=2) {
lt_insert_write(0, 'a', i);
lt_insert_write(0, 'b', i+1);
for (i = 1; i < 20; i++) {
r = lt_insert_write_no_check(i&1 ? 'a' : 'b', i);
if (r != 0)
break;
}
assert(lt->lock_escalation_allowed);
lt_insert_write(TOKUDB_OUT_OF_LOCKS, 'a', 100);
......@@ -167,6 +172,7 @@ static void run_escalation_test(void) {
lt_insert_write(0, 'c', i);
assert(lt->lock_escalation_allowed);
}
lt_unlock('a'); lt_unlock('c');
close_tree();
/* ******************** */
/*
......@@ -196,6 +202,7 @@ static void run_escalation_test(void) {
lt_insert_write(0, 'c', i);
assert(lt->lock_escalation_allowed);
}
lt_unlock('a'); lt_unlock('c');
close_tree();
/* ******************** */
#if 0 //Only use when messy transactions are enabled.
......@@ -234,6 +241,7 @@ static void run_escalation_test(void) {
lt_insert_write(0, 'a', i);
}
lt_insert_read(0, 'a', 10, 10);
lt_unlock('a');
close_tree();
/* ******************** */
/* escalate on read lock of different transaction. */
......@@ -242,6 +250,7 @@ static void run_escalation_test(void) {
lt_insert_write(0, 'a', i);
}
lt_insert_read(0, 'b', 10, 10);
lt_unlock('a'); lt_unlock('b');
close_tree();
/* ******************** */
/* txn A grabs write lock 0,9
......@@ -257,6 +266,7 @@ static void run_escalation_test(void) {
lt_insert_write(0, 'b', i);
assert(lt->lock_escalation_allowed);
}
lt_unlock('a'); lt_unlock('b');
close_tree();
/* ******************** */
/* [1-A-5] [10-B-15] [20-A-25] BORDER WRITE
......@@ -280,6 +290,7 @@ static void run_escalation_test(void) {
lt_insert_write(DB_LOCK_NOTGRANTED, 'b', 24);
lt_insert_write(0, 'a', 14);
lt_insert_write(0, 'b', 4);
lt_unlock('a'); lt_unlock('b');
close_tree();
/* ******************** */
/* Test read lock escalation, no writes. */
......@@ -288,6 +299,7 @@ static void run_escalation_test(void) {
for (i = 0; i < 1000; i ++) {
lt_insert_read (0, 'b', i, i);
}
lt_unlock('b');
close_tree();
/* ******************** */
/* Test read lock escalation, writes of same kind. */
......@@ -298,6 +310,7 @@ static void run_escalation_test(void) {
for (i = 0; i < 1000; i ++) {
lt_insert_read (0, 'b', i, i);
}
lt_unlock('b');
close_tree();
/* ******************** */
/* Test read lock escalation, writes of other kind. */
......@@ -312,6 +325,7 @@ static void run_escalation_test(void) {
if (i % 5 == 0) { continue; }
lt_insert_read (0, 'a', i, i);
}
lt_unlock('a'); lt_unlock('b'); lt_unlock('c');
close_tree();
/* ******************** */
/*
......@@ -320,7 +334,7 @@ static void run_escalation_test(void) {
txn C attempts to grab lock, escalation, and lock grab, should fail
lock
*/
/*
#if 0
setup_tree();
assert(lt->lock_escalation_allowed);
// this should grab ten locks successfully
......@@ -346,7 +360,7 @@ static void run_escalation_test(void) {
assert(lt->lock_escalation_allowed);
}
close_tree();
*/
#endif
/* ******************** */
}
......
......@@ -17,9 +17,7 @@ int nums[10000];
static void setup_ltm(void) {
assert(!ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
CKERR(r);
assert(ltm);
}
......
......@@ -20,9 +20,7 @@ int nums[10000];
static void setup_ltm(void) {
assert(!ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
CKERR(r);
assert(ltm);
}
......
......@@ -36,14 +36,10 @@ static void init_query(void) {
static void setup_tree(void) {
assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
CKERR(r);
assert(ltm);
r = toku_lt_create(&lt, dbpanic, ltm,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
CKERR(r);
assert(lt);
init_query();
......@@ -90,6 +86,10 @@ static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r)
lt_verify();
}
static void lt_unlock(TXNID txnid) {
r= toku_lt_unlock(lt, txnid); CKERR(r);
}
static void runtest(void) {
setup_tree();
lt_insert_write_range(0, 'a', 5, 15);
......@@ -98,6 +98,7 @@ static void runtest(void) {
lt_insert_write_range(DB_LOCK_NOTGRANTED, 'b', k, k);
for (int k = 5; k <= 20; k++)
lt_insert_write_range(0, 'a', k, k);
lt_unlock('a');
close_tree();
setup_tree();
......@@ -107,6 +108,7 @@ static void runtest(void) {
lt_insert_write_range(DB_LOCK_NOTGRANTED, 'b', k, k);
for (int k = 5; k <= 20; k++)
lt_insert_write_range(0, 'a', k, k);
lt_unlock('a');
close_tree();
setup_tree();
......@@ -115,18 +117,21 @@ static void runtest(void) {
lt_insert_write_range(0, 'a', k, k);
for (int k = 10; k <= 20; k++)
lt_insert_write_range(DB_LOCK_NOTGRANTED, 'b', k, k);
lt_unlock('a');
close_tree();
setup_tree();
lt_insert_write_range(0, 'a', 5, 10);
lt_insert_write_range(0, 'a', 20, 30);
lt_insert_write_range(0, 'a', 1, 8);
lt_unlock('a');
close_tree();
setup_tree();
lt_insert_write_range(0, 'a', 5, 10);
lt_insert_write_range(0, 'a', 20, 30);
lt_insert_write_range(0, 'a', 25, 35);
lt_unlock('a');
close_tree();
}
......
......@@ -43,11 +43,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
DBT key_l; dbt_init(&key_l, "L", 1);
......
......@@ -43,11 +43,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
DBT key_l; dbt_init(&key_l, "L", 1);
......
......@@ -33,11 +33,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -33,11 +33,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
DBT key_l; dbt_init(&key_l, "L", 1);
......
......@@ -33,11 +33,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
DBT key_l; dbt_init(&key_l, "L", 1);
......
......@@ -50,11 +50,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -30,7 +30,7 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
uint64_t target_wait_time, the_wait_time;
......
......@@ -3,7 +3,18 @@
//
// example: ./benchmark_point_write_locks.tlog --max_locks 1000000 --max_lock_memory 1000000000 --nrows 1000000
#define TOKU_ALLOW_DEPRECATED
#include <malloc.h>
#include "test.h"
#include <byteswap.h>
static uint64_t htonl64(uint64_t x) {
#if BYTE_ORDER == LITTLE_ENDIAN
return bswap_64(x);
#else
#error
#endif
}
struct my_ltm_status {
uint32_t max_locks, curr_locks;
......@@ -15,12 +26,32 @@ static void my_ltm_get_status(toku_ltm *ltm, struct my_ltm_status *my_status) {
toku_ltm_get_status(ltm, &my_status->max_locks, &my_status->curr_locks, &my_status->max_lock_memory, &my_status->curr_lock_memory, &my_status->status);
}
static void *my_malloc(size_t s) {
void * p = malloc(s);
if (verbose)
printf("%s %lu %lu\n", __FUNCTION__, s, malloc_usable_size(p));
return p;
}
static void *my_realloc(void *p, size_t s) {
if (verbose)
printf("%s %p %lu\n", __FUNCTION__, p, s);
return realloc(p, s);
}
static void my_free(void *p) {
if (verbose)
printf("%s %p %lu\n", __FUNCTION__, p, malloc_usable_size(p));
free(p);
}
int main(int argc, const char *argv[]) {
int r;
uint32_t max_locks = 2;
uint64_t max_lock_memory = 4096;
uint64_t nrows = 1;
bool do_malloc_trace = false;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
......@@ -43,12 +74,22 @@ int main(int argc, const char *argv[]) {
nrows = atoi(argv[++i]);
continue;
}
if (strcmp(argv[i], "--malloc") == 0) {
do_malloc_trace = true;
continue;
}
assert(0);
}
if (do_malloc_trace) {
toku_set_func_malloc(my_malloc);
toku_set_func_free(my_free);
toku_set_func_realloc(my_realloc);
}
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
struct my_ltm_status s;
......@@ -59,14 +100,15 @@ int main(int argc, const char *argv[]) {
assert(s.curr_lock_memory == 0);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
DB *db_a = (DB *) 2;
TXNID txn_a = 1;
// acquire the locks on keys 1 .. nrows
for (uint64_t k = 1; k <= nrows; k++) {
for (uint64_t i = 1; i <= nrows; i++) {
uint64_t k = htonl64(i);
DBT key = { .data = &k, .size = sizeof k };
r = toku_lt_acquire_write_lock(lt, db_a, txn_a, &key);
if (r != 0) {
......@@ -77,12 +119,12 @@ int main(int argc, const char *argv[]) {
struct my_ltm_status t;
my_ltm_get_status(ltm, &t);
assert(t.max_locks == max_locks);
assert(t.curr_locks == k);
assert(t.curr_locks == i);
assert(t.max_lock_memory == max_lock_memory);
assert(t.curr_lock_memory > s.curr_lock_memory);
if (verbose)
printf("%"PRIu64" %"PRIu64"\n", k, t.curr_lock_memory);
printf("%"PRIu64" %"PRIu64"\n", i, t.curr_lock_memory - s.curr_lock_memory);
s = t;
}
......@@ -91,6 +133,9 @@ int main(int argc, const char *argv[]) {
// release the locks
r = toku_lt_unlock(lt, txn_a); assert(r == 0);
my_ltm_get_status(ltm, &s);
assert(s.curr_locks == 0);
// shutdown
r = toku_lt_close(lt); assert(r == 0);
r = toku_ltm_close(ltm); assert(r == 0);
......
// benchmark point write locks acquisition rate.
// rate = nrows / time to execute the benchmark.
//
// example: ./benchmark_point_write_locks.tlog --max_locks 1000000 --max_lock_memory 1000000000 --nrows 1000000
#define TOKU_ALLOW_DEPRECATED
#include <malloc.h>
#include "test.h"
#include <byteswap.h>
static uint64_t htonl64(uint64_t x) {
#if BYTE_ORDER == LITTLE_ENDIAN
return bswap_64(x);
#else
#error
#endif
}
struct my_ltm_status {
uint32_t max_locks, curr_locks;
uint64_t max_lock_memory, curr_lock_memory;
LTM_STATUS_S status;
};
static void my_ltm_get_status(toku_ltm *ltm, struct my_ltm_status *my_status) {
toku_ltm_get_status(ltm, &my_status->max_locks, &my_status->curr_locks, &my_status->max_lock_memory, &my_status->curr_lock_memory, &my_status->status);
}
static void *my_malloc(size_t s) {
void * p = malloc(s);
if (verbose)
printf("%s %lu %lu\n", __FUNCTION__, s, malloc_usable_size(p));
return p;
}
static void *my_realloc(void *p, size_t s) {
if (verbose)
printf("%s %p %lu\n", __FUNCTION__, p, s);
return realloc(p, s);
}
static void my_free(void *p) {
if (verbose)
printf("%s %p %lu\n", __FUNCTION__, p, malloc_usable_size(p));
free(p);
}
int main(int argc, const char *argv[]) {
int r;
uint32_t max_locks = 2;
uint64_t max_lock_memory = 4096;
uint64_t nrows = 1;
bool do_malloc_trace = false;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
verbose++;
continue;
}
if (strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quiet") == 0) {
if (verbose > 0) verbose--;
continue;
}
if (strcmp(argv[i], "--max_locks") == 0 && i+1 < argc) {
max_locks = atoi(argv[++i]);
continue;
}
if (strcmp(argv[i], "--max_lock_memory") == 0 && i+1 < argc) {
max_lock_memory = atoi(argv[++i]);
continue;
}
if (strcmp(argv[i], "--nrows") == 0 && i+1 < argc) {
nrows = atoi(argv[++i]);
continue;
}
if (strcmp(argv[i], "--malloc") == 0) {
do_malloc_trace = true;
continue;
}
assert(0);
}
if (do_malloc_trace) {
toku_set_func_malloc(my_malloc);
toku_set_func_free(my_free);
toku_set_func_realloc(my_realloc);
}
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
struct my_ltm_status s;
my_ltm_get_status(ltm, &s);
assert(s.max_locks == max_locks);
assert(s.curr_locks == 0);
assert(s.max_lock_memory == max_lock_memory);
assert(s.curr_lock_memory == 0);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
DB *db_a = (DB *) 2;
TXNID txn_a = 1;
// acquire the locks on keys 1 .. nrows
for (uint64_t i = 1; i <= nrows; i++) {
uint64_t k_left = htonl64(2*i);
uint64_t k_right = htonl64(2*i+1);
DBT key_left = { .data = &k_left, .size = sizeof k_left };
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);
if (r != 0) {
assert(r == TOKUDB_OUT_OF_LOCKS);
break;
}
struct my_ltm_status t;
my_ltm_get_status(ltm, &t);
assert(t.max_locks == max_locks);
assert(t.curr_locks == i);
assert(t.max_lock_memory == max_lock_memory);
assert(t.curr_lock_memory > s.curr_lock_memory);
if (verbose)
printf("%"PRIu64" %"PRIu64"\n", i, t.curr_lock_memory - s.curr_lock_memory);
s = t;
}
// release the locks
r = toku_lt_unlock(lt, txn_a); assert(r == 0);
my_ltm_get_status(ltm, &s);
assert(s.curr_locks == 0);
// shutdown
r = toku_lt_close(lt); assert(r == 0);
r = toku_ltm_close(ltm); assert(r == 0);
return 0;
}
......@@ -36,14 +36,10 @@ static void init_query(void) {
static void setup_tree(void) {
assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
CKERR(r);
assert(ltm);
r = toku_lt_create(&lt, dbpanic, ltm,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
CKERR(r);
assert(lt);
init_query();
......@@ -106,45 +102,57 @@ static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r)
lt_verify();
}
static void lt_unlock(TXNID txnid) {
r = toku_lt_unlock(lt, txnid); CKERR(r);
}
static void runtest(void) {
setup_tree();
lt_insert_write_range(0, 'a', neg_infinite, infinite);
lt_unlock('a');
close_tree();
setup_tree();
lt_insert_read_range(0, 'a', 1, 2);
lt_insert_write_range(0, 'a', neg_infinite, infinite);
lt_unlock('a');
close_tree();
setup_tree();
lt_insert_write_range(0, 'a', 1, 2);
lt_insert_write_range(0, 'a', neg_infinite, infinite);
lt_unlock('a');
close_tree();
setup_tree();
lt_insert_read_range(0, 'b', 1, 2);
lt_insert_write_range(DB_LOCK_NOTGRANTED, 'a', neg_infinite, infinite);
lt_unlock('b');
close_tree();
setup_tree();
lt_insert_write_range(0, 'b', 1, 2);
lt_insert_write_range(DB_LOCK_NOTGRANTED, 'a', neg_infinite, infinite);
lt_unlock('b');
close_tree();
setup_tree();
lt_insert_write_range(0, 'a', neg_infinite, infinite);
lt_insert_write_range(0, 'a', neg_infinite, infinite);
lt_unlock('a');
close_tree();
setup_tree();
lt_insert_write_range(0, 'a', neg_infinite, infinite);
lt_insert_write_range(DB_LOCK_NOTGRANTED, 'b', neg_infinite, infinite);
lt_unlock('a');
close_tree();
setup_tree();
lt_insert_write_range(0, 'a', neg_infinite, infinite);
lt_insert_read_range(0, 'a', 1, 2);
lt_insert_read_range(DB_LOCK_NOTGRANTED, 'b', 10, 20);
lt_unlock('a');
close_tree();
}
......
......@@ -50,11 +50,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -22,9 +22,7 @@ int main(int argc, const char *argv[]) {
int r;
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, MAX_LOCKS, MAX_LOCK_MEMORY, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, MAX_LOCKS, MAX_LOCK_MEMORY, dbpanic, get_compare_fun_from_db);
CKERR(r);
do_ltm_status(ltm);
#if 0
......
......@@ -49,11 +49,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -38,11 +38,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -37,11 +37,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -36,7 +36,7 @@ main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_ltm_set_lock_wait_time(ltm, 5000);
......@@ -45,7 +45,7 @@ main(int argc, const char *argv[]) {
toku_ltm_set_mutex(ltm, &my_mutex);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -54,14 +54,14 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_pthread_mutex_t my_mutex = TOKU_PTHREAD_MUTEX_INITIALIZER;
toku_ltm_set_mutex(ltm, &my_mutex);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -36,11 +36,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -36,11 +36,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -36,11 +36,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -65,11 +65,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -40,11 +40,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -36,14 +36,10 @@ static void init_query(void) {
static void setup_tree(void) {
assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
CKERR(r);
assert(ltm);
r = toku_lt_create(&lt, dbpanic, ltm,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
CKERR(r);
assert(lt);
init_query();
......@@ -75,7 +71,7 @@ static DBT* set_to_infty(DBT *dbt, int value) {
}
static void lt_insert(int r_expect, char txn, int key_l,
int key_r, BOOL read_flag) {
int key_r, bool read_flag) {
DBT _key_left;
DBT _key_right;
DBT* key_left = &_key_left;
......@@ -102,12 +98,12 @@ static void lt_insert(int r_expect, char txn, int key_l,
static void lt_insert_read(int r_expect, char txn, int key_l, int key_r) UU();
static void lt_insert_read(int r_expect, char txn, int key_l, int key_r) {
lt_insert(r_expect, txn, key_l, key_r, TRUE);
lt_insert(r_expect, txn, key_l, key_r, true);
}
static void lt_insert_write(int r_expect, char txn, int key_l) UU();
static void lt_insert_write(int r_expect, char txn, int key_l) {
lt_insert(r_expect, txn, key_l, 0, FALSE);
lt_insert(r_expect, txn, key_l, 0, false);
}
static void lt_insert_write_range(int r_expect, char txn, int key_l, int key_r) {
......@@ -141,30 +137,35 @@ static void runtest(void) {
lt_insert_write_range(0, 'a', 30, 40);
lt_insert_write(0, 'a', 25);
lt_insert_write(0, 'a', 50);
lt_unlock('a');
close_tree();
// no overlaps (reverse)
setup_tree();
lt_insert_write_range(0, 'a', 30, 40);
lt_insert_write_range(0, 'a', 10, 20);
lt_unlock('a');
close_tree();
// overlaps
setup_tree();
lt_insert_write_range(0, 'a', 5, 15);
lt_insert_write_range(0, 'a', 10, 20);
lt_unlock('a');
close_tree();
setup_tree();
lt_insert_write_range(0, 'a', 5, 15);
lt_insert_write_range(0, 'a', 30, 40);
lt_insert_write_range(0, 'a', 10, 20);
lt_unlock('a');
close_tree();
// overlaps (reverse)
setup_tree();
lt_insert_write_range(0, 'a', 10, 20);
lt_insert_write_range(0, 'a', 5, 15);
lt_unlock('a');
close_tree();
// test borderwrite split
......@@ -173,6 +174,8 @@ static void runtest(void) {
lt_insert_write_range(0, 'a', 5, 6);
lt_insert_write_range(0, 'a', 20, 30);
lt_insert_write_range(0, 'b', 10, 10);
lt_unlock('a');
lt_unlock('b');
close_tree();
// test borderwrite split
......@@ -180,38 +183,46 @@ static void runtest(void) {
lt_insert_write_range(0, 'a', 0, 5);
lt_insert_write_range(0, 'a', 20, 30);
lt_insert_write_range(0, 'b', 10, 10);
lt_unlock('a');
lt_unlock('b');
close_tree();
setup_tree();
lt_insert_write_range(0, 'a', 15, 20);
lt_insert_write_range(0, 'a', 10, 30);
lt_unlock('a');
close_tree();
setup_tree();
lt_insert_write_range(0, 'a', 10, 30);
lt_insert_write_range(0, 'a', 15, 20);
lt_unlock('a');
close_tree();
setup_tree();
lt_insert_write_range(0, 'b', 70, 80);
lt_insert_write_range(0, 'b', 60, 70);
lt_insert_write_range(0, 'b', 80, 90);
lt_unlock('b');
close_tree();
setup_tree();
lt_insert_write(0, 'a', 5);
lt_insert_write_range(0, 'a', 1, 20);
lt_unlock('a');
close_tree();
setup_tree();
lt_insert_write(0, 'a', 5);
lt_insert_write(0, 'a', 10);
lt_unlock('a');
close_tree();
setup_tree();
lt_insert_write(0, 'a', 5);
lt_insert_write(0, 'a', 10);
lt_insert_write_range(0, 'a', 1, 20);
lt_unlock('a');
close_tree();
}
......
......@@ -36,14 +36,10 @@ static void init_query(void) {
static void setup_tree(void) {
assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
CKERR(r);
assert(ltm);
r = toku_lt_create(&lt, dbpanic, ltm,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
CKERR(r);
assert(lt);
init_query();
......@@ -113,6 +109,8 @@ static void runtest(void) {
setup_tree();
lt_insert_read_range(0, 'a', 1, 50);
lt_insert_write_range(0, 'b', 51, 99);
lt_unlock('a');
lt_unlock('b');
close_tree();
setup_tree();
......@@ -124,6 +122,8 @@ static void runtest(void) {
lt_insert_write_range(DB_LOCK_NOTGRANTED, 'b', 10, 11);
lt_insert_write_range(DB_LOCK_NOTGRANTED, 'b', 55, 56);
lt_insert_write_range(DB_LOCK_NOTGRANTED, 'b', 55, 65);
lt_unlock('a');
lt_unlock('b');
close_tree();
}
......
......@@ -36,14 +36,10 @@ static void init_query(void) {
static void setup_tree(void) {
assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
CKERR(r);
assert(ltm);
r = toku_lt_create(&lt, dbpanic, ltm,
get_compare_fun_from_db,
toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
CKERR(r);
assert(lt);
init_query();
......@@ -114,6 +110,8 @@ static void runtest(void) {
setup_tree();
lt_insert_write_range(0, 'a', 1, 50);
lt_insert_write_range(0, 'b', 51, 99);
lt_unlock('a');
lt_unlock('b');
close_tree();
setup_tree();
......@@ -123,6 +121,8 @@ static void runtest(void) {
lt_insert_write_range(0, 'b', 80, 90);
lt_insert_write_range(DB_LOCK_NOTGRANTED, 'b', 50, 60);
lt_insert_write_range(DB_LOCK_NOTGRANTED, 'b', 50, 50);
lt_unlock('a');
lt_unlock('b');
close_tree();
}
......
......@@ -34,11 +34,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
......@@ -33,11 +33,11 @@ int main(int argc, const char *argv[]) {
// setup
toku_ltm *ltm = NULL;
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_ltm_create(&ltm, max_locks, max_lock_memory, dbpanic, get_compare_fun_from_db);
assert(r == 0 && ltm);
toku_lock_tree *lt = NULL;
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db, toku_malloc, toku_free, toku_realloc);
r = toku_lt_create(&lt, dbpanic, ltm, get_compare_fun_from_db);
assert(r == 0 && lt);
const TXNID txn_a = 1;
......
This diff is collapsed.
......@@ -12,6 +12,7 @@
//Currently this is a stub implementation just so we can write and compile tests
//before actually implementing the range tree.
#include "memory.h"
#include <rangetree.h>
#include <errno.h>
#include <toku_assert.h>
......@@ -31,39 +32,42 @@ int
toku_rt_create(toku_range_tree** ptree,
int (*end_cmp)(const toku_point*,const toku_point*),
int (*data_cmp)(const TXNID,const TXNID),
BOOL allow_overlaps,
void* (*user_malloc) (size_t),
void (*user_free) (void*),
void* (*user_realloc)(void*, size_t)) {
bool allow_overlaps,
void (*incr_memory_size)(void *extra_memory_size, size_t s),
void (*decr_memory_size)(void *extra_memory_size, size_t s),
void *extra_memory_size) {
int r = ENOSYS;
toku_range_tree* temptree = NULL;
toku_range_tree* tmptree = NULL;
if (allow_overlaps)
return EINVAL;
r = toku_rt_super_create(ptree, &temptree, end_cmp, data_cmp, allow_overlaps,
user_malloc, user_free, user_realloc);
r = toku_rt_super_create(ptree, &tmptree, end_cmp, data_cmp, allow_overlaps, incr_memory_size, decr_memory_size, extra_memory_size);
if (r != 0)
goto cleanup;
//Any local initializers go here.
r = toku_omt_create(&temptree->i.omt);
r = toku_omt_create(&tmptree->i.omt);
if (r != 0)
goto cleanup;
*ptree = temptree;
tmptree->incr_memory_size(tmptree->extra_memory_size, toku_rt_memory_size(tmptree));
*ptree = tmptree;
r = 0;
cleanup:
if (r != 0) {
if (temptree)
user_free(temptree);
if (tmptree)
toku_free(tmptree);
}
return r;
}
static int
rt_clear_helper(OMTVALUE value, u_int32_t UU(index), void* extra) {
void (*user_free)(void*) = (void(*)(void*))extra;
user_free(value);
toku_range_tree *tree = (toku_range_tree *) extra;
size_t s = toku_malloc_usable_size(value);
tree->decr_memory_size(tree->extra_memory_size, s);
toku_free(value);
return 0;
}
......@@ -71,20 +75,24 @@ int
toku_rt_close(toku_range_tree* tree) {
if (!tree)
return EINVAL;
int r = toku_omt_iterate(tree->i.omt, rt_clear_helper, tree->free);
int r = toku_omt_iterate(tree->i.omt, rt_clear_helper, tree);
assert_zero(r);
tree->decr_memory_size(tree->extra_memory_size, toku_rt_memory_size(tree));
toku_omt_destroy(&tree->i.omt);
tree->free(tree);
toku_free(tree);
return 0;
}
void
toku_rt_clear(toku_range_tree* tree) {
assert(tree);
int r = toku_omt_iterate(tree->i.omt, rt_clear_helper, tree->free);
int r = toku_omt_iterate(tree->i.omt, rt_clear_helper, tree);
assert_zero(r);
size_t start_size = toku_omt_memory_size(tree->i.omt);;
toku_omt_clear(tree->i.omt);
tree->numelements = 0;
size_t end_size = toku_omt_memory_size(tree->i.omt);
assert(start_size >= end_size);
tree->decr_memory_size(tree->extra_memory_size, start_size - end_size);
}
typedef struct {
......@@ -204,17 +212,24 @@ toku_rt_insert(toku_range_tree* tree, toku_range* range) {
r = EDOM; goto cleanup;
}
assert(r == DB_NOTFOUND);
insert_range = tree->malloc(sizeof(*insert_range));
insert_range = toku_xmalloc(sizeof *insert_range);
*insert_range = *range;
size_t start_omt_size = toku_omt_memory_size(tree->i.omt);
static int count = 0;
count++;
r = toku_omt_insert_at(tree->i.omt, insert_range, index);
assert_zero(r);
tree->numelements++;
size_t end_omt_size = toku_omt_memory_size(tree->i.omt);
if (end_omt_size >= start_omt_size)
tree->incr_memory_size(tree->extra_memory_size, end_omt_size - start_omt_size);
else
tree->decr_memory_size(tree->extra_memory_size, start_omt_size - end_omt_size);
tree->incr_memory_size(tree->extra_memory_size, toku_malloc_usable_size(insert_range));
r = 0;
cleanup:
if (r != 0) {
if (insert_range)
tree->free(insert_range);
toku_free(insert_range);
}
return r;
}
......@@ -245,11 +260,16 @@ toku_rt_delete(toku_range_tree* tree, toku_range* range) {
r = EDOM;
goto cleanup;
}
size_t start_omt_size = toku_omt_memory_size(tree->i.omt);
r = toku_omt_delete_at(tree->i.omt, index);
assert_zero(r);
tree->free(data);
tree->numelements--;
size_t end_omt_size = toku_omt_memory_size(tree->i.omt);
if (start_omt_size >= end_omt_size)
tree->decr_memory_size(tree->extra_memory_size, start_omt_size - end_omt_size);
else
tree->incr_memory_size(tree->extra_memory_size, end_omt_size - start_omt_size);
tree->decr_memory_size(tree->extra_memory_size, toku_malloc_usable_size(data));
toku_free(data);
r = 0;
cleanup:
return r;
......@@ -257,7 +277,7 @@ cleanup:
static inline int
rt_neightbor(toku_range_tree* tree, toku_point* point,
toku_range* neighbor, BOOL* wasfound, int direction) {
toku_range* neighbor, bool* wasfound, int direction) {
int r = ENOSYS;
if (!tree || !point || !neighbor || !wasfound || tree->allow_overlaps) {
r = EINVAL; goto cleanup;
......@@ -272,14 +292,14 @@ rt_neightbor(toku_range_tree* tree, toku_point* point,
assert(direction==1 || direction==-1);
r = toku_omt_find(tree->i.omt, rt_heaviside, &extra, direction, &value, &index);
if (r == DB_NOTFOUND) {
*wasfound = FALSE;
*wasfound = false;
r = 0;
goto cleanup;
}
assert_zero(r);
assert(value);
toku_range* data = value;
*wasfound = TRUE;
*wasfound = true;
*neighbor = *data;
r = 0;
cleanup:
......@@ -287,17 +307,17 @@ cleanup:
}
int
toku_rt_predecessor (toku_range_tree* tree, toku_point* point, toku_range* pred, BOOL* wasfound) {
toku_rt_predecessor (toku_range_tree* tree, toku_point* point, toku_range* pred, bool* wasfound) {
return rt_neightbor(tree, point, pred, wasfound, -1);
}
int
toku_rt_successor (toku_range_tree* tree, toku_point* point, toku_range* succ, BOOL* wasfound) {
toku_rt_successor (toku_range_tree* tree, toku_point* point, toku_range* succ, bool* wasfound) {
return rt_neightbor(tree, point, succ, wasfound, 1);
}
int
toku_rt_get_allow_overlaps(toku_range_tree* tree, BOOL* allowed) {
toku_rt_get_allow_overlaps(toku_range_tree* tree, bool* allowed) {
if (!tree || !allowed)
return EINVAL;
assert(!tree->allow_overlaps);
......@@ -305,12 +325,9 @@ toku_rt_get_allow_overlaps(toku_range_tree* tree, BOOL* allowed) {
return 0;
}
int
toku_rt_get_size(toku_range_tree* tree, u_int32_t* size) {
if (!tree || !size)
return EINVAL;
*size = tree->numelements;
return 0;
size_t
toku_rt_get_size(toku_range_tree* tree) {
return toku_omt_size(tree->i.omt);
}
typedef struct {
......@@ -332,21 +349,22 @@ toku_rt_iterate(toku_range_tree* tree, int (*f)(toku_range*,void*), void* extra)
return toku_omt_iterate(tree->i.omt, rt_iterate_helper, &info);
}
static inline BOOL
static inline bool
toku__rt_overlap(toku_range_tree* tree, toku_interval* a, toku_interval* b) {
assert(tree);
assert(a);
assert(b);
//a->left <= b->right && b->left <= a->right
return (BOOL)((tree->end_cmp(a->left, b->right) <= 0) &&
(tree->end_cmp(b->left, a->right) <= 0));
return ((tree->end_cmp(a->left, b->right) <= 0) &&
(tree->end_cmp(b->left, a->right) <= 0));
}
void
toku_rt_verify(toku_range_tree *tree) {
int r;
if (!tree->allow_overlaps) {
for (u_int32_t i = 0; i < tree->numelements; i++) {
u_int32_t numelements = toku_omt_size(tree->i.omt);
for (u_int32_t i = 0; i < numelements; i++) {
// assert left <= right
OMTVALUE omtv;
r = toku_omt_fetch(tree->i.omt, i, &omtv);
......@@ -354,7 +372,7 @@ toku_rt_verify(toku_range_tree *tree) {
toku_range *v = (toku_range *) omtv;
assert(tree->end_cmp(v->ends.left, v->ends.right) <= 0);
// assert ranges are sorted
if (i < tree->numelements-1) {
if (i < numelements-1) {
OMTVALUE omtvnext;
r = toku_omt_fetch(tree->i.omt, i+1, &omtvnext);
assert_zero(r);
......@@ -363,7 +381,7 @@ toku_rt_verify(toku_range_tree *tree) {
}
}
// verify no overlaps
for (u_int32_t i = 1; i < tree->numelements; i++) {
for (u_int32_t i = 1; i < numelements; i++) {
OMTVALUE omtvprev;
r = toku_omt_fetch(tree->i.omt, i-1, &omtvprev);
assert_zero(r);
......@@ -376,3 +394,8 @@ toku_rt_verify(toku_range_tree *tree) {
}
}
}
size_t
toku_rt_memory_size(toku_range_tree *tree) {
return sizeof (toku_range_tree) + toku_omt_memory_size(tree->i.omt);
}
......@@ -25,17 +25,12 @@ struct __toku_range_tree {
with a range */
int (*data_cmp)(const TXNID,const TXNID);
/** Whether this tree allows ranges to overlap */
BOOL allow_overlaps;
/** The number of ranges in the range tree */
u_int32_t numelements;
/** The user malloc function */
void* (*malloc) (size_t);
/** The user free function */
void (*free) (void*);
/** The user realloc function */
void* (*realloc)(void*, size_t);
bool allow_overlaps;
toku_range_tree_local i;
void (*incr_memory_size)(void *extra_memory_size, size_t s);
void (*decr_memory_size)(void *extra_memory_size, size_t s);
void *extra_memory_size;
};
/*
......@@ -53,7 +48,7 @@ static inline int toku__rt_p_cmp(toku_range_tree* tree,
return 0;
}
static inline int toku__rt_increase_buffer(toku_range_tree* tree, toku_range** buf,
static inline int toku__rt_increase_buffer(toku_range_tree* tree UU(), toku_range** buf,
u_int32_t* buflen, u_int32_t num) {
assert(buf);
//TODO: SOME ATTRIBUTE TO REMOVE NEVER EXECUTABLE ERROR: assert(buflen);
......@@ -63,7 +58,7 @@ static inline int toku__rt_increase_buffer(toku_range_tree* tree, toku_range** b
temp_len = 1;
while (temp_len < num)
temp_len *= 2;
toku_range* temp_buf = tree->realloc(*buf, temp_len * sizeof(toku_range));
toku_range* temp_buf = toku_realloc(*buf, temp_len * sizeof(toku_range));
if (!temp_buf)
return errno;
*buf = temp_buf;
......@@ -72,31 +67,31 @@ static inline int toku__rt_increase_buffer(toku_range_tree* tree, toku_range** b
return 0;
}
static inline int toku_rt_super_create(toku_range_tree** upperptree,
toku_range_tree** ptree,
int (*end_cmp)(const toku_point*,const toku_point*),
int (*data_cmp)(const TXNID,const TXNID),
BOOL allow_overlaps,
void* (*user_malloc) (size_t),
void (*user_free) (void*),
void* (*user_realloc)(void*, size_t)) {
static inline int
toku_rt_super_create(toku_range_tree** upperptree,
toku_range_tree** ptree,
int (*end_cmp)(const toku_point*,const toku_point*),
int (*data_cmp)(const TXNID,const TXNID),
bool allow_overlaps,
void (*incr_memory_size)(void *extra_memory_size, size_t s),
void (*decr_memory_size)(void *extra_memory_size, size_t s),
void *extra_memory_size) {
toku_range_tree* temptree;
if (!upperptree || !ptree || !end_cmp || !data_cmp ||
!user_malloc || !user_free || !user_realloc)
if (!upperptree || !ptree || !end_cmp || !data_cmp)
return EINVAL;
temptree = (toku_range_tree*)user_malloc(sizeof(toku_range_tree));
temptree = (toku_range_tree*) toku_malloc(sizeof(toku_range_tree));
if (!temptree)
return ENOMEM;
//Any initializers go here.
memset(temptree, 0, sizeof(*temptree));
temptree->end_cmp = end_cmp;
temptree->data_cmp = data_cmp;
temptree->allow_overlaps = allow_overlaps;
temptree->malloc = user_malloc;
temptree->free = user_free;
temptree->realloc = user_realloc;
temptree->incr_memory_size = incr_memory_size;
temptree->decr_memory_size = decr_memory_size;
temptree->extra_memory_size = extra_memory_size;
*ptree = temptree;
return 0;
......
......@@ -18,7 +18,6 @@
MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7
*/
//Defines BOOL data type.
#include <toku_portability.h>
#include <brttypes.h>
#include <db.h>
......@@ -67,7 +66,7 @@ struct __toku_range_tree;
\return
- 0: Success.
- EINVAL: If any pointer argument is NULL. */
int toku_rt_get_allow_overlaps(toku_range_tree* tree, BOOL* allowed);
int toku_rt_get_allow_overlaps(toku_range_tree* tree, bool* allowed);
/**
Creates a range tree.
......@@ -87,16 +86,16 @@ int toku_rt_get_allow_overlaps(toku_range_tree* tree, BOOL* allowed);
\return
- 0: Success.
- EINVAL: If any pointer argument is NULL.
- EINVAL: If allow_overlaps = TRUE and the implementation does
- EINVAL: If allow_overlaps = true and the implementation does
not support overlaps.
- Other exit codes may be forwarded from underlying system calls. */
int toku_rt_create(toku_range_tree** ptree,
int (*end_cmp)(const toku_point*,const toku_point*),
int (*data_cmp)(const TXNID,const TXNID),
BOOL allow_overlaps,
void* (*user_malloc) (size_t),
void (*user_free) (void*),
void* (*user_realloc)(void*, size_t));
bool allow_overlaps,
void (*incr_memory_size)(void *extra_memory_size, size_t s),
void (*decr_memory_size)(void *extra_memory_size, size_t s),
void *extra_memory_size);
/**
Destroys and frees a range tree.
......@@ -164,7 +163,7 @@ int toku_rt_find(toku_range_tree* tree,toku_interval* query, u_int32_t k,
- EDOM: If an equivalent range (left, right, and data according to
end_cmp and data_cmp) already exists in the tree.
If an overlapping range exists in the tree and
allow_overlaps == FALSE.
allow_overlaps == false.
- Other exit codes may be forwarded from underlying system calls.
*/
int toku_rt_insert(toku_range_tree* tree, toku_range* range);
......@@ -186,7 +185,7 @@ int toku_rt_delete(toku_range_tree* tree, toku_range* range);
/**
Finds the strict predecessor range of a point i.e. the rightmost range
completely to the left of the query point according to end_cmp.
This operation is only defined if allow_overlaps == FALSE.
This operation is only defined if allow_overlaps == false.
\param tree The range tree to search in.
\param point The point to query. Must be a valid argument to
......@@ -203,12 +202,12 @@ int toku_rt_delete(toku_range_tree* tree, toku_range* range);
- Other exit codes may be forwarded from underlying system calls.
*/
int toku_rt_predecessor(toku_range_tree* tree, toku_point* point,
toku_range* pred, BOOL* wasfound);
toku_range* pred, bool* wasfound);
/**
Finds the strict successor range of a point i.e. the leftmost range
completely to the right of the query point according to end_cmp.
This operation is only defined if allow_overlaps == FALSE.
This operation is only defined if allow_overlaps == false.
\param tree The range tree to search in.
\param point The point to query. Must be a valid argument to
......@@ -225,24 +224,21 @@ int toku_rt_predecessor(toku_range_tree* tree, toku_point* point,
- Other exit codes may be forwarded from underlying system calls.
*/
int toku_rt_successor(toku_range_tree* tree, toku_point* point,
toku_range* succ, BOOL* wasfound);
toku_range* succ, bool* wasfound);
/**
Finds the number of elements in the range tree.
\param tree The range tree.
\param size A buffer to return the the number of elements
in the range tree.
\return
- 0: Success.
- EINVAL: If any pointer argument is NULL.
\return The number of ranges in the range tree
*/
int toku_rt_get_size(toku_range_tree* tree, u_int32_t* size);
size_t toku_rt_get_size(toku_range_tree* tree);
int toku_rt_iterate(toku_range_tree* tree, int (*f)(toku_range*,void*), void* extra);
void toku_rt_verify(toku_range_tree *tree);
size_t toku_rt_memory_size(toku_range_tree *tree);
#if defined(__cplusplus)
}
#endif
......
......@@ -20,10 +20,10 @@ init_range (toku_range* range, int left, int right, int data) {
}
static void
setup_tree (BOOL allow_overlaps, BOOL insert, int left, int right, int data) {
setup_tree (bool allow_overlaps, BOOL insert, int left, int right, int data) {
int r;
toku_range range;
r = toku_rt_create(&tree, int_cmp, char_cmp, allow_overlaps, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, char_cmp, allow_overlaps, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
if (insert) {
......
......@@ -100,3 +100,10 @@ verify_all_overlap (toku_interval* query, toku_range* list, unsigned listlen) {
}
}
static inline void
test_incr_memory_size(void *extra UU(), size_t s UU()) {
}
static inline void
test_decr_memory_size(void *extra UU(), size_t s UU()) {
}
......@@ -2,17 +2,17 @@
#include "test.h"
static void test_create_close(BOOL allow_overlaps) {
static void test_create_close(bool allow_overlaps) {
int r;
#ifdef TOKU_RT_NOOVERLAPS
if (allow_overlaps) return;
#endif
toku_range_tree *tree = NULL;
r = toku_rt_create(&tree, int_cmp, char_cmp, allow_overlaps, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, char_cmp, allow_overlaps, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
assert(tree!=NULL);
BOOL temp;
bool temp;
r = toku_rt_get_allow_overlaps(tree, &temp);
CKERR(r);
assert((temp != 0) == (allow_overlaps != 0));
......@@ -22,32 +22,12 @@ static void test_create_close(BOOL allow_overlaps) {
tree = NULL;
}
static void test_create_close_nomem(BOOL allow_overlaps) {
#ifdef TOKU_RT_NOOVERLAPS
if (allow_overlaps) return;
#endif
for (int i = 1; i <= 1; i++) {
mallocced = 0;
failon = i;
toku_range_tree *tree = NULL;
int r = toku_rt_create(&tree, int_cmp, char_cmp, allow_overlaps,
fail_malloc, toku_free, toku_realloc);
CKERR2(r, ENOMEM);
assert(tree==NULL);
}
}
int main(int argc, const char *argv[]) {
parse_args(argc, argv);
test_create_close(false);
test_create_close(true);
test_create_close_nomem(false);
test_create_close_nomem(true);
return 0;
}
......
......@@ -10,26 +10,16 @@ int main(int argc, const char *argv[]) {
parse_args(argc, argv);
/* Create tests */
r = toku_rt_create(NULL, int_cmp, TXNID_cmp, FALSE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(NULL, int_cmp, TXNID_cmp, false, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR2(r, EINVAL);
r = toku_rt_create(&tree, NULL, TXNID_cmp, FALSE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, NULL, TXNID_cmp, false, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR2(r, EINVAL);
assert(tree == NULL);
r = toku_rt_create(&tree, int_cmp, NULL, FALSE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, NULL, false, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR2(r, EINVAL);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, FALSE, NULL, toku_free, toku_realloc);
CKERR2(r, EINVAL);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, FALSE, toku_malloc, NULL, toku_realloc);
CKERR2(r, EINVAL);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, FALSE, toku_malloc, toku_free, NULL);
CKERR2(r, EINVAL);
assert(tree == NULL);
/* Close tests */
r = toku_rt_close(NULL);
CKERR2(r, EINVAL);
......@@ -38,7 +28,7 @@ int main(int argc, const char *argv[]) {
r = toku_rt_insert(NULL, &range);
CKERR2(r, EINVAL);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, FALSE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, false, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
assert(tree != NULL);
......@@ -51,7 +41,7 @@ int main(int argc, const char *argv[]) {
r = toku_rt_delete(NULL, &range);
CKERR2(r, EINVAL);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, FALSE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, false, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
assert(tree != NULL);
......@@ -68,7 +58,7 @@ int main(int argc, const char *argv[]) {
range.ends.right = (toku_point*)&stuff[1];
range.data = 0;
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, FALSE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, false, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
assert(tree != NULL);
......@@ -99,8 +89,8 @@ int main(int argc, const char *argv[]) {
/* Predecessor tests */
toku_point* foo = (toku_point*)&stuff[0];
BOOL wasfound;
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, FALSE, toku_malloc, toku_free, toku_realloc);
bool wasfound;
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, false, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
assert(tree != NULL);
......@@ -119,7 +109,7 @@ int main(int argc, const char *argv[]) {
r = toku_rt_close(tree); CKERR(r);
#ifndef TOKU_RT_NOOVERLAPS
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, TRUE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, true, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
assert(tree != NULL);
......@@ -133,7 +123,7 @@ int main(int argc, const char *argv[]) {
/* Successor tests */
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, FALSE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, false, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
assert(tree != NULL);
......@@ -152,7 +142,7 @@ int main(int argc, const char *argv[]) {
r = toku_rt_close(tree); CKERR(r);
#ifndef TOKU_RT_NOOVERLAPS
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, TRUE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, true, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
assert(tree != NULL);
......@@ -165,11 +155,11 @@ int main(int argc, const char *argv[]) {
#endif
/* Get allow overlap */
BOOL allowed;
bool allowed;
r = toku_rt_get_allow_overlaps(NULL, &allowed);
CKERR2(r, EINVAL);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, FALSE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, false, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
assert(tree != NULL);
......@@ -180,16 +170,10 @@ int main(int argc, const char *argv[]) {
tree = NULL;
/* size tests */
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, FALSE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, TXNID_cmp, false, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
assert(tree != NULL);
r = toku_rt_get_size(NULL, NULL); CKERR2(r, EINVAL);
r = toku_rt_get_size(tree, NULL); CKERR2(r, EINVAL);
u_int32_t tree_size;
r = toku_rt_get_size(NULL, &tree_size); CKERR2(r, EINVAL);
r = toku_rt_get_size(tree, &tree_size); CKERR(r);
r = toku_rt_close(tree); CKERR(r);
tree = NULL;
......
......@@ -21,7 +21,7 @@ int main(int argc, const char *argv[]) {
|-------B-------|
*/
#ifndef TOKU_RT_NOOVERLAPS
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, char_cmp, true, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
/* Verify we can insert a trivial range and lose it. */
......@@ -29,8 +29,7 @@ int main(int argc, const char *argv[]) {
range.ends.right = (toku_point*)&nums[1];
range.data = (TXNID)letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
u_int32_t num_in_range;
r = toku_rt_get_size(tree, &num_in_range); CKERR(r);
size_t num_in_range = toku_rt_get_size(tree);
assert(num_in_range == 1);
r = toku_rt_delete(tree, &range); CKERR(r);
......@@ -112,7 +111,7 @@ int main(int argc, const char *argv[]) {
|---A---|
|---B---|
*/
r = toku_rt_create(&tree, int_cmp, char_cmp, FALSE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, char_cmp, false, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
/* Verify we can insert a trivial range and lose it. */
......
......@@ -3,20 +3,8 @@
#include "test.h"
unsigned malloc_cnt;
unsigned malloc_cntl;
/* Controllable malloc failure: it fails only the ith time it is invoked */
static void* malloc_fail(size_t size) {
if (malloc_cntl == ++malloc_cnt) {
errno = ENOMEM;
return NULL;
} else
return toku_malloc(size);
}
static void
RunTest (BOOL f_overlaps_allowed) {
RunTest (bool f_overlaps_allowed) {
int i, j;
int r;
toku_range_tree *tree;
......@@ -30,7 +18,7 @@ RunTest (BOOL f_overlaps_allowed) {
/* Insert and delete lots of ranges to force memory increase and decrease */
r = toku_rt_create(&tree, int_cmp, char_cmp, f_overlaps_allowed, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, char_cmp, f_overlaps_allowed, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
/* Insert lots of ranges */
......@@ -52,28 +40,16 @@ RunTest (BOOL f_overlaps_allowed) {
}
r = toku_rt_close(tree); CKERR(r);
tree = NULL;
/* Force malloc to fail */
/* Failure when allocating the tree */
malloc_cnt = 0;
malloc_cntl = 1;
r = toku_rt_create(&tree, int_cmp, char_cmp, f_overlaps_allowed, malloc_fail, toku_free,
toku_realloc);
CKERR2(r, ENOMEM);
}
int main(int argc, const char *argv[]) {
parse_args(argc, argv);
#ifndef TOKU_RT_NOOVERLAPS
RunTest(TRUE);
RunTest(true);
#endif
RunTest(FALSE);
RunTest(false);
return 0;
}
......@@ -3,7 +3,7 @@
#include "test.h"
static void
run_test (BOOL overlap_allowed) {
run_test (bool overlap_allowed) {
int r;
toku_range_tree *tree;
toku_range range;
......@@ -17,15 +17,7 @@ run_test (BOOL overlap_allowed) {
1 2 3 4 5 6 7
|---A-----------|
*/
r = toku_rt_create(
&tree,
int_cmp,
char_cmp,
overlap_allowed,
toku_malloc,
toku_free,
toku_realloc
);
r = toku_rt_create(&tree, int_cmp, char_cmp, overlap_allowed, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
range.ends.left = (toku_point*)&nums[1];
......@@ -43,8 +35,8 @@ int main(int argc, const char *argv[]) {
parse_args(argc, argv);
#ifndef TOKU_RT_NOOVERLAPS
run_test(TRUE);
run_test(true);
#endif
run_test(FALSE);
run_test(false);
return 0;
}
......@@ -40,7 +40,7 @@ int main(int argc, const char *argv[]) {
|-------A-------|
|-------B-------|
*/
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, char_cmp, true, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
......@@ -190,7 +190,7 @@ int main(int argc, const char *argv[]) {
find_range.left = (toku_point*)&nums[3];
find_range.right = (toku_point*)&nums[4];
r = toku_rt_create(&tree, int_cmp, char_cmp, FALSE, toku_malloc, toku_free, toku_realloc);
r = toku_rt_create(&tree, int_cmp, char_cmp, false, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
......
......@@ -20,11 +20,11 @@ rundelete (int rexpect, toku_range* todelete) {
}
static void
tests (BOOL allow_overlaps) {
tests (bool allow_overlaps) {
toku_range insert;
int i;
/* Force buf to increase. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
setup_tree(allow_overlaps, false, 0, 0, 0);
for (i = 0; i < (int)numlen / 2; i++) {
runinsert(0, init_range(&insert, i, i, 0));
int j = numlen /2 + i;
......@@ -48,9 +48,9 @@ int main(int argc, const char *argv[]) {
for (i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) nums[i] = i;
buflen = 2;
buf = (toku_range*)toku_malloc(2 * sizeof(toku_range));
tests(FALSE);
tests(false);
#ifndef TOKU_RT_NOOVERLAPS
tests(TRUE);
tests(true);
#endif
tree = NULL;
......
......@@ -26,15 +26,15 @@ int main(int argc, const char *argv[]) {
parse_args(argc, argv);
toku_range_tree *tree;
r = toku_rt_create(&tree, int_cmp, char_cmp, FALSE, toku_malloc, toku_free, toku_realloc); CKERR(r);
r = toku_rt_create(&tree, int_cmp, char_cmp, false, test_incr_memory_size, test_decr_memory_size, NULL);
CKERR(r);
assert(count_ranges(tree) == 0);
const int nranges = 10;
int nums[nranges];
for (int i = 0; i < nranges; i++) {
assert(count_ranges(tree) == i);
u_int32_t treesize = 0;
r = toku_rt_get_size(tree, &treesize); CKERR(r);
u_int32_t treesize = toku_rt_get_size(tree);
assert(treesize == (u_int32_t) i);
nums[i] = i;
toku_range range; my_init_range(&range, &nums[i], &nums[i], 'a');
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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