Commit d8ecabcb authored by Rich Prohaska's avatar Rich Prohaska

implement db->del as a lookup followed by a delete to match BDB del return...

implement db->del as a lookup followed by a delete to match BDB del return value.  also implemented a tokutek flag that suppresses the return value.  closes #45

git-svn-id: file:///svn/tokudb@806 c7de825b-a66e-492c-adef-691d508d4ae1
parent cc73c569
......@@ -3,6 +3,7 @@
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <sys/stat.h>
#include <db.h>
......@@ -28,9 +29,9 @@ void db_put(DB *db, int k, int v) {
assert(r == 0);
}
void expect_db_del(DB *db, int k, int expectr) {
void expect_db_del(DB *db, int k, int flags, int expectr) {
DBT key;
int r = db->del(db, 0, dbt_init(&key, &k, sizeof k), 0);
int r = db->del(db, 0, dbt_init(&key, &k, sizeof k), flags);
assert(r == expectr);
}
......@@ -41,12 +42,12 @@ void expect_db_get(DB *db, int k, int expectr) {
}
void test_db_delete(int n, int dup_mode) {
if (verbose) printf("test_rand_insert:%d %d\n", n, dup_mode);
if (verbose) printf("test_db_delete:%d %d\n", n, dup_mode);
DB_ENV * const null_env = 0;
DB *db;
DB_TXN * const null_txn = 0;
const char * const fname = DIR "/" "test.rand.insert.brt";
const char * const fname = DIR "/" "test.db.delete.brt";
int r;
system("rm -rf " DIR);
......@@ -84,12 +85,50 @@ void test_db_delete(int n, int dup_mode) {
db_put(db, htonl(i), i);
for (i=0; i<n; i++) {
expect_db_del(db, htonl(i), 0);
expect_db_del(db, htonl(i), 0, 0);
expect_db_get(db, htonl(i), DB_NOTFOUND);
}
expect_db_del(db, htonl(n), DB_NOTFOUND);
expect_db_del(db, htonl(n), 0, DB_NOTFOUND);
#if USE_TDB
expect_db_del(db, htonl(n), DB_DELETE_ANY, 0);
#endif
#if USE_BDB && defined(DB_DELETE_ANY)
expect_db_del(db, htonl(n), DB_DELETE_ANY, EINVAL);
#endif
r = db->close(db, 0);
assert(r == 0);
}
void test_db_get_datasize0() {
if (verbose) printf("test_db_get_datasize0\n");
DB_ENV * const null_env = 0;
DB *db;
DB_TXN * const null_txn = 0;
const char * const fname = DIR "/" "test.db_delete.brt";
int r;
system("rm -rf " DIR);
r=mkdir(DIR, 0777); assert(r==0);
/* create the dup database file */
r = db_create(&db, null_env, 0);
assert(r == 0);
r = db->set_pagesize(db, 4096);
assert(r == 0);
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666);
assert(r == 0);
int k = 0;
db_put(db, k, 0);
DBT key, val;
r = db->get(db, 0, dbt_init(&key, &k, sizeof k), dbt_init_malloc(&val), 0);
assert(r == 0);
free(val.data);
r = db->close(db, 0);
assert(r == 0);
......@@ -98,6 +137,8 @@ void test_db_delete(int n, int dup_mode) {
int main(int argc, const char *argv[]) {
parse_args(argc, argv);
test_db_get_datasize0();
test_db_delete(0, 0);
int i;
......
......@@ -555,8 +555,18 @@ static int toku_db_cursor(DB * db, DB_TXN * txn, DBC ** c, u_int32_t flags) {
return 0;
}
static int toku_db_del(DB * db, DB_TXN * txn __attribute__ ((unused)), DBT * key, u_int32_t flags __attribute((unused))) {
int r = brt_delete(db->i->brt, key);
static int toku_db_del(DB * db, DB_TXN * txn, DBT * key, u_int32_t flags) {
int r;
/* DB_DELETE_ANY supresses the BDB DB->del return value indicating that the key was not found prior to the delete */
if (!(flags & DB_DELETE_ANY)) {
DBT search_val; memset(&search_val, 0, sizeof search_val);
search_val.flags = DB_DBT_MALLOC;
r = db->get(db, txn, key, &search_val, 0);
if (r != 0)
return r;
free(search_val.data);
}
r = brt_delete(db->i->brt, key);
return r;
}
......
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