Commit 987de2be authored by Rich Prohaska's avatar Rich Prohaska

simplify the cursor delete since the pivot flags are gone. addresses #250

git-svn-id: file:///svn/tokudb@1588 c7de825b-a66e-492c-adef-691d508d4ae1
parent 57aef552
......@@ -2647,7 +2647,7 @@ int toku_brt_cursor_delete(BRT_CURSOR cursor, int flags __attribute__((__unused_
BRTNODE node = cursor->path[cursor->path_len-1];
assert(node->height == 0);
int kvsize;
r = toku_pma_cursor_delete_under(cursor->pmacurs, &kvsize, node->rand4fingerprint, &node->local_fingerprint, 0);
r = toku_pma_cursor_delete_under(cursor->pmacurs, &kvsize, node->rand4fingerprint, &node->local_fingerprint);
if (r == 0) {
node->u.l.n_bytes_in_buffer -= PMA_ITEM_OVERHEAD + KEY_VALUE_OVERHEAD + kvsize;
node->dirty = 1;
......
......@@ -2000,10 +2000,10 @@ static void test_pma_cursor_delete_under() {
PMA_CURSOR cursor;
error = toku_pma_cursor(pma, &cursor, &skey, &sval); assert(error == 0);
int kvsize, lastkey;
int kvsize;
/* delete under an uninitialized cursor should fail */
error = toku_pma_cursor_delete_under(cursor, &kvsize, rand4fingerprint, &expect_fingerprint, 0);
error = toku_pma_cursor_delete_under(cursor, &kvsize, rand4fingerprint, &expect_fingerprint);
assert(error == DB_NOTFOUND);
int k, v;
......@@ -2035,11 +2035,11 @@ static void test_pma_cursor_delete_under() {
toku_free(val.data);
/* delete under should succeed */
error = toku_pma_cursor_delete_under(cursor, &kvsize, rand4fingerprint, &expect_fingerprint, &lastkey);
assert(error == 0 && lastkey);
error = toku_pma_cursor_delete_under(cursor, &kvsize, rand4fingerprint, &expect_fingerprint);
assert(error == 0);
/* 2nd delete under should fail */
error = toku_pma_cursor_delete_under(cursor, &kvsize, rand4fingerprint, &expect_fingerprint, 0);
error = toku_pma_cursor_delete_under(cursor, &kvsize, rand4fingerprint, &expect_fingerprint);
assert(error == DB_NOTFOUND);
}
assert(i == n);
......@@ -2068,10 +2068,10 @@ static void test_pma_cursor_delete_under_mode(int n, int dup_mode) {
PMA_CURSOR cursor;
error = toku_pma_cursor(pma, &cursor, &skey, &sval); assert(error == 0);
int kvsize, lastkey;
int kvsize;
/* delete under an uninitialized cursor should fail */
error = toku_pma_cursor_delete_under(cursor, &kvsize, rand4fingerprint, &expect_fingerprint, &lastkey);
error = toku_pma_cursor_delete_under(cursor, &kvsize, rand4fingerprint, &expect_fingerprint);
assert(error == DB_NOTFOUND);
int k, v;
......@@ -2109,12 +2109,11 @@ static void test_pma_cursor_delete_under_mode(int n, int dup_mode) {
toku_free(val.data);
/* delete under should succeed */
error = toku_pma_cursor_delete_under(cursor, &kvsize, rand4fingerprint, &expect_fingerprint, &lastkey);
error = toku_pma_cursor_delete_under(cursor, &kvsize, rand4fingerprint, &expect_fingerprint);
assert(error == 0);
if (i == 0 || i >= n-2) assert(lastkey);
/* 2nd delete under should fail */
error = toku_pma_cursor_delete_under(cursor, &kvsize, rand4fingerprint, &expect_fingerprint, &lastkey);
error = toku_pma_cursor_delete_under(cursor, &kvsize, rand4fingerprint, &expect_fingerprint);
assert(error == DB_NOTFOUND);
}
assert(i == n);
......
......@@ -770,6 +770,7 @@ static int pma_next_key(PMA pma, DBT *k, DBT *v, int here, int n, int *found) {
return here;
}
#if 0 /* not used yet */
/* find the previous matching key in the pma starting from index here */
static int pma_prev_key(PMA pma, DBT *k, DBT *v, int here, int n, int *found) {
assert(here < n);
......@@ -783,6 +784,7 @@ static int pma_prev_key(PMA pma, DBT *k, DBT *v, int here, int n, int *found) {
}
return here;
}
#endif
int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val) {
PMA pma = c->pma;
......@@ -821,47 +823,7 @@ int toku_pma_cursor_set_range_both(PMA_CURSOR c, DBT *key, DBT *val) {
return r;
}
/* set lastkeymatch if the kv pair under the cursor is the last one in the pma
compare with the next and previous valid pma entries */
static void pma_cursor_key_last(PMA_CURSOR c, int *lastkeymatch) {
*lastkeymatch = 1;
PMA pma = c->pma;
if (pma->dup_mode & TOKU_DB_DUPSORT) {
int here, found;
/* get the current key */
here = c->position; assert(0 <= here && here < (int) pma->N);
struct kv_pair *kv = kv_pair_ptr(pma->pairs[here]);
DBT currentkey; toku_fill_dbt(&currentkey, kv_pair_key(kv), kv_pair_keylen(kv));
DBT currentval; toku_fill_dbt(&currentval, kv_pair_val(kv), kv_pair_vallen(kv));
/* check if the next key == current key */
here = c->position+1;
for (;;) {
here = pma_next_key(pma, &currentkey, &currentval, here, pma->N, &found);
if (!found) break;
if (kv_pair_valid(pma->pairs[here])) {
*lastkeymatch = 0; /* next key == current key */
return;
}
}
/* check if the prev key == current key */
here = c->position-1;
for (;;) {
here = pma_prev_key(pma, &currentkey, &currentval, here, pma->N, &found);
if (!found) break;
if (kv_pair_valid(pma->pairs[here])) {
*lastkeymatch = 0; /* prev key == current key */
return;
}
}
}
}
int toku_pma_cursor_delete_under(PMA_CURSOR c, int *kvsize, u_int32_t rand4sem, u_int32_t *fingerprint, int *lastkeymatch) {
int toku_pma_cursor_delete_under(PMA_CURSOR c, int *kvsize, u_int32_t rand4sem, u_int32_t *fingerprint) {
int r = DB_NOTFOUND;
if (c->position >= 0) {
PMA pma = c->pma;
......@@ -873,8 +835,6 @@ int toku_pma_cursor_delete_under(PMA_CURSOR c, int *kvsize, u_int32_t rand4sem,
*fingerprint -= rand4sem*toku_calccrc32_kvpair (kv_pair_key_const(kv), kv_pair_keylen(kv), kv_pair_val_const(kv), kv_pair_vallen(kv));
pma->pairs[c->position] = kv_pair_set_deleted(kv);
r = 0;
if (lastkeymatch)
pma_cursor_key_last(c, lastkeymatch);
}
}
return r;
......
......@@ -119,7 +119,7 @@ int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val);
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*/);
int toku_pma_cursor_delete_under(PMA_CURSOR /*c*/, int */*kvsize*/, u_int32_t /*rand4sem*/, u_int32_t */*fingerprint*/);
int toku_pma_random_pick(PMA, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen);
......
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