Commit f9d49ff9 authored by Rich Prohaska's avatar Rich Prohaska

unified the cursor search for cursor set, get_both, set_range, and...

unified the cursor search for cursor set, get_both, set_range, and get_both_range.  still need to prune the search for some of these operations.


addresses  #186


git-svn-id: file:///svn/tokudb@1149 c7de825b-a66e-492c-adef-691d508d4ae1
parent ae4b7d10
......@@ -378,7 +378,7 @@ int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int fl
goto died1;
}
toku_pma_set_dup_mode(result->u.l.buffer, flags);
if (flags & TOKU_DB_DUPSORT) toku_pma_set_dup_compare(result->u.l.buffer, dup_compare);
toku_pma_set_dup_compare(result->u.l.buffer, dup_compare);
//printf("%s:%d r PMA= %p\n", __FILE__, __LINE__, result->u.l.buffer);
toku_verify_counts(result);
#define BRT_USE_PMA_BULK_INSERT 1
......
......@@ -328,8 +328,7 @@ static void initialize_brtnode (BRT t, BRTNODE n, DISKOFF nodename, int height)
int r = toku_pma_create(&n->u.l.buffer, t->compare_fun, t->db, toku_cachefile_filenum(t->cf), n->nodesize);
assert(r==0);
toku_pma_set_dup_mode(n->u.l.buffer, t->flags & (TOKU_DB_DUP+TOKU_DB_DUPSORT));
if (t->flags & TOKU_DB_DUPSORT)
toku_pma_set_dup_compare(n->u.l.buffer, t->dup_compare);
toku_pma_set_dup_compare(n->u.l.buffer, t->dup_compare);
static int rcount=0;
//printf("%s:%d n PMA= %p (rcount=%d)\n", __FILE__, __LINE__, n->u.l.buffer, rcount);
rcount++;
......@@ -2654,69 +2653,17 @@ static int brtcurs_set_position_prev (BRT_CURSOR cursor, DBT *key, TOKUTXN txn)
return 0;
}
static int brtcurs_set_key(BRT_CURSOR cursor, DISKOFF off, DBT *key, DBT *val, int flag, TOKUTXN txn, BRTNODE parent_brtnode) {
BRT brt = cursor->brt;
void *node_v;
int r;
r = toku_cachetable_get_and_pin(brt->cf, off, &node_v, NULL, toku_brtnode_flush_callback,
toku_brtnode_fetch_callback, brt);
if (r != 0)
return r;
BRTNODE node = node_v;
int childnum;
node->parent_brtnode = parent_brtnode;
if (node->height > 0) {
cursor->path_len += 1;
for (;;) {
childnum = brtnode_left_child(node, key, flag == DB_GET_BOTH ? val : 0, brt);
cursor->path[cursor->path_len-1] = node;
cursor->pathcnum[cursor->path_len-1] = childnum;
brt_node_add_cursor(node, childnum, cursor);
int more = node->u.n.n_bytes_in_hashtable[childnum];
if (more > 0) {
brt_flush_child(cursor->brt, node, childnum, cursor, txn);
node = cursor->path[cursor->path_len-1];
childnum = cursor->pathcnum[cursor->path_len-1];
brt_node_remove_cursor(node, childnum, cursor);
/* the node may have split. search the node keys again */
continue;
}
break;
}
r = brtcurs_set_key(cursor, BRTNODE_CHILD_DISKOFF(node, childnum), key, val, flag, txn, node);
if (r != 0)
brt_node_remove_cursor(node, childnum, cursor);
} else {
cursor->path_len += 1;
cursor->path[cursor->path_len-1] = node;
r = toku_pma_cursor(node->u.l.buffer, &cursor->pmacurs, &cursor->brt->skey, &cursor->brt->sval);
if (r == 0) {
if (flag == DB_SET)
r = toku_pma_cursor_set_key(cursor->pmacurs, key);
else if (flag == DB_GET_BOTH)
r = toku_pma_cursor_set_both(cursor->pmacurs, key, val);
else {
assert(0);
r = DB_NOTFOUND;
}
if (r != 0) {
int rr = toku_pma_cursor_free(&cursor->pmacurs);
assert(rr == 0);
}
}
}
if (r != 0) {
cursor->path_len -= 1;
//verify_local_fingerprint_nonleaf(node);
toku_cachetable_unpin(brt->cf, off, node->dirty, brtnode_size(node));
}
return r;
static int brtcurs_dupsort_next_child(BRT_CURSOR cursor, BRTNODE node, int childnum, int op) {
cursor = cursor; node = node; op = op;
return childnum + 1;
}
static int brtcurs_set_range(BRT_CURSOR cursor, DISKOFF off, DBT *key, TOKUTXN txn, BRTNODE parent_brtnode) {
static int brtcurs_nodup_next_child(BRT_CURSOR cursor, BRTNODE node, int childnum, int op) {
cursor = cursor; node = node; op = op;
return childnum + 1;
}
static int brtcurs_set_search(BRT_CURSOR cursor, DISKOFF off, int op, DBT *key, DBT *val, TOKUTXN txn, BRTNODE parent_brtnode) {
BRT brt = cursor->brt;
void *node_v;
int r;
......@@ -2731,40 +2678,54 @@ static int brtcurs_set_range(BRT_CURSOR cursor, DISKOFF off, DBT *key, TOKUTXN t
if (node->height > 0) {
cursor->path_len += 1;
/* select a subtree by key */
childnum = brtnode_which_child(node, key, brt);
next_child:
/* select the leftmost subtree that may contain the key and val */
childnum = brtnode_left_child(node, key, val, brt);
for (;;) {
cursor->path[cursor->path_len-1] = node;
cursor->pathcnum[cursor->path_len-1] = childnum;
brt_node_add_cursor(node, childnum, cursor);
int more = node->u.n.n_bytes_in_hashtable[childnum];
if (more > 0) {
brt_flush_child(cursor->brt, node, childnum, cursor, txn);
node = cursor->path[cursor->path_len-1];
childnum = cursor->pathcnum[cursor->path_len-1];
brt_node_remove_cursor(node, childnum, cursor);
continue;
/* flush the buffer for the child subtree */
for (;;) {
cursor->path[cursor->path_len-1] = node;
cursor->pathcnum[cursor->path_len-1] = childnum;
brt_node_add_cursor(node, childnum, cursor);
int more = node->u.n.n_bytes_in_hashtable[childnum];
if (more > 0) {
brt_flush_child(cursor->brt, node, childnum, cursor, txn);
node = cursor->path[cursor->path_len-1];
childnum = cursor->pathcnum[cursor->path_len-1];
brt_node_remove_cursor(node, childnum, cursor);
continue;
}
break;
}
break;
}
r = brtcurs_set_range(cursor, BRTNODE_CHILD_DISKOFF(node, childnum), key, txn, node);
if (r != 0) {
/* search in the child subtree */
r = brtcurs_set_search(cursor, BRTNODE_CHILD_DISKOFF(node, childnum), op, key, val, txn, node);
if (r == 0)
break;
/* not found in the child subtree, look elsewhere */
node = cursor->path[cursor->path_len-1];
childnum = cursor->pathcnum[cursor->path_len-1];
brt_node_remove_cursor(node, childnum, cursor);
/* no key in the child subtree is >= key, need to search the next child */
childnum += 1;
if (0) printf("set_range %d %d\n", childnum, node->u.n.n_children);
if (childnum < node->u.n.n_children)
goto next_child;
}
if (brt->flags & TOKU_DB_DUPSORT)
childnum = brtcurs_dupsort_next_child(cursor, node, childnum, op);
else
childnum = brtcurs_nodup_next_child(cursor, node, childnum, op);
if (childnum >= node->u.n.n_children) {
r = DB_NOTFOUND;
break;
}
}
} else {
cursor->path_len += 1;
cursor->path[cursor->path_len-1] = node;
r = toku_pma_cursor(node->u.l.buffer, &cursor->pmacurs, &cursor->brt->skey, &cursor->brt->sval);
if (r == 0) {
r = toku_pma_cursor_set_range(cursor->pmacurs, key);
if (op == DB_SET || op == DB_GET_BOTH)
r = toku_pma_cursor_set_both(cursor->pmacurs, key, val);
else if (op == DB_SET_RANGE /* || op == DB_GET_BOTH_RANGE */ )
r = toku_pma_cursor_set_range_both(cursor->pmacurs, key, val);
else
assert(0);
if (r != 0) {
int rr = toku_pma_cursor_free(&cursor->pmacurs);
assert(rr == 0);
......@@ -2919,7 +2880,7 @@ int toku_brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags, TOKUT
case DB_SET:
r = unpin_cursor(cursor);
assert(r == 0);
r = brtcurs_set_key(cursor, *rootp, kbt, vbt, DB_SET, txn, null_brtnode);
r = brtcurs_set_search(cursor, *rootp, DB_SET, kbt, 0, txn, null_brtnode);
if (r != 0) goto died0;
r = toku_pma_cursor_get_current(cursor->pmacurs, 0, vbt, 0);
if (r != 0) goto died0;
......@@ -2927,13 +2888,13 @@ int toku_brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags, TOKUT
case DB_GET_BOTH:
r = unpin_cursor(cursor);
assert(r == 0);
r = brtcurs_set_key(cursor, *rootp, kbt, vbt, DB_GET_BOTH, txn, null_brtnode);
r = brtcurs_set_search(cursor, *rootp, DB_GET_BOTH, kbt, vbt, txn, null_brtnode);
if (r != 0) goto died0;
break;
case DB_SET_RANGE:
r = unpin_cursor(cursor);
assert(r == 0);
r = brtcurs_set_range(cursor, *rootp, kbt, txn, null_brtnode);
r = brtcurs_set_search(cursor, *rootp, DB_SET_RANGE, kbt, 0, txn, null_brtnode);
if (r != 0) goto died0;
r = toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt, 0);
if (r != 0) goto died0;
......
......@@ -1799,7 +1799,7 @@ static void test_pma_cursor_set_key() {
for (i=0; i<n; i += 1) {
k = htonl(i);
toku_fill_dbt(&key, &k, sizeof k);
error = toku_pma_cursor_set_key(cursor, &key);
error = toku_pma_cursor_set_both(cursor, &key, 0);
if (i % 10 == 0) {
assert(error == 0);
toku_init_dbt(&val); val.flags = DB_DBT_MALLOC;
......@@ -1856,7 +1856,7 @@ static void test_pma_cursor_set_range() {
for (i=0; i<100; i += 1) {
k = htonl(i);
toku_fill_dbt(&key, &k, sizeof k);
error = toku_pma_cursor_set_range(cursor, &key);
error = toku_pma_cursor_set_range_both(cursor, &key, 0);
if (error != 0) {
assert(error == DB_NOTFOUND);
assert(i > largest_key);
......@@ -2039,6 +2039,7 @@ static void test_pma_cursor_set_both() {
error = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, n * (8 + sizeof (int) + sizeof (int)));
assert(error == 0);
error = toku_pma_set_dup_compare(pma, toku_default_compare_fun); assert(error == 0);
PMA_CURSOR cursor;
error = toku_pma_cursor(pma, &cursor, &skey, &sval);
......@@ -2184,7 +2185,7 @@ static void test_dup_key_insert(int n) {
k = htonl(2);
toku_fill_dbt(&key, &k, sizeof k);
r = toku_pma_cursor_set_key(cursor, &key);
r = toku_pma_cursor_set_both(cursor, &key, 0);
if (r != 0) {
assert(n == 0);
} else {
......@@ -2376,7 +2377,7 @@ static void test_dupsort_key_insert(int n, int dup_data) {
assert(r == 0);
toku_fill_dbt(&key, &k, sizeof k);
r = toku_pma_cursor_set_key(cursor, &key);
r = toku_pma_cursor_set_both(cursor, &key, 0);
if (r != 0) {
assert(n == 0);
} else {
......
......@@ -70,8 +70,6 @@ static void __pma_delete_resume(PMA pma, int here);
*/
static int __pma_count_cursor_refs(PMA pma, int here);
static int __pma_compare_kv(PMA pma, struct kv_pair *a, struct kv_pair *b);
/**************************** end of static functions forward declarations. *********************/
......@@ -262,8 +260,25 @@ void toku_pma_show_stats (void) {
printf("%d finds, %d divides, %d scans\n", pma_count_finds, pma_count_divides, pma_count_scans);
}
static int pma_compare_kv_kv(PMA pma, struct kv_pair *a, struct kv_pair *b) {
DBT dbta, dbtb;;
int cmp = pma->compare_fun(pma->db, toku_fill_dbt(&dbta, kv_pair_key(a), kv_pair_keylen(a)), toku_fill_dbt(&dbtb, kv_pair_key(b), kv_pair_keylen(b)));
if (cmp == 0 && (pma->dup_mode & TOKU_DB_DUPSORT)) {
cmp = pma->dup_compare_fun(pma->db, toku_fill_dbt(&dbta, kv_pair_val(a), kv_pair_vallen(b)), toku_fill_dbt(&dbtb, kv_pair_val(b), kv_pair_vallen(b)));
}
return cmp;
}
static int pma_compare_dbt_kv(PMA pma, DBT *k, DBT *v, struct kv_pair *kv) {
DBT k2, v2;
int cmp = pma->compare_fun(pma->db, k, toku_fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
if (cmp == 0 && v)
cmp = pma->dup_compare_fun(pma->db, v, toku_fill_dbt(&v2, kv_pair_val(kv), kv_pair_vallen(kv)));
return cmp;
}
/* search the index for a matching key */
static int __pma_search(PMA pma, DBT *k, int lo, int hi, int *found) {
static unsigned int __pma_search(PMA pma, DBT *k, int lo, int hi, int *found) {
assert(0 <= lo && lo <= hi);
if (lo >= hi) {
*found = 0;
......@@ -276,9 +291,7 @@ static int __pma_search(PMA pma, DBT *k, int lo, int hi, int *found) {
mi++;
if (mi >= hi)
return __pma_search(pma, k, lo, omi, found);
struct kv_pair *kv = kv_pair_ptr(pma->pairs[mi]);
DBT k2;
int cmp = pma->compare_fun(pma->db, k, toku_fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
int cmp = pma_compare_dbt_kv(pma, k, 0, kv_pair_ptr(pma->pairs[mi]));
if (cmp > 0)
return __pma_search(pma, k, mi+1, hi, found);
if (cmp < 0)
......@@ -289,7 +302,7 @@ static int __pma_search(PMA pma, DBT *k, int lo, int hi, int *found) {
}
/* search the index for the rightmost matching key */
static int __pma_right_search(PMA pma, DBT *k, int lo, int hi, int *found) {
static unsigned int pma_right_search(PMA pma, DBT *k, DBT *v, int lo, int hi, int *found) {
assert(0 <= lo && lo <= hi);
if (lo >= hi) {
*found = 0;
......@@ -301,18 +314,16 @@ static int __pma_right_search(PMA pma, DBT *k, int lo, int hi, int *found) {
while (mi < hi && !kv_pair_inuse(pma->pairs[mi]))
mi++;
if (mi >= hi)
return __pma_right_search(pma, k, lo, omi, found);
struct kv_pair *kv = kv_pair_ptr(pma->pairs[mi]);
DBT k2;
int cmp = pma->compare_fun(pma->db, k, toku_fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
return pma_right_search(pma, k, v, lo, omi, found);
int cmp = pma_compare_dbt_kv(pma, k, v, kv_pair_ptr(pma->pairs[mi]));
if (cmp > 0)
return __pma_right_search(pma, k, mi+1, hi, found);
return pma_right_search(pma, k, v, mi+1, hi, found);
if (cmp < 0)
return __pma_right_search(pma, k, lo, mi, found);
return pma_right_search(pma, k, v, lo, mi, found);
/* we have a match, try to find a match on the right tree */
int here;
here = __pma_right_search(pma, k, mi+1, hi, found);
here = pma_right_search(pma, k, v, mi+1, hi, found);
if (*found == 0)
here = mi;
*found = 1;
......@@ -321,7 +332,7 @@ static int __pma_right_search(PMA pma, DBT *k, int lo, int hi, int *found) {
}
/* search the index for the left most matching key */
static unsigned int pma_left_search(PMA pma, DBT *k, int lo, int hi, int *found) {
static unsigned int pma_left_search(PMA pma, DBT *k, DBT *v, int lo, int hi, int *found) {
assert(0 <= lo && lo <= hi);
if (lo >= hi) {
*found = 0;
......@@ -333,52 +344,16 @@ static unsigned int pma_left_search(PMA pma, DBT *k, int lo, int hi, int *found)
while (mi < hi && !kv_pair_inuse(pma->pairs[mi]))
mi++;
if (mi >= hi)
return pma_left_search(pma, k, lo, omi, found);
struct kv_pair *kv = kv_pair_ptr(pma->pairs[mi]);
DBT k2;
int cmp = pma->compare_fun(pma->db, k, toku_fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
return pma_left_search(pma, k, v, lo, omi, found);
int cmp = pma_compare_dbt_kv(pma, k, v, kv_pair_ptr(pma->pairs[mi]));
if (cmp > 0)
return pma_left_search(pma, k, mi+1, hi, found);
return pma_left_search(pma, k, v, mi+1, hi, found);
if (cmp < 0)
return pma_left_search(pma, k, lo, mi, found);
return pma_left_search(pma, k, v, lo, mi, found);
/* we have a match, try to find a match on the left tree */
int here;
here = pma_left_search(pma, k, lo, mi, found);
if (*found == 0)
here = mi;
*found = 1;
return here;
}
}
/* search the index for the right most matching key and value */
static int __pma_dup_search(PMA pma, DBT *k, DBT *v, int lo, int hi, int *found) {
assert(0 <= lo && lo <= hi);
if (lo >= hi) {
*found = 0;
return lo;
} else {
int mi = (lo + hi)/2;
assert(lo <= mi && mi < hi);
int omi = mi;
while (mi < hi && !kv_pair_inuse(pma->pairs[mi]))
mi++;
if (mi >= hi)
return __pma_dup_search(pma, k, v, lo, omi, found);
struct kv_pair *kv = kv_pair_ptr(pma->pairs[mi]);
DBT k2, v2;
int cmp = pma->compare_fun(pma->db, k, toku_fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
if (cmp == 0)
cmp = pma->dup_compare_fun(pma->db, v, toku_fill_dbt(&v2, kv_pair_val(kv), kv_pair_vallen(kv)));
if (cmp > 0)
return __pma_dup_search(pma, k, v, mi+1, hi, found);
if (cmp < 0)
return __pma_dup_search(pma, k, v, lo, mi, found);
/* we have a match, try to find a match on the right tree */
int here;
here = __pma_dup_search(pma, k, v, mi+1, hi, found);
here = pma_left_search(pma, k, v, lo, mi, found);
if (*found == 0)
here = mi;
*found = 1;
......@@ -432,24 +407,10 @@ int toku_pmainternal_find (PMA pma, DBT *k) {
assert(0<=lo);
assert(lo==hi);
assert((unsigned)hi <= toku_pma_index_limit(pma));
#if 0
/* If lo points at something, the something should not be smaller than key. */
if (lo>0 && lo < toku_pma_index_limit(pma) && pma->pairs[lo]) {
//printf("lo=%d\n", lo);
DBT k2;
assert(0 >= pma->compare_fun(db, k, toku_fill_dbt(&k2, pma->pairs[lo]->key, pma->pairs[lo]->keylen)));
}
#endif
return lo;
#else
int found, lo;
lo = __pma_search(pma, k, db, 0, pma->N, &found);
if (lo>0 && lo < toku_pma_index_limit(pma) && pma->pairs[lo]) {
//printf("lo=%d\n", lo);
DBT k2;
assert(0 >= pma->compare_fun(db, k, toku_fill_dbt(&k2, pma->pairs[lo]->key, pma->pairs[lo]->keylen)));
}
int found;
int lo = __pma_search(pma, k, 0, pma->N, &found);
return lo;
#endif
}
......@@ -694,7 +655,6 @@ int toku_pma_set_dup_mode(PMA pma, int dup_mode) {
}
int toku_pma_set_dup_compare(PMA pma, pma_compare_fun_t dup_compare_fun) {
assert(pma->dup_mode & TOKU_DB_DUPSORT);
pma->dup_compare_fun = dup_compare_fun;
return 0;
}
......@@ -798,67 +758,30 @@ int toku_pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val, int even_delet
return 0;
}
int toku_pma_cursor_set_key(PMA_CURSOR c, DBT *key) {
PMA pma = c->pma;
unsigned int here;
int found;
if (pma->dup_mode & TOKU_DB_DUP) {
here = pma_left_search(pma, key, 0, pma->N, &found);
} else
here = toku_pmainternal_find(pma, key);
assert(here<=toku_pma_index_limit(pma));
int r = DB_NOTFOUND;
if (here < (unsigned)pma->N) {
DBT k2;
struct kv_pair *pair = pma->pairs[here];
if (kv_pair_valid(pair) &&
pma->compare_fun(pma->db, key, toku_fill_dbt(&k2, kv_pair_key(pair), kv_pair_keylen(pair)))==0) {
__pma_delete_resume(c->pma, c->position);
c->position = here;
r = 0;
}
}
return r;
}
int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val) {
PMA pma = c->pma;
unsigned int here; int found;
if (pma->dup_mode & TOKU_DB_DUPSORT)
here = __pma_dup_search(pma, key, val, 0, pma->N, &found);
else
here = toku_pmainternal_find(pma, key);
here = pma_left_search(pma, key, val, 0, pma->N, &found);
assert(here<=toku_pma_index_limit(pma));
int r = DB_NOTFOUND;
if (here < pma->N) {
DBT k2, v2;
struct kv_pair *pair = pma->pairs[here];
if (kv_pair_valid(pair) &&
pma->compare_fun(pma->db, key, toku_fill_dbt(&k2, kv_pair_key(pair), kv_pair_keylen(pair))) == 0 &&
pma->compare_fun(pma->db, val, toku_fill_dbt(&v2, kv_pair_val(pair), kv_pair_vallen(pair))) == 0) {
__pma_delete_resume(c->pma, c->position);
c->position = here;
r = 0;
}
if (found && kv_pair_valid(pma->pairs[here])) {
__pma_delete_resume(c->pma, c->position);
c->position = here;
r = 0;
}
return r;
}
int toku_pma_cursor_set_range(PMA_CURSOR c, DBT *key) {
int toku_pma_cursor_set_range_both(PMA_CURSOR c, DBT *key, DBT *val) {
PMA pma = c->pma;
unsigned int here;
int found;
if (pma->dup_mode & TOKU_DB_DUP)
here = pma_left_search(pma, key, 0, pma->N, &found);
else
here = toku_pmainternal_find(pma, key);
unsigned int here; int found;
here = pma_left_search(pma, key, val, 0, pma->N, &found);
assert(here<=toku_pma_index_limit(pma));
/* find the first valid pair where key[here] >= key */
int r = DB_NOTFOUND;
while (here < pma->N) {
struct kv_pair *pair = pma->pairs[here];
if (kv_pair_valid(pair)) {
if (kv_pair_valid(pma->pairs[here])) {
__pma_delete_resume(c->pma, c->position);
c->position = here;
r = 0;
......@@ -876,11 +799,7 @@ static int pma_next_key(PMA pma, DBT *k, DBT *v, int here, int n, int *found) {
while (here < n && !kv_pair_inuse(pma->pairs[here]))
here += 1;
if (here < n) {
struct kv_pair *kv = kv_pair_ptr(pma->pairs[here]);
DBT k2, v2;
int cmp = pma->compare_fun(pma->db, k, toku_fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
if (cmp == 0 && v)
cmp = pma->dup_compare_fun(pma->db, v, toku_fill_dbt(&v2, kv_pair_val(kv), kv_pair_vallen(kv)));
int cmp = pma_compare_dbt_kv(pma, k, v, kv_pair_ptr(pma->pairs[here]));
if (cmp == 0)
*found = 1;
}
......@@ -894,11 +813,7 @@ static int pma_prev_key(PMA pma, DBT *k, DBT *v, int here, int n, int *found) {
while (0 <= here && !kv_pair_inuse(pma->pairs[here]))
here -= 1;
if (0 <= here) {
struct kv_pair *kv = kv_pair_ptr(pma->pairs[here]);
DBT k2, v2;
int cmp = pma->compare_fun(pma->db, k, toku_fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
if (cmp == 0 && v)
cmp = pma->dup_compare_fun(pma->db, v, toku_fill_dbt(&v2, kv_pair_val(kv), kv_pair_vallen(kv)));
int cmp = pma_compare_dbt_kv(pma, k, v, kv_pair_ptr(pma->pairs[here]));
if (cmp == 0)
*found = 1;
}
......@@ -1045,7 +960,7 @@ enum pma_errors toku_pma_lookup (PMA pma, DBT *k, DBT *v) {
unsigned int here;
int found;
if (pma->dup_mode & TOKU_DB_DUP) {
here = pma_left_search(pma, k, 0, pma->N, &found);
here = pma_left_search(pma, k, 0, 0, pma->N, &found);
} else
here = toku_pmainternal_find(pma, k);
assert(here<=toku_pma_index_limit(pma));
......@@ -1099,10 +1014,10 @@ int toku_pma_insert (PMA pma, DBT *k, DBT *v, TOKUTXN txn, FILENUM filenum, DISK
unsigned int idx;
if (pma->dup_mode & TOKU_DB_DUPSORT) {
idx = __pma_dup_search(pma, k, v, 0, pma->N, &found);
idx = pma_right_search(pma, k, v, 0, pma->N, &found);
if (found) return BRT_ALREADY_THERE;
} else if (pma->dup_mode & TOKU_DB_DUP) {
idx = __pma_right_search(pma, k, 0, pma->N, &found);
idx = pma_right_search(pma, k, 0, 0, pma->N, &found);
if (found) idx += 1;
} else {
idx = toku_pmainternal_find(pma, k);
......@@ -1146,7 +1061,7 @@ static int pma_delete_dup (PMA pma, DBT *k, u_int32_t rand4sem, u_int32_t *finge
/* find the left most matching key in the pma */
int found;
unsigned int lefthere;
lefthere = pma_left_search(pma, k, 0, pma->N, &found);
lefthere = pma_left_search(pma, k, 0, 0, pma->N, &found);
int rightfound = found, righthere = lefthere;
while (rightfound) {
struct kv_pair *kv = pma->pairs[righthere];
......@@ -1288,7 +1203,7 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
unsigned int idx;
int found;
if (pma->dup_mode & TOKU_DB_DUPSORT) {
idx = __pma_dup_search(pma, k, v, 0, pma->N, &found);
idx = pma_right_search(pma, k, v, 0, pma->N, &found);
#if PMA_DUP_DUP
if (found) idx += 1;
#else
......@@ -1297,7 +1212,7 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
}
#endif
} else if (pma->dup_mode & TOKU_DB_DUP) {
idx = __pma_right_search(pma, k, 0, pma->N, &found);
idx = pma_right_search(pma, k, 0, 0, pma->N, &found);
if (found) idx += 1;
} else {
idx = toku_pmainternal_find(pma, k);
......@@ -1464,14 +1379,6 @@ static void __pma_relocate_kvpairs(PMA pma) {
#endif
static int __pma_compare_kv(PMA pma, struct kv_pair *a, struct kv_pair *b) {
DBT dbta, dbtb;
int cmp = pma->compare_fun(pma->db, toku_fill_dbt(&dbta, kv_pair_key(a), kv_pair_keylen(a)), toku_fill_dbt(&dbtb, kv_pair_key(b), kv_pair_keylen(b)));
if (cmp == 0 && (pma->dup_mode & TOKU_DB_DUPSORT)) {
cmp = pma->dup_compare_fun(pma->db, toku_fill_dbt(&dbta, kv_pair_val(a), kv_pair_vallen(b)), toku_fill_dbt(&dbtb, kv_pair_val(b), kv_pair_vallen(b)));
}
return cmp;
}
int toku_pma_split(TOKUTXN txn, FILENUM filenum,
PMA origpma, unsigned int *origpma_size, DBT *splitk,
......@@ -1555,7 +1462,7 @@ int toku_pma_split(TOKUTXN txn, FILENUM filenum,
splitk->size = kv_pair_keylen(a);
}
splitk->flags = BRT_PIVOT_PRESENT_L;
if (spliti < npairs && __pma_compare_kv(origpma, a, pairs[spliti].pair) == 0) {
if (spliti < npairs && pma_compare_kv_kv(origpma, a, pairs[spliti].pair) == 0) {
splitk->flags += BRT_PIVOT_PRESENT_R;
}
}
......
......@@ -107,14 +107,11 @@ int toku_pma_cursor_set_position_prev (PMA_CURSOR c);
it has been deleted previously */
int toku_pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val, int even_deleted);
/* set the cursor to the matching key and value pair */
/* move the cursor to the kv pair matching the key and the val if nonzero*/
int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val);
/* move the cursor to the kv pair matching the key */
int toku_pma_cursor_set_key(PMA_CURSOR c, DBT *key);
/* set the cursor to the smallest key in the pma >= key */
int toku_pma_cursor_set_range(PMA_CURSOR c, DBT *key);
/* set the cursor to the smallest key in the pma >= key and the val if nonzero*/
int toku_pma_cursor_set_range_both(PMA_CURSOR c, DBT *key, DBT *val);
/* delete the key value pair under the cursor, return the size of the pair */
int toku_pma_cursor_delete_under(PMA_CURSOR /*c*/, int */*kvsize*/, u_int32_t /*rand4sem*/, u_int32_t */*fingerprint*/, int */*lastkeymatch*/);
......
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