Commit a98f0cd1 authored by Rich Prohaska's avatar Rich Prohaska

change the db->put to require flags != 0. closes #180

git-svn-id: file:///svn/tokudb@1217 c7de825b-a66e-492c-adef-691d508d4ae1
parent 683fd63c
#include <stdlib.h>
#include <stdint.h>
#ifndef DB_YESOVERWRITE
#define DB_YESOVERWRITE 0
#endif
int verbose=0;
#define CKERR(r) ({ if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0); })
......
......@@ -6,6 +6,7 @@
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <db.h>
......@@ -66,7 +67,7 @@ void test_cursor_delete(int dup_mode) {
int k = htonl(dup_mode & DB_DUP ? 1 : i);
int v = htonl(i);
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0); assert(r == 0);
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_YESOVERWRITE); assert(r == 0);
}
/* verify the sort order with a cursor */
......@@ -112,11 +113,19 @@ void test_cursor_delete_dupsort() {
int k = htonl(1);
int v = htonl(1);
DBT key, val;
#if USE_BDB
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
if (i == 0)
assert(r == 0);
else
assert(r == DB_KEYEXIST);
#endif
#if USE_TDB
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == EINVAL);
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_YESOVERWRITE);
assert(r == 0);
#endif
}
/* verify the sort order with a cursor */
......
......@@ -45,11 +45,11 @@ void insert() {
dbt_init(&key, "key", sizeof("key"));
dbt_init(&value, "value1", sizeof("value1"));
r = db->put(db, null_txn, &key, &value, 0); CKERR(r);
r = db->put(db, null_txn, &key, &value, DB_YESOVERWRITE); CKERR(r);
dbt_init(&key, "key", sizeof("key"));
dbt_init(&value, "value2", sizeof("value2"));
r = db->put(db, null_txn, &key, &value, 0); CKERR(r);
r = db->put(db, null_txn, &key, &value, DB_YESOVERWRITE); CKERR(r);
}
void cursor_range_with_delete(u_int32_t flag) {
......
......@@ -12,7 +12,12 @@
#include "test.h"
void db_put(DB *db, int k, int v) {
DB_TXN * const null_txn = 0;
DBT key, val;
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_YESOVERWRITE);
assert(r == 0);
}
void expect(DBC *cursor, int k, int v) {
DBT key, val;
......@@ -61,9 +66,7 @@ void test_dup_delete(int n, int dup_mode) {
continue;
int k = htonl(i);
int v = htonl(n+i);
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
}
/* reopen the database to force nonleaf buffering */
......@@ -82,10 +85,9 @@ void test_dup_delete(int n, int dup_mode) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = htonl(n+i);
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
DBT key, val;
r = db->get(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init_malloc(&val), 0);
assert(r == 0);
int vv;
......@@ -155,9 +157,7 @@ void test_dup_delete_delete(int n) {
continue;
int k = htonl(i);
int v = i;
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
}
/* reopen the database to force nonleaf buffering */
......@@ -176,9 +176,7 @@ void test_dup_delete_delete(int n) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = i;
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
}
/* delete the dup key */
......@@ -239,9 +237,7 @@ void test_dup_delete_insert(int n, int dup_mode) {
continue;
int k = htonl(i);
int v = i;
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
}
/* reopen the database to force nonleaf buffering */
......@@ -260,10 +256,9 @@ void test_dup_delete_insert(int n, int dup_mode) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = htonl(i);
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
DBT key, val;
r = db->get(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init_malloc(&val), 0);
assert(r == 0);
int vv;
......@@ -282,10 +277,9 @@ void test_dup_delete_insert(int n, int dup_mode) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = htonl(i);
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
DBT key, val;
r = db->get(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init_malloc(&val), 0);
assert(r == 0);
int vv;
......@@ -343,9 +337,7 @@ void test_all_dup_delete_insert(int n) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = i;
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
}
/* reopen the database to force nonleaf buffering */
......@@ -364,9 +356,7 @@ void test_all_dup_delete_insert(int n) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = n+i;
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
}
DBT key; int k = htonl(n/2);
......@@ -377,9 +367,7 @@ void test_all_dup_delete_insert(int n) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = 2*n+i;
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
}
DBC *cursor;
......@@ -423,9 +411,7 @@ void test_walk_empty(int n, int dup_mode) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = htonl(i);
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
}
/* reopen the database to force nonleaf buffering */
......@@ -444,9 +430,7 @@ void test_walk_empty(int n, int dup_mode) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = htonl(n+i);
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
}
{
......@@ -499,10 +483,9 @@ void test_icdi_search(int n, int dup_mode) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = htonl(i);
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
DBT key, val;
r = db->get(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init_malloc(&val), 0);
assert(r == 0);
int vv;
......@@ -533,10 +516,9 @@ void test_icdi_search(int n, int dup_mode) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = htonl(n+i);
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
DBT key, val;
r = db->get(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init_malloc(&val), 0);
assert(r == 0);
int vv;
......@@ -588,10 +570,9 @@ void test_ici_search(int n, int dup_mode) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = htonl(i);
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
DBT key, val;
r = db->get(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init_malloc(&val), 0);
assert(r == 0);
int vv;
......@@ -617,10 +598,9 @@ void test_ici_search(int n, int dup_mode) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = htonl(n+i);
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db,k, v);
DBT key, val;
r = db->get(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init_malloc(&val), 0);
assert(r == 0);
int vv;
......@@ -645,13 +625,6 @@ void test_ici_search(int n, int dup_mode) {
assert(r == 0);
}
void db_insert(DB *db, int k, int v) {
DB_TXN * const null_txn = 0;
DBT key, val;
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
}
void expect_db_lookup(DB *db, int k, int v) {
DB_TXN * const null_txn = 0;
DBT key, val;
......@@ -687,14 +660,14 @@ void test_i0i1ci0_search(int n, int dup_mode) {
assert(r == 0);
/* insert <0,0> */
db_insert(db, 0, 0);
db_put(db, 0, 0);
/* insert n duplicates */
int i;
for (i=0; i<n; i++) {
int k = htonl(1);
int v = htonl(i);
db_insert(db, k, v);
db_put(db, k, v);
expect_db_lookup(db, k, htonl(0));
}
......@@ -711,7 +684,7 @@ void test_i0i1ci0_search(int n, int dup_mode) {
assert(r == 0);
/* insert <0,1> */
db_insert(db, 0, 1);
db_put(db, 0, 1);
/* verify dup search digs deep into the tree */
expect_db_lookup(db, 0, 0);
......
......@@ -12,7 +12,12 @@
#include "test.h"
void db_put(DB *db, int k, int v) {
DB_TXN * const null_txn = 0;
DBT key, val;
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_YESOVERWRITE);
assert(r == 0);
}
void expect(DBC *cursor, int k, int v) {
DBT key, val;
......@@ -72,18 +77,14 @@ void test_insert(int n, int dup_mode) {
continue;
int k = htonl(i);
int v = values[i];
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
}
/* insert n duplicates */
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = values[i];
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
}
/* verify lookups */
......@@ -175,9 +176,7 @@ void test_nonleaf_insert(int n, int dup_mode) {
continue;
int k = htonl(i);
int v = values[i];
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
db_put(db, k, v);
}
/* reopen the database to force nonleaf buffering */
......@@ -196,9 +195,7 @@ void test_nonleaf_insert(int n, int dup_mode) {
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = values[i];
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
CKERR(r);
db_put(db, k, v);
}
/* verify lookups */
......
......@@ -23,7 +23,7 @@ DBT *dbt_init_zero(DBT *dbt) {
void db_put(DB *db, int k, int v) {
DB_TXN * const null_txn = 0;
DBT key, val;
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_YESOVERWRITE);
assert(r == 0);
}
......
......@@ -17,7 +17,7 @@
void db_put(DB *db, int k, int v) {
DB_TXN * const null_txn = 0;
DBT key, val;
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_YESOVERWRITE);
assert(r == 0);
}
......
......@@ -17,7 +17,7 @@
void db_put(DB *db, int k, int v) {
DB_TXN * const null_txn = 0;
DBT key, val;
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_YESOVERWRITE);
assert(r == 0);
}
......
......@@ -17,7 +17,7 @@
void db_put(DB *db, int k, int v) {
DB_TXN * const null_txn = 0;
DBT key, val;
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_YESOVERWRITE);
assert(r == 0);
}
......
......@@ -17,7 +17,7 @@
void db_put(DB *db, int k, int v) {
DB_TXN * const null_txn = 0;
DBT key, val;
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_YESOVERWRITE);
assert(r == 0);
}
......
......@@ -17,7 +17,7 @@
void db_put(DB *db, int k, int v) {
DB_TXN * const null_txn = 0;
DBT key, val;
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_YESOVERWRITE);
assert(r == 0);
}
......
......@@ -22,7 +22,7 @@ void test_get (int dup_mode) {
r = db->set_flags(db, dup_mode); assert(r == 0);
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666); assert(r == 0);
dbt_init(&key, "a", 2);
r = db->put(db, null_txn, &key, dbt_init(&data, "b", 2), 0); assert(r==0);
r = db->put(db, null_txn, &key, dbt_init(&data, "b", 2), DB_YESOVERWRITE); assert(r==0);
memset(&data, 0, sizeof(data));
r = db->get(db, null_txn, &key, &data, 0); assert(r == 0);
assert(strcmp(data.data, "b")==0);
......
......@@ -36,7 +36,7 @@ void test_insert_delete_insert(int dup_mode) {
int k = htonl(1), v = 2;
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_YESOVERWRITE);
assert(r == 0);
r = cursor->c_get(cursor, dbt_init(&key, &k, sizeof k), dbt_init_malloc(&val), DB_SET);
......@@ -51,7 +51,7 @@ void test_insert_delete_insert(int dup_mode) {
if (key.data) free(key.data);
if (val.data) free(val.data);
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_YESOVERWRITE);
assert(r == 0);
r = cursor->c_get(cursor, dbt_init_malloc(&key), dbt_init_malloc(&val), DB_CURRENT);
......
......@@ -12,8 +12,6 @@
#include "test.h"
void test_key_size_limit(int dup_mode) {
if (verbose) printf("test_key_size_limit:%d\n", dup_mode);
......@@ -50,7 +48,7 @@ void test_key_size_limit(int dup_mode) {
memset(v, 0, vs);
memcpy(v, &vs, sizeof vs);
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, k, ks), dbt_init(&val, v, vs), 0);
r = db->put(db, null_txn, dbt_init(&key, k, ks), dbt_init(&val, v, vs), DB_YESOVERWRITE);
if (r == 0) {
bigest = mi;
lo = mi+1;
......
......@@ -1291,10 +1291,15 @@ static int toku_db_put_noassociate(DB * db, DB_TXN * txn, DBT * key, DBT * data,
/* no other flags are currently supported */
return EINVAL;
} else {
assert(flags == 0);
if (brtflags & TOKU_DB_DUPSORT) {
#if TDB_EQ_BDB
r = toku_db_get_noassociate(db, txn, key, data, DB_GET_BOTH);
if (r == 0)
return DB_KEYEXIST;
#else
return EINVAL;
#endif
}
}
......
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