Commit 3c2c1699 authored by Rich Prohaska's avatar Rich Prohaska

fix pma double delete and test pma double insert

git-svn-id: file:///svn/tokudb@272 c7de825b-a66e-492c-adef-691d508d4ae1
parent 3c410fd0
......@@ -1388,11 +1388,81 @@ void test_pma_delete_insert() {
assert(error == 0);
}
void test_pma_double_delete() {
printf("test_pma_double_delete\n");
PMA pma;
int error;
error = pma_create(&pma, default_compare_fun);
assert(error == 0);
PMA_CURSOR pmacursor;
error = pma_cursor(pma, &pmacursor);
assert(error == 0);
DBT key, val;
int k, v;
k = 1; v = 1;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = pma_insert(pma, &key, &val, 0);
assert(error == 0);
error = pma_cursor_set_position_first(pmacursor);
assert(error == 0);
assert_cursor_equal(pmacursor, 1);
k = 1;
fill_dbt(&key, &k, sizeof k);
error = pma_delete(pma, &key, 0);
assert(error == 0);
assert_cursor_nokey(pmacursor);
k = 1;
fill_dbt(&key, &k, sizeof k);
error = pma_delete(pma, &key, 0);
assert(error == DB_NOTFOUND);
error = pma_cursor_free(&pmacursor);
assert(error == 0);
error = pma_free(&pma);
assert(error == 0);
}
void test_pma_delete() {
test_pma_delete_shrink(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_insert(); memory_check_all_free();
test_pma_double_delete(); memory_check_all_free();
}
void test_pma_double_insert() {
printf("test_pma_double_insert\n");
int error;
PMA pma;
error = pma_create(&pma, default_compare_fun);
assert(error == 0);
DBT key, val;
int k, v;
k = 1; v = 1;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = pma_insert(pma, &key, &val, 0);
assert(error == 0);
error = pma_insert(pma, &key, &val, 0);
assert(error == BRT_ALREADY_THERE);
error = pma_free(&pma);
assert(error == 0);
}
void pma_tests (void) {
......@@ -1414,6 +1484,7 @@ void pma_tests (void) {
test_pma_bulk_insert(); memory_check_all_free();
test_pma_insert_or_replace(); memory_check_all_free();
test_pma_delete();
test_pma_double_insert(); memory_check_all_free();
}
int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
......
......@@ -603,8 +603,8 @@ int pma_delete (PMA pma, DBT *k, DB *db) {
l = pmainternal_find(pma, k, db);
struct kv_pair *kv = pma->pairs[l];
if (!kv_pair_inuse(kv)) {
printf("%s:%d l=%d r=%d\n", __FILE__, __LINE__, l, DB_NOTFOUND);
if (!kv_pair_valid(kv)) {
if (0) printf("%s:%d l=%d r=%d\n", __FILE__, __LINE__, l, DB_NOTFOUND);
return DB_NOTFOUND;
}
pma->pairs[l] = kv_pair_set_deleted(kv);
......
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