Commit 03339433 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #293

Addresses #307
Replaced unsigned with u_int32_t
Also one bugfix with incorrect assert.
Made all tests run properly (bugs were mostly in the test).

git-svn-id: file:///svn/tokudb@2035 c7de825b-a66e-492c-adef-691d508d4ae1
parent b898d248
...@@ -24,7 +24,7 @@ static int __toku_lt_panic(toku_lock_tree *tree) { ...@@ -24,7 +24,7 @@ static int __toku_lt_panic(toku_lock_tree *tree) {
return tree->panic(tree->db); return tree->panic(tree->db);
} }
const unsigned __toku_default_buflen = 2; const u_int32_t __toku_default_buflen = 2;
static const DBT __toku_lt_infinity; static const DBT __toku_lt_infinity;
static const DBT __toku_lt_neg_infinity; static const DBT __toku_lt_neg_infinity;
...@@ -134,11 +134,11 @@ static int __toku_payload_copy(toku_lock_tree* tree, ...@@ -134,11 +134,11 @@ static int __toku_payload_copy(toku_lock_tree* tree,
else { else {
assert(payload_in); assert(payload_in);
if (tree->payload_used + len_in > tree->payload_capacity) return ENOMEM; if (tree->payload_used + len_in > tree->payload_capacity) return ENOMEM;
*payload_out = tree->malloc(len_in); *payload_out = tree->malloc((size_t)len_in);
if (!*payload_out) return errno; if (!*payload_out) return errno;
tree->payload_used += len_in; tree->payload_used += len_in;
*len_out = len_in; *len_out = len_in;
memcpy(*payload_out, payload_in, len_in); memcpy(*payload_out, payload_in, (size_t)len_in);
} }
return 0; return 0;
} }
...@@ -242,19 +242,19 @@ assert(tree->selfread); ...@@ -242,19 +242,19 @@ assert(tree->selfread);
*/ */
static int __toku_lt_rt_dominates(toku_lock_tree* tree, toku_range* query, static int __toku_lt_rt_dominates(toku_lock_tree* tree, toku_range* query,
toku_range_tree* rt, BOOL* dominated) { toku_range_tree* rt, BOOL* dominated) {
assert(tree && query && rt && dominated); assert(tree && query && dominated);
if (!rt) { if (!rt) {
*dominated = FALSE; *dominated = FALSE;
return 0; return 0;
} }
BOOL allow_overlaps; BOOL allow_overlaps;
const size_t query_size = 1; const u_int32_t query_size = 1;
toku_range buffer[query_size]; toku_range buffer[query_size];
unsigned buflen = query_size; u_int32_t buflen = query_size;
toku_range* buf = &buffer[0]; toku_range* buf = &buffer[0];
unsigned numfound; u_int32_t numfound;
int r; int r;
/* Sanity check. (Function only supports non-overlap range trees.) */ /* Sanity check. (Function only supports non-overlap range trees.) */
r = toku_rt_get_allow_overlaps(rt, &allow_overlaps); r = toku_rt_get_allow_overlaps(rt, &allow_overlaps);
...@@ -292,11 +292,11 @@ static int __toku_lt_borderwrite_conflict(toku_lock_tree* tree, DB_TXN* self, ...@@ -292,11 +292,11 @@ static int __toku_lt_borderwrite_conflict(toku_lock_tree* tree, DB_TXN* self,
toku_range_tree* rt = tree->borderwrite; toku_range_tree* rt = tree->borderwrite;
assert(rt); assert(rt);
const size_t query_size = 2; const u_int32_t query_size = 2;
toku_range buffer[query_size]; toku_range buffer[query_size];
unsigned buflen = query_size; u_int32_t buflen = query_size;
toku_range* buf = &buffer[0]; toku_range* buf = &buffer[0];
unsigned numfound; u_int32_t numfound;
int r; int r;
r = toku_rt_find(rt, query, query_size, &buf, &buflen, &numfound); r = toku_rt_find(rt, query, query_size, &buf, &buflen, &numfound);
...@@ -322,11 +322,11 @@ static int __toku_lt_borderwrite_conflict(toku_lock_tree* tree, DB_TXN* self, ...@@ -322,11 +322,11 @@ static int __toku_lt_borderwrite_conflict(toku_lock_tree* tree, DB_TXN* self,
static int __toku_lt_meets(toku_lock_tree* tree, toku_range* query, static int __toku_lt_meets(toku_lock_tree* tree, toku_range* query,
toku_range_tree* rt, BOOL* met) { toku_range_tree* rt, BOOL* met) {
assert(tree && query && rt && met); assert(tree && query && rt && met);
const size_t query_size = 1; const u_int32_t query_size = 1;
toku_range buffer[query_size]; toku_range buffer[query_size];
unsigned buflen = query_size; u_int32_t buflen = query_size;
toku_range* buf = &buffer[0]; toku_range* buf = &buffer[0];
unsigned numfound; u_int32_t numfound;
int r; int r;
BOOL allow_overlaps; BOOL allow_overlaps;
...@@ -354,11 +354,11 @@ static int __toku_lt_meets_peer(toku_lock_tree* tree, toku_range* query, ...@@ -354,11 +354,11 @@ static int __toku_lt_meets_peer(toku_lock_tree* tree, toku_range* query,
assert(tree && query && rt && self && met); assert(tree && query && rt && self && met);
assert(query->left == query->right); assert(query->left == query->right);
const size_t query_size = 2; const u_int32_t query_size = 2;
toku_range buffer[query_size]; toku_range buffer[query_size];
unsigned buflen = query_size; u_int32_t buflen = query_size;
toku_range* buf = &buffer[0]; toku_range* buf = &buffer[0];
unsigned numfound; u_int32_t numfound;
int r; int r;
r = toku_rt_find(rt, query, query_size, &buf, &buflen, &numfound); r = toku_rt_find(rt, query, query_size, &buf, &buflen, &numfound);
...@@ -451,9 +451,9 @@ static BOOL __toku_lt_p_independent(toku_point* point, toku_range* range) { ...@@ -451,9 +451,9 @@ static BOOL __toku_lt_p_independent(toku_point* point, toku_range* range) {
static int __toku_lt_extend_extreme(toku_lock_tree* tree,toku_range* to_insert, static int __toku_lt_extend_extreme(toku_lock_tree* tree,toku_range* to_insert,
BOOL* alloc_left, BOOL* alloc_right, BOOL* alloc_left, BOOL* alloc_right,
unsigned numfound) { u_int32_t numfound) {
assert(to_insert && tree && alloc_left && alloc_right); assert(to_insert && tree && alloc_left && alloc_right);
unsigned i; u_int32_t i;
assert(numfound <= tree->buflen); assert(numfound <= tree->buflen);
for (i = 0; i < numfound; i++) { for (i = 0; i < numfound; i++) {
int c; int c;
...@@ -513,10 +513,10 @@ static int __toku_lt_alloc_extreme(toku_lock_tree* tree, toku_range* to_insert, ...@@ -513,10 +513,10 @@ static int __toku_lt_alloc_extreme(toku_lock_tree* tree, toku_range* to_insert,
static int __toku_lt_delete_overlapping_ranges(toku_lock_tree* tree, static int __toku_lt_delete_overlapping_ranges(toku_lock_tree* tree,
toku_range_tree* rt, toku_range_tree* rt,
unsigned numfound) { u_int32_t numfound) {
assert(tree && rt); assert(tree && rt);
int r; int r;
unsigned i; u_int32_t i;
assert(numfound <= tree->buflen); assert(numfound <= tree->buflen);
for (i = 0; i < numfound; i++) { for (i = 0; i < numfound; i++) {
r = toku_rt_delete(rt, &tree->buf[i]); r = toku_rt_delete(rt, &tree->buf[i]);
...@@ -526,11 +526,11 @@ static int __toku_lt_delete_overlapping_ranges(toku_lock_tree* tree, ...@@ -526,11 +526,11 @@ static int __toku_lt_delete_overlapping_ranges(toku_lock_tree* tree,
} }
static void __toku_lt_free_points(toku_lock_tree* tree, toku_range* to_insert, static void __toku_lt_free_points(toku_lock_tree* tree, toku_range* to_insert,
unsigned numfound) { u_int32_t numfound) {
assert(tree && to_insert); assert(tree && to_insert);
assert(numfound <= tree->buflen); assert(numfound <= tree->buflen);
unsigned i; u_int32_t i;
for (i = 0; i < numfound; i++) { for (i = 0; i < numfound; i++) {
/* /*
We will maintain the invariant: (separately for read and write We will maintain the invariant: (separately for read and write
...@@ -564,7 +564,7 @@ static int __toku_consolidate(toku_lock_tree* tree, ...@@ -564,7 +564,7 @@ static int __toku_consolidate(toku_lock_tree* tree,
if (r!=0) return r; if (r!=0) return r;
assert(selfread); assert(selfread);
/* Find all overlapping ranges in the self-read */ /* Find all overlapping ranges in the self-read */
unsigned numfound; u_int32_t numfound;
r = toku_rt_find(selfread, query, 0, &tree->buf, &tree->buflen, r = toku_rt_find(selfread, query, 0, &tree->buf, &tree->buflen,
&numfound); &numfound);
if (r!=0) return r; if (r!=0) return r;
...@@ -624,7 +624,7 @@ static int __toku_lt_free_contents_slow(toku_lock_tree* tree, ...@@ -624,7 +624,7 @@ static int __toku_lt_free_contents_slow(toku_lock_tree* tree,
toku_range query; toku_range query;
toku_point left; toku_point left;
toku_point right; toku_point right;
unsigned numfound; u_int32_t numfound;
__toku_lt_init_full_query(tree, &query, &left, &right); __toku_lt_init_full_query(tree, &query, &left, &right);
/* /*
...@@ -657,7 +657,7 @@ static int __toku_lt_free_contents(toku_lock_tree* tree, toku_range_tree* rt) { ...@@ -657,7 +657,7 @@ static int __toku_lt_free_contents(toku_lock_tree* tree, toku_range_tree* rt) {
toku_point right; toku_point right;
__toku_lt_init_full_query(tree, &query, &left, &right); __toku_lt_init_full_query(tree, &query, &left, &right);
unsigned numfound; u_int32_t numfound;
r = toku_rt_find(rt, &query, 0, &tree->buf, &tree->buflen, &numfound); r = toku_rt_find(rt, &query, 0, &tree->buf, &tree->buflen, &numfound);
if (r==0) __toku_lt_free_points(tree, &query, numfound); if (r==0) __toku_lt_free_points(tree, &query, numfound);
else if (r==ENOMEM) r = __toku_lt_free_contents_slow(tree, rt); else if (r==ENOMEM) r = __toku_lt_free_contents_slow(tree, rt);
...@@ -673,7 +673,7 @@ static BOOL __toku_r_backwards(toku_range* range) { ...@@ -673,7 +673,7 @@ static BOOL __toku_r_backwards(toku_range* range) {
/* Optimization: if all the pointers are equal, clearly left == right. */ /* Optimization: if all the pointers are equal, clearly left == right. */
return (left->key_payload != right->key_payload || return (left->key_payload != right->key_payload ||
left->data_payload != right->data_payload) && left->data_payload != right->data_payload) &&
__toku_lt_point_cmp(&left, &right) > 0; __toku_lt_point_cmp(left, right) > 0;
} }
...@@ -705,7 +705,7 @@ static int __toku_lt_preprocess(toku_lock_tree* tree, DB_TXN* txn, ...@@ -705,7 +705,7 @@ static int __toku_lt_preprocess(toku_lock_tree* tree, DB_TXN* txn,
return 0; return 0;
} }
static int __toku_lt_get_border(toku_lock_tree* tree, unsigned numfound, static int __toku_lt_get_border(toku_lock_tree* tree, u_int32_t numfound,
toku_range* pred, toku_range* succ, toku_range* pred, toku_range* succ,
BOOL* found_p, BOOL* found_s, BOOL* found_p, BOOL* found_s,
toku_range* to_insert) { toku_range* to_insert) {
...@@ -800,12 +800,12 @@ static int __toku_lt_borderwrite_insert(toku_lock_tree* tree, ...@@ -800,12 +800,12 @@ static int __toku_lt_borderwrite_insert(toku_lock_tree* tree,
assert(tree && query && to_insert); assert(tree && query && to_insert);
int r; int r;
toku_range_tree* borderwrite = tree->borderwrite; assert(borderwrite); toku_range_tree* borderwrite = tree->borderwrite; assert(borderwrite);
const size_t query_size = 1; const u_int32_t query_size = 1;
toku_range buffer[query_size]; toku_range buffer[query_size];
unsigned buflen = query_size; u_int32_t buflen = query_size;
toku_range* buf = &buffer[0]; toku_range* buf = &buffer[0];
unsigned numfound; u_int32_t numfound;
r = toku_rt_find(borderwrite, query, query_size, &buf, &buflen, &numfound); r = toku_rt_find(borderwrite, query, query_size, &buf, &buflen, &numfound);
if (r!=0) return __toku_lt_panic(tree); if (r!=0) return __toku_lt_panic(tree);
assert(numfound <= query_size); assert(numfound <= query_size);
......
...@@ -63,7 +63,7 @@ typedef struct { ...@@ -63,7 +63,7 @@ typedef struct {
/** A temporary area where we store the results of various find on /** A temporary area where we store the results of various find on
the range trees that this lock tree owns */ the range trees that this lock tree owns */
toku_range* buf; toku_range* buf;
unsigned buflen; /**< The length of buf */ u_int32_t buflen; /**< The length of buf */
/** The maximum amount of memory to be used for DBT payloads. */ /** The maximum amount of memory to be used for DBT payloads. */
size_t payload_capacity; size_t payload_capacity;
/** The current amount of memory used for DBT payloads. */ /** The current amount of memory used for DBT payloads. */
......
...@@ -30,7 +30,7 @@ else ...@@ -30,7 +30,7 @@ else
GCOV_FLAGS = GCOV_FLAGS =
endif endif
CFLAGS = -W -Wall -Wextra -Werror $(OPTFLAGS) -g3 -ggdb3 $(GCOV_FLAGS) CFLAGS = -W -Wall -Wextra -Werror $(OPTFLAGS) -g3 -ggdb3 $(GCOV_FLAGS)
CFLAGS += -Wbad-function-cast -Wcast-align -Wconversion -Waggregate-return CFLAGS += -Wbad-function-cast -Wcast-align -Waggregate-return
CFLAGS += -Wmissing-noreturn -Wmissing-format-attribute -Wunreachable-code CFLAGS += -Wmissing-noreturn -Wmissing-format-attribute -Wunreachable-code
CPPFLAGS += -L../ -L../../range_tree CPPFLAGS += -L../ -L../../range_tree
CPPFLAGS += -I. -I../ -I../../range_tree -I../../../newbrt -I../../../include -lpthread CPPFLAGS += -I. -I../ -I../../range_tree -I../../../newbrt -I../../../include -lpthread
......
...@@ -106,3 +106,9 @@ DBT *dbt_init(DBT *dbt, void *data, u_int32_t size) { ...@@ -106,3 +106,9 @@ DBT *dbt_init(DBT *dbt, void *data, u_int32_t size) {
Return values conform to cmp from qsort(3). Return values conform to cmp from qsort(3).
*/ */
extern int __toku_lt_point_cmp(void* a, void* b); extern int __toku_lt_point_cmp(void* a, void* b);
void init_point(toku_point* point, toku_lock_tree* tree) {
assert(point && tree);
memset(point, 0, sizeof(toku_point));
point->lt = tree;
}
...@@ -28,11 +28,29 @@ toku_range* buf; ...@@ -28,11 +28,29 @@ toku_range* buf;
unsigned buflen; unsigned buflen;
unsigned numfound; unsigned numfound;
void init_query(BOOL dups) {
init_point(&qleft, lt);
init_point(&qright, lt);
qleft.key_payload = (void *) toku_lt_neg_infinity;
qright.key_payload = (void *) toku_lt_infinity;
if (dups) {
qleft.data_payload = qleft.key_payload;
qright.data_payload = qright.key_payload;
}
memset(&query,0,sizeof(query));
query.left = &qleft;
query.right = &qright;
}
void setup_tree(BOOL dups) { void setup_tree(BOOL dups) {
r = toku_lt_create(&lt, db, dups, dbpanic, mem, dbcmp, dbcmp, r = toku_lt_create(&lt, db, dups, dbpanic, mem, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc); toku_malloc, toku_free, toku_realloc);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
init_query(dups);
} }
void close_tree(void) { void close_tree(void) {
...@@ -109,13 +127,13 @@ void lt_find(BOOL dups, toku_range_tree* rt, ...@@ -109,13 +127,13 @@ void lt_find(BOOL dups, toku_range_tree* rt,
assert(numfound==k); assert(numfound==k);
toku_point left, right; toku_point left, right;
memset(&left,0,sizeof(left)); init_point(&left, lt);
setup_payload_len(&left.key_payload, &left.key_len, key_l); setup_payload_len(&left.key_payload, &left.key_len, key_l);
if (dups) { if (dups) {
if (key_l < null) left.data_payload = left.key_payload; if (key_l < null) left.data_payload = left.key_payload;
else setup_payload_len(&left.data_payload, &left.data_len, data_l); else setup_payload_len(&left.data_payload, &left.data_len, data_l);
} }
memset(&right,0,sizeof(right)); init_point(&right, lt);
setup_payload_len(&right.key_payload, &right.key_len, key_r); setup_payload_len(&right.key_payload, &right.key_len, key_r);
if (dups) { if (dups) {
if (key_r < null) right.data_payload = right.key_payload; if (key_r < null) right.data_payload = right.key_payload;
...@@ -202,31 +220,12 @@ void insert_2_noclose(BOOL dups, int key_l[2], int key_r[2], ...@@ -202,31 +220,12 @@ void insert_2_noclose(BOOL dups, int key_l[2], int key_r[2],
} }
void init_query(BOOL dups) {
memset(&qleft, 0,sizeof(qleft));
memset(&qright,0,sizeof(qright));
qleft.key_payload = (void *) toku_lt_neg_infinity;
qright.key_payload = (void *) toku_lt_infinity;
if (dups) {
qleft.data_payload = qleft.key_payload;
qright.data_payload = qright.key_payload;
}
memset(&query,0,sizeof(query));
query.left = &qleft;
query.right = &qright;
}
void runtest(BOOL dups) { void runtest(BOOL dups) {
int i; int i;
const DBT* choices[3]; const DBT* choices[3];
init_query(dups);
choices[0] = toku_lt_neg_infinity; choices[0] = toku_lt_neg_infinity;
choices[1] = NULL; choices[1] = NULL;
choices[2] = toku_lt_infinity; choices[2] = toku_lt_infinity;
......
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