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) {
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_neg_infinity;
......@@ -134,11 +134,11 @@ static int __toku_payload_copy(toku_lock_tree* tree,
else {
assert(payload_in);
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;
tree->payload_used += len_in;
*len_out = len_in;
memcpy(*payload_out, payload_in, len_in);
memcpy(*payload_out, payload_in, (size_t)len_in);
}
return 0;
}
......@@ -242,19 +242,19 @@ assert(tree->selfread);
*/
static int __toku_lt_rt_dominates(toku_lock_tree* tree, toku_range* query,
toku_range_tree* rt, BOOL* dominated) {
assert(tree && query && rt && dominated);
assert(tree && query && dominated);
if (!rt) {
*dominated = FALSE;
return 0;
}
BOOL allow_overlaps;
const size_t query_size = 1;
toku_range buffer[query_size];
unsigned buflen = query_size;
toku_range* buf = &buffer[0];
unsigned numfound;
int r;
BOOL allow_overlaps;
const u_int32_t query_size = 1;
toku_range buffer[query_size];
u_int32_t buflen = query_size;
toku_range* buf = &buffer[0];
u_int32_t numfound;
int r;
/* Sanity check. (Function only supports non-overlap range trees.) */
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,
toku_range_tree* rt = tree->borderwrite;
assert(rt);
const size_t query_size = 2;
const u_int32_t query_size = 2;
toku_range buffer[query_size];
unsigned buflen = query_size;
u_int32_t buflen = query_size;
toku_range* buf = &buffer[0];
unsigned numfound;
u_int32_t numfound;
int r;
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,
static int __toku_lt_meets(toku_lock_tree* tree, toku_range* query,
toku_range_tree* rt, BOOL* met) {
assert(tree && query && rt && met);
const size_t query_size = 1;
const u_int32_t query_size = 1;
toku_range buffer[query_size];
unsigned buflen = query_size;
u_int32_t buflen = query_size;
toku_range* buf = &buffer[0];
unsigned numfound;
u_int32_t numfound;
int r;
BOOL allow_overlaps;
......@@ -354,11 +354,11 @@ static int __toku_lt_meets_peer(toku_lock_tree* tree, toku_range* query,
assert(tree && query && rt && self && met);
assert(query->left == query->right);
const size_t query_size = 2;
const u_int32_t query_size = 2;
toku_range buffer[query_size];
unsigned buflen = query_size;
u_int32_t buflen = query_size;
toku_range* buf = &buffer[0];
unsigned numfound;
u_int32_t numfound;
int r;
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) {
static int __toku_lt_extend_extreme(toku_lock_tree* tree,toku_range* to_insert,
BOOL* alloc_left, BOOL* alloc_right,
unsigned numfound) {
u_int32_t numfound) {
assert(to_insert && tree && alloc_left && alloc_right);
unsigned i;
u_int32_t i;
assert(numfound <= tree->buflen);
for (i = 0; i < numfound; i++) {
int c;
......@@ -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,
toku_range_tree* rt,
unsigned numfound) {
u_int32_t numfound) {
assert(tree && rt);
int r;
unsigned i;
u_int32_t i;
assert(numfound <= tree->buflen);
for (i = 0; i < numfound; i++) {
r = toku_rt_delete(rt, &tree->buf[i]);
......@@ -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,
unsigned numfound) {
u_int32_t numfound) {
assert(tree && to_insert);
assert(numfound <= tree->buflen);
unsigned i;
u_int32_t i;
for (i = 0; i < numfound; i++) {
/*
We will maintain the invariant: (separately for read and write
......@@ -564,7 +564,7 @@ static int __toku_consolidate(toku_lock_tree* tree,
if (r!=0) return r;
assert(selfread);
/* 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,
&numfound);
if (r!=0) return r;
......@@ -624,7 +624,7 @@ static int __toku_lt_free_contents_slow(toku_lock_tree* tree,
toku_range query;
toku_point left;
toku_point right;
unsigned numfound;
u_int32_t numfound;
__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) {
toku_point 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);
if (r==0) __toku_lt_free_points(tree, &query, numfound);
else if (r==ENOMEM) r = __toku_lt_free_contents_slow(tree, rt);
......@@ -673,7 +673,7 @@ static BOOL __toku_r_backwards(toku_range* range) {
/* Optimization: if all the pointers are equal, clearly left == right. */
return (left->key_payload != right->key_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,
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,
BOOL* found_p, BOOL* found_s,
toku_range* to_insert) {
......@@ -800,12 +800,12 @@ static int __toku_lt_borderwrite_insert(toku_lock_tree* tree,
assert(tree && query && to_insert);
int r;
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];
unsigned buflen = query_size;
u_int32_t buflen = query_size;
toku_range* buf = &buffer[0];
unsigned numfound;
u_int32_t numfound;
r = toku_rt_find(borderwrite, query, query_size, &buf, &buflen, &numfound);
if (r!=0) return __toku_lt_panic(tree);
assert(numfound <= query_size);
......
......@@ -63,7 +63,7 @@ typedef struct {
/** A temporary area where we store the results of various find on
the range trees that this lock tree owns */
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. */
size_t payload_capacity;
/** The current amount of memory used for DBT payloads. */
......
......@@ -30,7 +30,7 @@ else
GCOV_FLAGS =
endif
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
CPPFLAGS += -L../ -L../../range_tree
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) {
Return values conform to cmp from qsort(3).
*/
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;
unsigned buflen;
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) {
r = toku_lt_create(&lt, db, dups, dbpanic, mem, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lt);
init_query(dups);
}
void close_tree(void) {
......@@ -109,13 +127,13 @@ void lt_find(BOOL dups, toku_range_tree* rt,
assert(numfound==k);
toku_point left, right;
memset(&left,0,sizeof(left));
init_point(&left, lt);
setup_payload_len(&left.key_payload, &left.key_len, key_l);
if (dups) {
if (key_l < null) left.data_payload = left.key_payload;
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);
if (dups) {
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],
}
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) {
int i;
const DBT* choices[3];
init_query(dups);
choices[0] = toku_lt_neg_infinity;
choices[1] = NULL;
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