Commit c71ab0c0 authored by Rich Prohaska's avatar Rich Prohaska

fix the cursor first last deleted pair problem

git-svn-id: file:///svn/tokudb@288 c7de825b-a66e-492c-adef-691d508d4ae1
parent 7ac29707
...@@ -1433,12 +1433,110 @@ void test_pma_double_delete() { ...@@ -1433,12 +1433,110 @@ void test_pma_double_delete() {
assert(error == 0); assert(error == 0);
} }
void test_pma_cursor_first_delete_last() {
printf("test_pma_cursor_first_delete_last\n");
int error;
PMA pma;
error = pma_create(&pma, default_compare_fun);
assert(error == 0);
DBT key, val;
int k, v;
int i;
for (i=1; i<=2; i++) {
k = htonl(i);
v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = pma_insert(pma, &key, &val, 0);
assert(error == 0);
}
assert(pma_n_entries(pma) == 2);
PMA_CURSOR pmacursor;
error = pma_cursor(pma, &pmacursor);
assert(error == 0);
error = pma_cursor_set_position_first(pmacursor);
assert(error == 0);
k = htonl(1);
fill_dbt(&key, &k, sizeof k);
error = pma_delete(pma, &key, 0);
assert(error == 0);
assert(pma_n_entries(pma) == 2);
error = pma_cursor_set_position_last(pmacursor);
assert(error == 0);
assert(pma_n_entries(pma) == 1);
error = pma_cursor_free(&pmacursor);
assert(error == 0);
error = pma_free(&pma);
assert(error == 0);
}
void test_pma_cursor_last_delete_first() {
printf("test_pma_cursor_last_delete_first\n");
int error;
PMA pma;
error = pma_create(&pma, default_compare_fun);
assert(error == 0);
DBT key, val;
int k, v;
int i;
for (i=1; i<=2; i++) {
k = htonl(i);
v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = pma_insert(pma, &key, &val, 0);
assert(error == 0);
}
assert(pma_n_entries(pma) == 2);
PMA_CURSOR pmacursor;
error = pma_cursor(pma, &pmacursor);
assert(error == 0);
error = pma_cursor_set_position_last(pmacursor);
assert(error == 0);
k = htonl(2);
fill_dbt(&key, &k, sizeof k);
error = pma_delete(pma, &key, 0);
assert(error == 0);
assert(pma_n_entries(pma) == 2);
error = pma_cursor_set_position_first(pmacursor);
assert(error == 0);
assert(pma_n_entries(pma) == 1);
error = pma_cursor_free(&pmacursor);
assert(error == 0);
error = pma_free(&pma);
assert(error == 0);
}
void test_pma_delete() { void test_pma_delete() {
test_pma_delete_shrink(256); memory_check_all_free(); test_pma_delete_shrink(256); memory_check_all_free();
test_pma_delete_random(256); memory_check_all_free(); test_pma_delete_random(256); memory_check_all_free();
test_pma_delete_cursor(32); memory_check_all_free(); test_pma_delete_cursor(32); memory_check_all_free();
test_pma_delete_insert(); memory_check_all_free(); test_pma_delete_insert(); memory_check_all_free();
test_pma_double_delete(); memory_check_all_free(); test_pma_double_delete(); memory_check_all_free();
test_pma_cursor_first_delete_last(); memory_check_all_free();
test_pma_cursor_last_delete_first(); memory_check_all_free();
} }
void test_pma_already_there() { void test_pma_already_there() {
......
...@@ -376,12 +376,21 @@ int pma_cursor_get_pma(PMA_CURSOR c, PMA *pmap) { ...@@ -376,12 +376,21 @@ int pma_cursor_get_pma(PMA_CURSOR c, PMA *pmap) {
int pma_cursor_set_position_last (PMA_CURSOR c) { int pma_cursor_set_position_last (PMA_CURSOR c) {
PMA pma = c->pma; PMA pma = c->pma;
int result = 0;
int old_position = c->position;
c->position=pma->N-1; c->position=pma->N-1;
while (!kv_pair_valid(c->pma->pairs[c->position])) { while (!kv_pair_valid(c->pma->pairs[c->position])) {
if (c->position>0) c->position--; if (c->position>0)
else return DB_NOTFOUND; c->position--;
else {
c->position = -1;
result = DB_NOTFOUND;
break;
}
} }
return 0; if (old_position != c->position)
__pma_delete_resume(pma, old_position);
return result;
} }
int pma_cursor_set_position_prev (PMA_CURSOR c) { int pma_cursor_set_position_prev (PMA_CURSOR c) {
...@@ -401,12 +410,21 @@ int pma_cursor_set_position_prev (PMA_CURSOR c) { ...@@ -401,12 +410,21 @@ int pma_cursor_set_position_prev (PMA_CURSOR c) {
int pma_cursor_set_position_first (PMA_CURSOR c) { int pma_cursor_set_position_first (PMA_CURSOR c) {
PMA pma = c->pma; PMA pma = c->pma;
int result = 0;
int old_position = c->position;
c->position=0; c->position=0;
while (!kv_pair_valid(c->pma->pairs[c->position])) { while (!kv_pair_valid(c->pma->pairs[c->position])) {
if (c->position+1<pma->N) c->position++; if (c->position+1<pma->N)
else return DB_NOTFOUND; c->position++;
else {
c->position = -1;
result =DB_NOTFOUND;
break;
}
} }
return 0; if (old_position != c->position)
__pma_delete_resume(pma, old_position);
return result;
} }
int pma_cursor_set_position_next (PMA_CURSOR c) { int pma_cursor_set_position_next (PMA_CURSOR c) {
......
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