Commit 6d969a29 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Stop passing DB* everywhere. Instead store it in the BRT and PMA structs. Fixes #39.

git-svn-id: file:///svn/tokudb@761 c7de825b-a66e-492c-adef-691d508d4ae1
parent 96339489
......@@ -85,7 +85,7 @@ BRT_INTERNAL_H_INCLUDES = brt-internal.h cachetable.h hashtable.h pma.h brt.h br
key.o: brttypes.h key.h
pma-test.o: $(BRT_INTERNAL_H_INCLUDES) pma-internal.h pma.h list.h mempool.h
pma-test: pma.o memory.o key.o ybt.o log.o mempool.o fingerprint.o brt-serialize.o hashtable.o primes.o log_code.o
pma.o: pma.h yerror.h pma-internal.h memory.h key.h ybt.h brttypes.h log.h ../include/db.h
pma.o: pma.h yerror.h pma-internal.h memory.h key.h ybt.h brttypes.h log.h ../include/db.h log_header.h
ybt.o: ybt.h brttypes.h ../include/db.h
ybt-test: ybt-test.o ybt.o memory.o
ybt-test.o: ybt.h ../include/db.h
......
......@@ -31,7 +31,7 @@ void setup (void) {
int r;
unlink(fname);
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(fname, 0, 1, &t, nodesize, ct, NULL_TXN, toku_default_compare_fun); assert(r==0);
r = open_brt(fname, 0, 1, &t, nodesize, ct, NULL_TXN, toku_default_compare_fun, (DB*)0); assert(r==0);
}
void shutdown (void) {
......@@ -52,7 +52,7 @@ void insert (long long v) {
long_long_to_array(kc, v);
memset(vc, 0, sizeof vc);
long_long_to_array(vc, v);
brt_insert(t, fill_dbt(&kt, kc, keysize), fill_dbt(&vt, vc, valsize), 0, 0);
brt_insert(t, fill_dbt(&kt, kc, keysize), fill_dbt(&vt, vc, valsize), 0);
if (do_verify) toku_cachetable_verify(ct);
}
......
......@@ -98,13 +98,14 @@ struct brt {
unsigned int flags;
int (*compare_fun)(DB*,const DBT*,const DBT*);
int (*dup_compare)(DB*,const DBT*,const DBT*);
DB *db; // To pass to the compare fun
void *skey,*sval; /* Used for DBT return values. */
};
/* serialization code */
void toku_serialize_brtnode_to(int fd, DISKOFF off, DISKOFF size, BRTNODE node);
int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int flags, int nodesize, int (*bt_compare)(DB *, const DBT*, const DBT*), int (*dup_compare)(DB *, const DBT *, const DBT *));
int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int flags, int nodesize, int (*bt_compare)(DB *, const DBT*, const DBT*), int (*dup_compare)(DB *, const DBT *, const DBT *), DB *db, FILENUM filenum);
unsigned int toku_serialize_brtnode_size(BRTNODE node); /* How much space will it take? */
int toku_keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len);
......@@ -189,7 +190,6 @@ struct brt_cmd {
struct brt_cmd_insert_delete {
DBT *key;
DBT *val;
DB *db;
} id;
} u;
};
......@@ -213,4 +213,5 @@ static const BRTNODE null_brtnode=0;
extern u_int32_t toku_calccrc32_kvpair (const void *key, int keylen, const void *val, int vallen);
extern u_int32_t toku_calccrc32_cmd (int type, const void *key, int keylen, const void *val, int vallen);
extern u_int32_t toku_calccrc32_cmdstruct (BRT_CMD *cmd);
#endif
......@@ -44,7 +44,7 @@ void test_serialize(void) {
toku_serialize_brtnode_to(fd, sn.nodesize*20, sn.nodesize, &sn); assert(r==0);
r = toku_deserialize_brtnode_from(fd, nodesize*20, &dn, 0, nodesize, 0, 0);
r = toku_deserialize_brtnode_from(fd, nodesize*20, &dn, 0, nodesize, 0, 0, 0, (FILENUM){0});
assert(r==0);
assert(dn->thisnodename==nodesize*20);
......
......@@ -182,8 +182,9 @@ void toku_serialize_brtnode_to(int fd, DISKOFF off, DISKOFF size, BRTNODE node)
}
int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int flags, int nodesize,
int (*bt_compare)(DB *, const DBT *, const DBT *),
int (*dup_compare)(DB *, const DBT *, const DBT *)) {
int (*bt_compare)(DB *, const DBT *, const DBT *),
int (*dup_compare)(DB *, const DBT *, const DBT *),
DB *db, FILENUM filenum) {
TAGMALLOC(BRTNODE, result);
struct rbuf rc;
int i;
......@@ -342,7 +343,7 @@ int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int fl
} else {
int n_in_buf = rbuf_int(&rc);
result->u.l.n_bytes_in_buffer = 0;
r=toku_pma_create(&result->u.l.buffer, bt_compare, nodesize);
r=toku_pma_create(&result->u.l.buffer, bt_compare, db, filenum, nodesize);
if (r!=0) {
if (0) { died_21: toku_pma_free(&result->u.l.buffer); }
goto died1;
......
......@@ -28,7 +28,7 @@ static void test0 (void) {
assert(r==0);
printf("%s:%d test0\n", __FILE__, __LINE__);
unlink(fname);
r = open_brt(fname, 0, 1, &t, 1024, ct, null_txn, toku_default_compare_fun);
r = open_brt(fname, 0, 1, &t, 1024, ct, null_txn, toku_default_compare_fun, null_db);
assert(r==0);
//printf("%s:%d test0\n", __FILE__, __LINE__);
//printf("%s:%d n_items_malloced=%lld\n", __FILE__, __LINE__, n_items_malloced);
......@@ -50,11 +50,11 @@ static void test1 (void) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
unlink(fname);
r = open_brt(fname, 0, 1, &t, 1024, ct, null_txn, toku_default_compare_fun);
r = open_brt(fname, 0, 1, &t, 1024, ct, null_txn, toku_default_compare_fun, null_db);
assert(r==0);
brt_insert(t, fill_dbt(&k, "hello", 6), fill_dbt(&v, "there", 6), null_db, null_txn);
brt_insert(t, fill_dbt(&k, "hello", 6), fill_dbt(&v, "there", 6), null_txn);
{
r = brt_lookup(t, fill_dbt(&k, "hello", 6), init_dbt(&v), 0);
r = brt_lookup(t, fill_dbt(&k, "hello", 6), init_dbt(&v));
assert(r==0);
assert(strcmp(v.data, "there")==0);
assert(v.size==6);
......@@ -76,7 +76,7 @@ static void test2 (int memcheck) {
memory_check_all_free();
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
unlink(fname);
r = open_brt(fname, 0, 1, &t, 1024, ct, null_txn, toku_default_compare_fun);
r = open_brt(fname, 0, 1, &t, 1024, ct, null_txn, toku_default_compare_fun, null_db);
printf("%s:%d did setup\n", __FILE__, __LINE__);
assert(r==0);
for (i=0; i<2048; i++) {
......@@ -84,7 +84,7 @@ static void test2 (int memcheck) {
char key[100],val[100];
snprintf(key,100,"hello%d",i);
snprintf(val,100,"there%d",i);
brt_insert(t, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), null_db, null_txn);
brt_insert(t, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), null_txn);
//printf("%s:%d did insert %d\n", __FILE__, __LINE__, i);
if (0) {
brt_flush(t);
......@@ -115,14 +115,14 @@ static void test3 (int nodesize, int count, int memcheck) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
gettimeofday(&t0, 0);
unlink(fname);
r = open_brt(fname, 0, 1, &t, nodesize, ct, null_txn, toku_default_compare_fun);
r = open_brt(fname, 0, 1, &t, nodesize, ct, null_txn, toku_default_compare_fun, null_db);
assert(r==0);
for (i=0; i<count; i++) {
char key[100],val[100];
DBT k,v;
snprintf(key,100,"hello%d",i);
snprintf(val,100,"there%d",i);
brt_insert(t, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), null_db, null_txn);
brt_insert(t, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), null_txn);
}
r = close_brt(t); assert(r==0);
r = toku_cachetable_close(&ct); assert(r==0);
......@@ -146,14 +146,14 @@ static void test4 (int nodesize, int count, int memcheck) {
memory_check=memcheck;
memory_check_all_free();
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(fname, 0, 1, &t, nodesize, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(fname, 0, 1, &t, nodesize, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
for (i=0; i<count; i++) {
char key[100],val[100];
int rv = random();
DBT k,v;
snprintf(key,100,"hello%d",rv);
snprintf(val,100,"there%d",i);
brt_insert(t, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), null_db, null_txn);
brt_insert(t, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), null_txn);
}
r = close_brt(t); assert(r==0);
r = toku_cachetable_close(&ct); assert(r==0);
......@@ -178,7 +178,7 @@ static void test5 (void) {
for (i=0; i<limit; i++) values[i]=-1;
unlink(fname);
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(fname, 0, 1, &t, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(fname, 0, 1, &t, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
for (i=0; i<limit/2; i++) {
char key[100],val[100];
int rk = random()%limit;
......@@ -188,7 +188,7 @@ static void test5 (void) {
snprintf(key, 100, "key%d", rk);
snprintf(val, 100, "val%d", rv);
DBT k,v;
brt_insert(t, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), null_db, null_txn);
brt_insert(t, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), null_txn);
}
printf("\n");
for (i=0; i<limit/2; i++) {
......@@ -199,7 +199,7 @@ static void test5 (void) {
if (i%1000==0) printf("r"); fflush(stdout);
snprintf(key, 100, "key%d", rk);
snprintf(valexpected, 100, "val%d", values[rk]);
r = brt_lookup(t, fill_dbt(&k, key, 1+strlen(key)), init_dbt(&v), 0);
r = brt_lookup(t, fill_dbt(&k, key, 1+strlen(key)), init_dbt(&v));
assert(r==0);
assert(v.size==(1+strlen(valexpected)));
assert(memcmp(v.data,valexpected,v.size)==0);
......@@ -221,7 +221,7 @@ static void test_dump_empty_db (void) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
unlink(fname);
r = open_brt(fname, 0, 1, &t, 1024, ct, null_txn, toku_default_compare_fun);
r = open_brt(fname, 0, 1, &t, 1024, ct, null_txn, toku_default_compare_fun, null_db);
assert(r==0);
dump_brt(t);
r = close_brt(t); assert(r==0);
......@@ -241,16 +241,16 @@ static void test_multiple_files_of_size (int size) {
unlink(n1);
memory_check_all_free();
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(n0, 0, 1, &t0, size, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n1, 0, 1, &t1, size, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n0, 0, 1, &t0, size, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
r = open_brt(n1, 0, 1, &t1, size, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
for (i=0; i<10000; i++) {
char key[100],val[100];
DBT k,v;
snprintf(key, 100, "key%d", i);
snprintf(val, 100, "val%d", i);
brt_insert(t0, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), null_db, null_txn);
brt_insert(t0, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), null_txn);
snprintf(val, 100, "Val%d", i);
brt_insert(t1, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), null_db, null_txn);
brt_insert(t1, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), null_txn);
}
//toku_verify_brt(t0);
//dump_brt(t0);
......@@ -265,22 +265,22 @@ static void test_multiple_files_of_size (int size) {
/* Now see if the data is all there. */
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(n0, 0, 0, &t0, 1<<12, ct, null_txn, toku_default_compare_fun);
r = open_brt(n0, 0, 0, &t0, 1<<12, ct, null_txn, toku_default_compare_fun, null_db);
printf("%s:%d r=%d\n", __FILE__, __LINE__,r);
assert(r==0);
r = open_brt(n1, 0, 0, &t1, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n1, 0, 0, &t1, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
for (i=0; i<10000; i++) {
char key[100],val[100];
DBT k,actual;
snprintf(key, 100, "key%d", i);
snprintf(val, 100, "val%d", i);
r=brt_lookup(t0, fill_dbt(&k, key, 1+strlen(key)), init_dbt(&actual), 0);
r=brt_lookup(t0, fill_dbt(&k, key, 1+strlen(key)), init_dbt(&actual));
assert(r==0);
assert(strcmp(val,actual.data)==0);
assert(actual.size==1+strlen(val));
snprintf(val, 100, "Val%d", i);
r=brt_lookup(t1, fill_dbt(&k, key, 1+strlen(key)), init_dbt(&actual), 0);
r=brt_lookup(t1, fill_dbt(&k, key, 1+strlen(key)), init_dbt(&actual));
assert(r==0);
assert(strcmp(val,actual.data)==0);
assert(actual.size==1+strlen(val));
......@@ -310,10 +310,10 @@ static void test_named_db (void) {
unlink(n1);
memory_check_all_free();
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(n0, "db1", 1, &t0, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n0, "db1", 1, &t0, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
brt_insert(t0, fill_dbt(&k, "good", 5), fill_dbt(&v, "day", 4), null_db, null_txn); assert(r==0);
brt_insert(t0, fill_dbt(&k, "good", 5), fill_dbt(&v, "day", 4), null_txn); assert(r==0);
r = close_brt(t0); assert(r==0);
r = toku_cachetable_close(&ct); assert(r==0);
......@@ -321,10 +321,10 @@ static void test_named_db (void) {
memory_check_all_free();
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(n0, "db1", 0, &t0, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n0, "db1", 0, &t0, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
{
r = brt_lookup(t0, fill_dbt(&k, "good", 5), init_dbt(&v), 0);
r = brt_lookup(t0, fill_dbt(&k, "good", 5), init_dbt(&v));
assert(r==0);
assert(v.size==4);
assert(strcmp(v.data,"day")==0);
......@@ -347,11 +347,11 @@ static void test_multiple_dbs (void) {
unlink(n1);
memory_check_all_free();
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(n0, "db1", 1, &t0, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n1, "db2", 1, &t1, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n0, "db1", 1, &t0, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
r = open_brt(n1, "db2", 1, &t1, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
brt_insert(t0, fill_dbt(&k, "good", 5), fill_dbt(&v, "grief", 6), null_db, null_txn); assert(r==0);
brt_insert(t1, fill_dbt(&k, "bad", 4), fill_dbt(&v, "night", 6), null_db, null_txn); assert(r==0);
brt_insert(t0, fill_dbt(&k, "good", 5), fill_dbt(&v, "grief", 6), null_txn); assert(r==0);
brt_insert(t1, fill_dbt(&k, "bad", 4), fill_dbt(&v, "night", 6), null_txn); assert(r==0);
r = close_brt(t0); assert(r==0);
r = close_brt(t1); assert(r==0);
......@@ -360,22 +360,22 @@ static void test_multiple_dbs (void) {
memory_check_all_free();
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(n0, "db1", 0, &t0, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n1, "db2", 0, &t1, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n0, "db1", 0, &t0, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
r = open_brt(n1, "db2", 0, &t1, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
{
r = brt_lookup(t0, fill_dbt(&k, "good", 5), init_dbt(&v), 0);
r = brt_lookup(t0, fill_dbt(&k, "good", 5), init_dbt(&v));
assert(r==0);
assert(v.size==6);
assert(strcmp(v.data,"grief")==0);
r = brt_lookup(t1, fill_dbt(&k, "good", 5), init_dbt(&v), 0);
r = brt_lookup(t1, fill_dbt(&k, "good", 5), init_dbt(&v));
assert(r!=0);
r = brt_lookup(t0, fill_dbt(&k, "bad", 4), init_dbt(&v), 0);
r = brt_lookup(t0, fill_dbt(&k, "bad", 4), init_dbt(&v));
assert(r!=0);
r = brt_lookup(t1, fill_dbt(&k, "bad", 4), init_dbt(&v), 0);
r = brt_lookup(t1, fill_dbt(&k, "bad", 4), init_dbt(&v));
assert(r==0);
assert(v.size==6);
assert(strcmp(v.data,"night")==0);
......@@ -403,7 +403,7 @@ static void test_multiple_dbs_many (void) {
for (i=0; i<MANYN; i++) {
char dbname[20];
snprintf(dbname, 20, "db%d", i);
r = open_brt(name, dbname, 1, &trees[i], 1<<12, ct, null_txn, toku_default_compare_fun);
r = open_brt(name, dbname, 1, &trees[i], 1<<12, ct, null_txn, toku_default_compare_fun, null_db);
assert(r==0);
}
for (i=0; i<MANYN; i++) {
......@@ -411,7 +411,7 @@ static void test_multiple_dbs_many (void) {
DBT kdbt,vdbt;
snprintf(k, 20, "key%d", i);
snprintf(v, 20, "val%d", i);
brt_insert(trees[i], fill_dbt(&kdbt, k, strlen(k)+1), fill_dbt(&vdbt, v, strlen(v)+1), null_db, null_txn);
brt_insert(trees[i], fill_dbt(&kdbt, k, strlen(k)+1), fill_dbt(&vdbt, v, strlen(v)+1), null_txn);
}
for (i=0; i<MANYN; i++) {
r = close_brt(trees[i]); assert(r==0);
......@@ -432,7 +432,7 @@ static void test_multiple_brts_one_db_one_file (void) {
unlink(name);
r = brt_create_cachetable(&ct, 32, ZERO_LSN, NULL_LOGGER); assert(r==0);
for (i=0; i<MANYN; i++) {
r = open_brt(name, 0, (i==0), &trees[i], 1<<12, ct, null_txn, toku_default_compare_fun);
r = open_brt(name, 0, (i==0), &trees[i], 1<<12, ct, null_txn, toku_default_compare_fun, null_db);
assert(r==0);
}
for (i=0; i<MANYN; i++) {
......@@ -440,14 +440,14 @@ static void test_multiple_brts_one_db_one_file (void) {
DBT kb, vb;
snprintf(k, 20, "key%d", i);
snprintf(v, 20, "val%d", i);
brt_insert(trees[i], fill_dbt(&kb, k, strlen(k)+1), fill_dbt(&vb, v, strlen(v)+1), null_db, null_txn);
brt_insert(trees[i], fill_dbt(&kb, k, strlen(k)+1), fill_dbt(&vb, v, strlen(v)+1), null_txn);
}
for (i=0; i<MANYN; i++) {
char k[20],vexpect[20];
DBT kb, vb;
snprintf(k, 20, "key%d", i);
snprintf(vexpect, 20, "val%d", i);
r=brt_lookup(trees[0], fill_dbt(&kb, k, strlen(k)+1), init_dbt(&vb), 0);
r=brt_lookup(trees[0], fill_dbt(&kb, k, strlen(k)+1), init_dbt(&vb));
assert(r==0);
assert(vb.size==1+strlen(vexpect));
assert(strcmp(vb.data, vexpect)==0);
......@@ -475,7 +475,7 @@ static void test_read_what_was_written (void) {
memory_check_all_free();
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(n, 0, 1, &brt, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n, 0, 1, &brt, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
r = close_brt(brt); assert(r==0);
r = toku_cachetable_close(&ct); assert(r==0);
......@@ -483,12 +483,12 @@ static void test_read_what_was_written (void) {
/* Now see if we can read an empty tree in. */
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(n, 0, 0, &brt, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n, 0, 0, &brt, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
/* See if we can put something in it. */
{
DBT k,v;
brt_insert(brt, fill_dbt(&k, "hello", 6), fill_dbt(&v, "there", 6), null_db, null_txn);
brt_insert(brt, fill_dbt(&k, "hello", 6), fill_dbt(&v, "there", 6), null_txn);
}
r = close_brt(brt); assert(r==0);
......@@ -498,11 +498,11 @@ static void test_read_what_was_written (void) {
/* Now see if we can read it in and get the value. */
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(n, 0, 0, &brt, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n, 0, 0, &brt, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
{
DBT k,v;
r = brt_lookup(brt, fill_dbt(&k, "hello", 6), init_dbt(&v), 0);
r = brt_lookup(brt, fill_dbt(&k, "hello", 6), init_dbt(&v));
assert(r==0);
assert(v.size==6);
assert(strcmp(v.data,"there")==0);
......@@ -522,7 +522,7 @@ static void test_read_what_was_written (void) {
int verify_result=toku_verify_brt(brt);;
assert(verify_result==0);
}
brt_insert(brt, fill_dbt(&k, key, strlen(key)+1), fill_dbt(&v, val, strlen(val)+1), null_db, null_txn);
brt_insert(brt, fill_dbt(&k, key, strlen(key)+1), fill_dbt(&v, val, strlen(val)+1), null_txn);
if (i<600) {
int verify_result=toku_verify_brt(brt);
if (verify_result) {
......@@ -535,7 +535,7 @@ static void test_read_what_was_written (void) {
char expectedval[100];
snprintf(key, 100, "key%d", j);
snprintf(expectedval, 100, "val%d", j);
r=brt_lookup(brt, fill_dbt(&k, key, strlen(key)+1), init_dbt(&v), 0);
r=brt_lookup(brt, fill_dbt(&k, key, strlen(key)+1), init_dbt(&v));
if (r!=0) {
printf("%s:%d r=%d on lookup(key=%s) after i=%d\n", __FILE__, __LINE__, r, key, i);
dump_brt(brt);
......@@ -560,7 +560,7 @@ static void test_read_what_was_written (void) {
DBT k,v;
snprintf(key, 100, "key%d", i);
snprintf(expectedval, 100, "val%d", i);
r=brt_lookup(brt, fill_dbt(&k, key, strlen(key)+1), init_dbt(&v), 0);
r=brt_lookup(brt, fill_dbt(&k, key, strlen(key)+1), init_dbt(&v));
if (r!=0) printf("%s:%d r=%d on key=%s\n", __FILE__, __LINE__, r, key);
assert(r==0);
......@@ -574,11 +574,11 @@ static void test_read_what_was_written (void) {
memory_check_all_free();
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(n, 0, 0, &brt, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n, 0, 0, &brt, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
{
DBT k,v;
r = brt_lookup(brt, fill_dbt(&k, "hello", 6), init_dbt(&v), 0);
r = brt_lookup(brt, fill_dbt(&k, "hello", 6), init_dbt(&v));
assert(r==0);
assert(v.size==6);
assert(strcmp(v.data,"there")==0);
......@@ -590,7 +590,7 @@ static void test_read_what_was_written (void) {
DBT k,v;
snprintf(key, 100, "key%d", i);
snprintf(expectedval, 100, "val%d", i);
r=brt_lookup(brt, fill_dbt(&k, key, strlen(key)+1), init_dbt(&v), 0);
r=brt_lookup(brt, fill_dbt(&k, key, strlen(key)+1), init_dbt(&v));
if (r!=0) printf("%s:%d r=%d on key=%s\n", __FILE__, __LINE__, r, key);
assert(r==0);
......@@ -622,17 +622,17 @@ void test_cursor_last_empty(void) {
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
r = open_brt(n, 0, 1, &brt, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n, 0, 1, &brt, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
r = brt_cursor(brt, &cursor); assert(r==0);
init_dbt(&kbt);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
init_dbt(&vbt);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
r = brt_cursor_get(cursor, &kbt, &vbt, DB_LAST, null_db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_LAST, null_txn);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
assert(r==DB_NOTFOUND);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_FIRST, null_db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_FIRST, null_txn);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
assert(r==DB_NOTFOUND);
r = close_brt(brt);
......@@ -654,10 +654,10 @@ void test_cursor_next (void) {
memory_check_all_free();
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
r = open_brt(n, 0, 1, &brt, 1<<12, ct, null_txn, toku_default_compare_fun); assert(r==0);
r = open_brt(n, 0, 1, &brt, 1<<12, ct, null_txn, toku_default_compare_fun, null_db); assert(r==0);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
r = brt_insert(brt, fill_dbt(&kbt, "hello", 6), fill_dbt(&vbt, "there", 6), null_db, null_txn);
r = brt_insert(brt, fill_dbt(&kbt, "byebye", 7), fill_dbt(&vbt, "byenow", 7), null_db, null_txn);
r = brt_insert(brt, fill_dbt(&kbt, "hello", 6), fill_dbt(&vbt, "there", 6), null_txn);
r = brt_insert(brt, fill_dbt(&kbt, "byebye", 7), fill_dbt(&vbt, "byenow", 7), null_txn);
printf("%s:%d calling brt_cursor(...)\n", __FILE__, __LINE__);
r = brt_cursor(brt, &cursor); assert(r==0);
init_dbt(&kbt);
......@@ -666,7 +666,7 @@ void test_cursor_next (void) {
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
printf("%s:%d calling brt_cursor_get(...)\n", __FILE__, __LINE__);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_txn);
printf("%s:%d called brt_cursor_get(...)\n", __FILE__, __LINE__);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
assert(r==0);
......@@ -675,14 +675,14 @@ void test_cursor_next (void) {
assert(vbt.size==7);
assert(memcmp(vbt.data, "byenow", 7)==0);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_txn);
assert(r==0);
assert(kbt.size==6);
assert(memcmp(kbt.data, "hello", 6)==0);
assert(vbt.size==6);
assert(memcmp(vbt.data, "there", 6)==0);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_txn);
assert(r==DB_NOTFOUND);
r = close_brt(brt);
......@@ -734,7 +734,7 @@ static void test_wrongendian_compare (int wrong_p, unsigned int N) {
//printf("%s:%d WRONG=%d\n", __FILE__, __LINE__, wrong_p);
if (0) { // ???? Why is this commented out?
r = open_brt(n, 0, 1, &brt, 1<<20, ct, null_txn, wrong_p ? wrong_compare_fun : toku_default_compare_fun); assert(r==0);
r = open_brt(n, 0, 1, &brt, 1<<20, ct, null_txn, wrong_p ? wrong_compare_fun : toku_default_compare_fun, &nonce_db); assert(r==0);
for (i=1; i<257; i+=255) {
unsigned char a[4],b[4];
b[3] = a[0] = i&255;
......@@ -746,14 +746,14 @@ static void test_wrongendian_compare (int wrong_p, unsigned int N) {
printf("%s:%d insert: %02x%02x%02x%02x -> %02x%02x%02x%02x\n", __FILE__, __LINE__,
((char*)kbt.data)[0], ((char*)kbt.data)[1], ((char*)kbt.data)[2], ((char*)kbt.data)[3],
((char*)vbt.data)[0], ((char*)vbt.data)[1], ((char*)vbt.data)[2], ((char*)vbt.data)[3]);
r = brt_insert(brt, &kbt, &vbt, &nonce_db, null_txn);
r = brt_insert(brt, &kbt, &vbt, null_txn);
assert(r==0);
}
r = brt_cursor(brt, &cursor); assert(r==0);
for (i=0; i<2; i++) {
init_dbt(&kbt); init_dbt(&vbt);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_txn);
assert(r==0);
assert(kbt.size==4 && vbt.size==4);
printf("%s:%d %02x%02x%02x%02x -> %02x%02x%02x%02x\n", __FILE__, __LINE__,
......@@ -767,7 +767,7 @@ static void test_wrongendian_compare (int wrong_p, unsigned int N) {
{
toku_cachetable_verify(ct);
r = open_brt(n, 0, 1, &brt, 1<<20, ct, null_txn, wrong_p ? wrong_compare_fun : toku_default_compare_fun); assert(r==0);
r = open_brt(n, 0, 1, &brt, 1<<20, ct, null_txn, wrong_p ? wrong_compare_fun : toku_default_compare_fun, &nonce_db); assert(r==0);
toku_cachetable_verify(ct);
for (i=0; i<N; i++) {
......@@ -781,7 +781,7 @@ static void test_wrongendian_compare (int wrong_p, unsigned int N) {
if (0) printf("%s:%d insert: %02x%02x%02x%02x -> %02x%02x%02x%02x\n", __FILE__, __LINE__,
((unsigned char*)kbt.data)[0], ((unsigned char*)kbt.data)[1], ((unsigned char*)kbt.data)[2], ((unsigned char*)kbt.data)[3],
((unsigned char*)vbt.data)[0], ((unsigned char*)vbt.data)[1], ((unsigned char*)vbt.data)[2], ((unsigned char*)vbt.data)[3]);
r = brt_insert(brt, &kbt, &vbt, &nonce_db, null_txn);
r = brt_insert(brt, &kbt, &vbt, null_txn);
assert(r==0);
toku_cachetable_verify(ct);
}
......@@ -791,7 +791,7 @@ static void test_wrongendian_compare (int wrong_p, unsigned int N) {
for (i=0; i<N; i++) {
int this;
init_dbt(&kbt); init_dbt(&vbt);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_txn);
assert(r==0);
assert(kbt.size==4 && vbt.size==4);
if (0) printf("%s:%d %02x%02x%02x%02x -> %02x%02x%02x%02x\n", __FILE__, __LINE__,
......@@ -819,7 +819,7 @@ int test_brt_cursor_keycompare(DB *db __attribute__((unused)), const DBT *a, con
return toku_keycompare(a->data, a->size, b->data, b->size);
}
void assert_cursor_notfound(BRT brt, int position, DB *db) {
void assert_cursor_notfound(BRT brt, int position) {
BRT_CURSOR cursor;
int r;
DBT kbt, vbt;
......@@ -829,14 +829,14 @@ void assert_cursor_notfound(BRT brt, int position, DB *db) {
init_dbt(&kbt); kbt.flags = DB_DBT_MALLOC;
init_dbt(&vbt); vbt.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &kbt, &vbt, position, db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, position, null_txn);
assert(r == DB_NOTFOUND);
r = brt_cursor_close(cursor);
assert(r==0);
}
void assert_cursor_value(BRT brt, int position, long long value, DB *db) {
void assert_cursor_value(BRT brt, int position, long long value) {
BRT_CURSOR cursor;
int r;
DBT kbt, vbt;
......@@ -848,7 +848,7 @@ void assert_cursor_value(BRT brt, int position, long long value, DB *db) {
if (test_cursor_debug) printf("key: ");
init_dbt(&kbt); kbt.flags = DB_DBT_MALLOC;
init_dbt(&vbt); vbt.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &kbt, &vbt, position, db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, position, null_txn);
assert(r == 0);
if (test_cursor_debug) printf("%s ", (char*)kbt.data);
assert(vbt.size == sizeof v);
......@@ -862,7 +862,7 @@ void assert_cursor_value(BRT brt, int position, long long value, DB *db) {
assert(r==0);
}
void assert_cursor_first_last(BRT brt, long long firstv, long long lastv, DB *db) {
void assert_cursor_first_last(BRT brt, long long firstv, long long lastv) {
BRT_CURSOR cursor;
int r;
DBT kbt, vbt;
......@@ -874,7 +874,7 @@ void assert_cursor_first_last(BRT brt, long long firstv, long long lastv, DB *db
if (test_cursor_debug) printf("first key: ");
init_dbt(&kbt); kbt.flags = DB_DBT_MALLOC;
init_dbt(&vbt); vbt.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &kbt, &vbt, DB_FIRST, db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_FIRST, null_txn);
assert(r == 0);
if (test_cursor_debug) printf("%s ", (char*)kbt.data);
assert(vbt.size == sizeof v);
......@@ -887,7 +887,7 @@ void assert_cursor_first_last(BRT brt, long long firstv, long long lastv, DB *db
if (test_cursor_debug) printf("last key:");
init_dbt(&kbt); kbt.flags = DB_DBT_MALLOC;
init_dbt(&vbt); vbt.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &kbt, &vbt, DB_LAST, db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_LAST, null_txn);
assert(r == 0);
if (test_cursor_debug)printf("%s ", (char*)kbt.data);
assert(vbt.size == sizeof v);
......@@ -915,7 +915,7 @@ void test_brt_cursor_first(int n, DB *db) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(r==0);
/* insert a bunch of kv pairs */
......@@ -927,14 +927,14 @@ void test_brt_cursor_first(int n, DB *db) {
fill_dbt(&kbt, key, strlen(key)+1);
v = i;
fill_dbt(&vbt, &v, sizeof v);
r = brt_insert(brt, &kbt, &vbt, db, 0);
r = brt_insert(brt, &kbt, &vbt, 0);
assert(r==0);
}
if (n == 0)
assert_cursor_notfound(brt, DB_FIRST, db);
assert_cursor_notfound(brt, DB_FIRST);
else
assert_cursor_value(brt, DB_FIRST, 0, db);
assert_cursor_value(brt, DB_FIRST, 0);
r = close_brt(brt);
assert(r==0);
......@@ -957,7 +957,7 @@ void test_brt_cursor_last(int n, DB *db) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(r==0);
/* insert keys 0, 1, .. (n-1) */
......@@ -969,14 +969,14 @@ void test_brt_cursor_last(int n, DB *db) {
fill_dbt(&kbt, key, strlen(key)+1);
v = i;
fill_dbt(&vbt, &v, sizeof v);
r = brt_insert(brt, &kbt, &vbt, db, 0);
r = brt_insert(brt, &kbt, &vbt, 0);
assert(r==0);
}
if (n == 0)
assert_cursor_notfound(brt, DB_LAST, db);
assert_cursor_notfound(brt, DB_LAST);
else
assert_cursor_value(brt, DB_LAST, n-1, db);
assert_cursor_value(brt, DB_LAST, n-1);
r = close_brt(brt);
assert(r==0);
......@@ -999,7 +999,7 @@ void test_brt_cursor_first_last(int n, DB *db) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(r==0);
/* insert a bunch of kv pairs */
......@@ -1012,15 +1012,15 @@ void test_brt_cursor_first_last(int n, DB *db) {
v = i;
fill_dbt(&vbt, &v, sizeof v);
r = brt_insert(brt, &kbt, &vbt, db, 0);
r = brt_insert(brt, &kbt, &vbt, 0);
assert(r==0);
}
if (n == 0) {
assert_cursor_notfound(brt, DB_FIRST, db);
assert_cursor_notfound(brt, DB_LAST, db);
assert_cursor_notfound(brt, DB_FIRST);
assert_cursor_notfound(brt, DB_LAST);
} else
assert_cursor_first_last(brt, 0, n-1, db);
assert_cursor_first_last(brt, 0, n-1);
r = close_brt(brt);
assert(r==0);
......@@ -1045,7 +1045,7 @@ void test_brt_cursor_rfirst(int n, DB *db) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(r==0);
/* insert keys n-1, n-2, ... , 0 */
......@@ -1058,14 +1058,14 @@ void test_brt_cursor_rfirst(int n, DB *db) {
fill_dbt(&kbt, key, strlen(key)+1);
v = i;
fill_dbt(&vbt, &v, sizeof v);
r = brt_insert(brt, &kbt, &vbt, db, 0);
r = brt_insert(brt, &kbt, &vbt, 0);
assert(r==0);
}
if (n == 0)
assert_cursor_notfound(brt, DB_FIRST, db);
assert_cursor_notfound(brt, DB_FIRST);
else
assert_cursor_value(brt, DB_FIRST, 0, db);
assert_cursor_value(brt, DB_FIRST, 0);
r = close_brt(brt);
assert(r==0);
......@@ -1074,7 +1074,7 @@ void test_brt_cursor_rfirst(int n, DB *db) {
assert(r==0);
}
void assert_cursor_walk(BRT brt, int n, DB *db) {
void assert_cursor_walk(BRT brt, int n) {
BRT_CURSOR cursor;
int i;
int r;
......@@ -1089,7 +1089,7 @@ void assert_cursor_walk(BRT brt, int n, DB *db) {
init_dbt(&kbt); kbt.flags = DB_DBT_MALLOC;
init_dbt(&vbt); vbt.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_txn);
if (r != 0)
break;
if (test_cursor_debug) printf("%s ", (char*)kbt.data);
......@@ -1120,7 +1120,7 @@ void test_brt_cursor_walk(int n, DB *db) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(r==0);
/* insert a bunch of kv pairs */
......@@ -1132,12 +1132,12 @@ void test_brt_cursor_walk(int n, DB *db) {
fill_dbt(&kbt, key, strlen(key)+1);
v = i;
fill_dbt(&vbt, &v, sizeof v);
r = brt_insert(brt, &kbt, &vbt, db, 0);
r = brt_insert(brt, &kbt, &vbt, 0);
assert(r==0);
}
/* walk the tree */
assert_cursor_walk(brt, n, db);
assert_cursor_walk(brt, n);
r = close_brt(brt);
assert(r==0);
......@@ -1147,7 +1147,7 @@ void test_brt_cursor_walk(int n, DB *db) {
}
void assert_cursor_rwalk(BRT brt, int n, DB *db) {
void assert_cursor_rwalk(BRT brt, int n) {
BRT_CURSOR cursor;
int i;
int r;
......@@ -1162,7 +1162,7 @@ void assert_cursor_rwalk(BRT brt, int n, DB *db) {
init_dbt(&kbt); kbt.flags = DB_DBT_MALLOC;
init_dbt(&vbt); vbt.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &kbt, &vbt, DB_PREV, db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_PREV, null_txn);
if (r != 0)
break;
if (test_cursor_debug) printf("%s ", (char*)kbt.data);
......@@ -1193,7 +1193,7 @@ void test_brt_cursor_rwalk(int n, DB *db) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(r==0);
/* insert a bunch of kv pairs */
......@@ -1205,12 +1205,12 @@ void test_brt_cursor_rwalk(int n, DB *db) {
fill_dbt(&kbt, &k, sizeof k);
v = i;
fill_dbt(&vbt, &v, sizeof v);
r = brt_insert(brt, &kbt, &vbt, db, 0);
r = brt_insert(brt, &kbt, &vbt, 0);
assert(r==0);
}
/* walk the tree */
assert_cursor_rwalk(brt, n, db);
assert_cursor_rwalk(brt, n);
r = close_brt(brt);
assert(r==0);
......@@ -1220,7 +1220,7 @@ void test_brt_cursor_rwalk(int n, DB *db) {
}
void assert_cursor_walk_inorder(BRT brt, int n, DB *db) {
void assert_cursor_walk_inorder(BRT brt, int n) {
BRT_CURSOR cursor;
int i;
int r;
......@@ -1237,7 +1237,7 @@ void assert_cursor_walk_inorder(BRT brt, int n, DB *db) {
init_dbt(&kbt); kbt.flags = DB_DBT_MALLOC;
init_dbt(&vbt); vbt.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_txn);
if (r != 0)
break;
if (test_cursor_debug) printf("%s ", (char*)kbt.data);
......@@ -1272,7 +1272,7 @@ void test_brt_cursor_rand(int n, DB *db) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(r==0);
/* insert a bunch of kv pairs */
......@@ -1286,19 +1286,19 @@ void test_brt_cursor_rand(int n, DB *db) {
fill_dbt(&kbt, key, strlen(key)+1);
v = i;
fill_dbt(&vbt, &v, sizeof v);
r = brt_lookup(brt, &kbt, &vbt, db);
r = brt_lookup(brt, &kbt, &vbt);
if (r == 0) {
printf("dup");
continue;
}
r = brt_insert(brt, &kbt, &vbt, db, 0);
r = brt_insert(brt, &kbt, &vbt, 0);
assert(r==0);
break;
}
}
/* walk the tree */
assert_cursor_walk_inorder(brt, n, db);
assert_cursor_walk_inorder(brt, n);
r = close_brt(brt);
assert(r==0);
......@@ -1325,7 +1325,7 @@ void test_brt_cursor_split(int n, DB *db) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(r==0);
/* insert a bunch of kv pairs */
......@@ -1336,7 +1336,7 @@ void test_brt_cursor_split(int n, DB *db) {
fill_dbt(&kbt, key, strlen(key)+1);
v = keyseqnum;
fill_dbt(&vbt, &v, sizeof v);
r = brt_insert(brt, &kbt, &vbt, db, 0);
r = brt_insert(brt, &kbt, &vbt, 0);
assert(r==0);
}
......@@ -1347,7 +1347,7 @@ void test_brt_cursor_split(int n, DB *db) {
for (i=0; i<n/2; i++) {
init_dbt(&kbt); kbt.flags = DB_DBT_MALLOC;
init_dbt(&vbt); vbt.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_txn);
assert(r==0);
if (test_cursor_debug) printf("%s ", (char*)kbt.data);
toku_free(kbt.data);
......@@ -1362,7 +1362,7 @@ void test_brt_cursor_split(int n, DB *db) {
fill_dbt(&kbt, key, strlen(key)+1);
v = keyseqnum;
fill_dbt(&vbt, &v, sizeof v);
r = brt_insert(brt, &kbt, &vbt, db, 0);
r = brt_insert(brt, &kbt, &vbt, 0);
assert(r==0);
}
......@@ -1370,7 +1370,7 @@ void test_brt_cursor_split(int n, DB *db) {
for (;;) {
init_dbt(&kbt); kbt.flags = DB_DBT_MALLOC;
init_dbt(&vbt); vbt.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, db, null_txn);
r = brt_cursor_get(cursor, &kbt, &vbt, DB_NEXT, null_txn);
if (r != 0)
break;
if (test_cursor_debug) printf("%s ", (char*)kbt.data);
......@@ -1403,7 +1403,7 @@ void test_multiple_brt_cursors(int n, DB *db) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(r==0);
int i;
......@@ -1453,7 +1453,7 @@ void test_multiple_brt_cursor_walk(int n, DB *db) {
r = brt_create_cachetable(&ct, cachesize, ZERO_LSN, NULL_LOGGER);
assert(r==0);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(r==0);
int c;
......@@ -1473,7 +1473,7 @@ void test_multiple_brt_cursor_walk(int n, DB *db) {
v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
r = brt_insert(brt, &key, &val, db, 0);
r = brt_insert(brt, &key, &val, 0);
assert(r == 0);
/* point cursor i / cursor_gap to the current last key i */
......@@ -1481,7 +1481,7 @@ void test_multiple_brt_cursor_walk(int n, DB *db) {
c = i / cursor_gap;
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursors[c], &key, &val, DB_LAST, db, null_txn);
r = brt_cursor_get(cursors[c], &key, &val, DB_LAST, null_txn);
assert(r == 0);
toku_free(key.data);
toku_free(val.data);
......@@ -1493,7 +1493,7 @@ void test_multiple_brt_cursor_walk(int n, DB *db) {
for (c=0; c<ncursors; c++) {
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursors[c], &key, &val, DB_NEXT, db, null_txn);
r = brt_cursor_get(cursors[c], &key, &val, DB_NEXT, null_txn);
if (r == DB_NOTFOUND) {
/* we already consumed 1 previously */
assert(i == cursor_gap-1);
......@@ -1535,7 +1535,7 @@ void test_brt_cursor_set(int n, int cursor_op, DB *db) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(r==0);
int i;
......@@ -1548,7 +1548,7 @@ void test_brt_cursor_set(int n, int cursor_op, DB *db) {
v = 10*i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
r = brt_insert(brt, &key, &val, db, 0);
r = brt_insert(brt, &key, &val, 0);
assert(r == 0);
}
......@@ -1563,7 +1563,7 @@ void test_brt_cursor_set(int n, int cursor_op, DB *db) {
k = htonl(v);
fill_dbt(&key, &k, sizeof k);
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &key, &val, cursor_op, db, null_txn);
r = brt_cursor_get(cursor, &key, &val, cursor_op, null_txn);
assert(r == 0);
assert(val.size == sizeof vv);
memcpy(&vv, val.data, val.size);
......@@ -1578,7 +1578,7 @@ void test_brt_cursor_set(int n, int cursor_op, DB *db) {
k = htonl(i);
fill_dbt(&key, &k, sizeof k);
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &key, &val, DB_SET, db, null_txn);
r = brt_cursor_get(cursor, &key, &val, DB_SET, null_txn);
assert(r == DB_NOTFOUND);
}
......@@ -1606,7 +1606,7 @@ void test_brt_cursor_set_range(int n, DB *db) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
r = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(r==0);
int i;
......@@ -1620,7 +1620,7 @@ void test_brt_cursor_set_range(int n, DB *db) {
v = 10*i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
r = brt_insert(brt, &key, &val, db, 0);
r = brt_insert(brt, &key, &val, 0);
assert(r == 0);
}
......@@ -1636,7 +1636,7 @@ void test_brt_cursor_set_range(int n, DB *db) {
k = htonl(v);
fill_dbt(&key, &k, sizeof k);
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &key, &val, DB_SET_RANGE, db, null_txn);
r = brt_cursor_get(cursor, &key, &val, DB_SET_RANGE, null_txn);
if (v > max_key)
/* there is no smallest key if v > the max key */
assert(r == DB_NOTFOUND);
......@@ -1673,7 +1673,7 @@ void test_brt_cursor_delete(int n, DB *db) {
error = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(error == 0);
error = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
error = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(error == 0);
error = brt_cursor(brt, &cursor);
......@@ -1689,7 +1689,7 @@ void test_brt_cursor_delete(int n, DB *db) {
v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = brt_insert(brt, &key, &val, db, 0);
error = brt_insert(brt, &key, &val, 0);
assert(error == 0);
}
......@@ -1697,7 +1697,7 @@ void test_brt_cursor_delete(int n, DB *db) {
for (;;) {
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
error = brt_cursor_get(cursor, &key, &val, DB_NEXT, db, null_txn);
error = brt_cursor_get(cursor, &key, &val, DB_NEXT, null_txn);
if (error == DB_NOTFOUND)
break;
assert(error == 0);
......@@ -1735,7 +1735,7 @@ void test_brt_cursor_get_both(int n, DB *db) {
error = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(error == 0);
error = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare);
error = open_brt(fname, 0, 1, &brt, 1<<12, ct, null_txn, test_brt_cursor_keycompare, db);
assert(error == 0);
error = brt_cursor(brt, &cursor);
......@@ -1749,7 +1749,7 @@ void test_brt_cursor_get_both(int n, DB *db) {
v = n+1;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = brt_cursor_get(cursor, &key, &val, DB_GET_BOTH, db, null_txn);
error = brt_cursor_get(cursor, &key, &val, DB_GET_BOTH, null_txn);
assert(error == DB_NOTFOUND);
int i;
......@@ -1759,7 +1759,7 @@ void test_brt_cursor_get_both(int n, DB *db) {
v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = brt_insert(brt, &key, &val, db, 0);
error = brt_insert(brt, &key, &val, 0);
assert(error == 0);
}
......@@ -1768,7 +1768,7 @@ void test_brt_cursor_get_both(int n, DB *db) {
v = n-1;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = brt_cursor_get(cursor, &key, &val, DB_GET_BOTH, db, null_txn);
error = brt_cursor_get(cursor, &key, &val, DB_GET_BOTH, null_txn);
assert(error == DB_NOTFOUND);
/* verify that key match but data mismatch fails */
......@@ -1777,7 +1777,7 @@ void test_brt_cursor_get_both(int n, DB *db) {
v = i+1;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = brt_cursor_get(cursor, &key, &val, DB_GET_BOTH, db, null_txn);
error = brt_cursor_get(cursor, &key, &val, DB_GET_BOTH, null_txn);
assert(error == DB_NOTFOUND);
}
......@@ -1787,7 +1787,7 @@ void test_brt_cursor_get_both(int n, DB *db) {
v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = brt_cursor_get(cursor, &key, &val, DB_GET_BOTH, db, null_txn);
error = brt_cursor_get(cursor, &key, &val, DB_GET_BOTH, null_txn);
assert(error == 0);
#ifdef DB_CURRENT
init_dbt(&key); key.flags = DB_DBT_MALLOC;
......@@ -1808,7 +1808,7 @@ void test_brt_cursor_get_both(int n, DB *db) {
v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = brt_cursor_get(cursor, &key, &val, DB_GET_BOTH, db, null_txn);
error = brt_cursor_get(cursor, &key, &val, DB_GET_BOTH, null_txn);
assert(error == DB_NOTFOUND);
}
......@@ -1887,7 +1887,7 @@ void test_large_kv(int bsize, int ksize, int vsize) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
unlink(fname);
r = open_brt(fname, 0, 1, &t, bsize, ct, null_txn, toku_default_compare_fun);
r = open_brt(fname, 0, 1, &t, bsize, ct, null_txn, toku_default_compare_fun, null_db);
assert(r==0);
DBT key, val;
......@@ -1897,7 +1897,7 @@ void test_large_kv(int bsize, int ksize, int vsize) {
fill_dbt(&key, k, ksize);
fill_dbt(&val, v, vsize);
r = brt_insert(t, &key, &val, 0, 0);
r = brt_insert(t, &key, &val, 0);
assert(r == 0);
toku_free(k);
......@@ -1934,13 +1934,13 @@ void test_brt_delete_empty() {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
unlink(fname);
r = open_brt(fname, 0, 1, &t, 4096, ct, null_txn, toku_default_compare_fun);
r = open_brt(fname, 0, 1, &t, 4096, ct, null_txn, toku_default_compare_fun, null_db);
assert(r==0);
DBT key;
int k = htonl(1);
fill_dbt(&key, &k, sizeof k);
r = brt_delete(t, &key, 0);
r = brt_delete(t, &key);
assert(r == 0);
r = close_brt(t); assert(r==0);
......@@ -1963,7 +1963,7 @@ void test_brt_delete_present(int n) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
unlink(fname);
r = open_brt(fname, 0, 1, &t, 4096, ct, null_txn, toku_default_compare_fun);
r = open_brt(fname, 0, 1, &t, 4096, ct, null_txn, toku_default_compare_fun, null_db);
assert(r==0);
DBT key, val;
......@@ -1974,7 +1974,7 @@ void test_brt_delete_present(int n) {
k = htonl(i); v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
r = brt_insert(t, &key, &val, 0, 0);
r = brt_insert(t, &key, &val, 0);
assert(r == 0);
}
......@@ -1982,7 +1982,7 @@ void test_brt_delete_present(int n) {
for (i=0; i<n; i++) {
k = htonl(i);
fill_dbt(&key, &k, sizeof k);
r = brt_delete(t, &key, 0);
r = brt_delete(t, &key);
assert(r == 0);
}
......@@ -1991,7 +1991,7 @@ void test_brt_delete_present(int n) {
k = htonl(i);
fill_dbt(&key, &k, sizeof k);
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = brt_lookup(t, &key, &val, 0);
r = brt_lookup(t, &key, &val);
assert(r == DB_NOTFOUND);
}
......@@ -2003,7 +2003,7 @@ void test_brt_delete_present(int n) {
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &key, &val, DB_FIRST, null_db, null_txn);
r = brt_cursor_get(cursor, &key, &val, DB_FIRST, null_txn);
assert(r != 0);
r = brt_cursor_close(cursor);
......@@ -2025,7 +2025,7 @@ void test_brt_delete_not_present(int n) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
unlink(fname);
r = open_brt(fname, 0, 1, &t, 4096, ct, null_txn, toku_default_compare_fun);
r = open_brt(fname, 0, 1, &t, 4096, ct, null_txn, toku_default_compare_fun, null_db);
assert(r==0);
DBT key, val;
......@@ -2036,7 +2036,7 @@ void test_brt_delete_not_present(int n) {
k = htonl(i); v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
r = brt_insert(t, &key, &val, 0, 0);
r = brt_insert(t, &key, &val, 0);
assert(r == 0);
}
......@@ -2044,14 +2044,14 @@ void test_brt_delete_not_present(int n) {
for (i=0; i<n; i++) {
k = htonl(i);
fill_dbt(&key, &k, sizeof k);
r = brt_delete(t, &key, 0);
r = brt_delete(t, &key);
assert(r == 0);
}
/* try to delete key n+1 not in the tree */
k = htonl(n+1);
fill_dbt(&key, &k, sizeof k);
r = brt_delete(t, &key, 0);
r = brt_delete(t, &key);
/* the delete may be buffered or may be executed on a leaf node, so the
return value depends */
printf("brt_delete k=%d %d\n", k, r);
......@@ -2072,7 +2072,7 @@ void test_brt_delete_cursor_first(int n) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
unlink(fname);
r = open_brt(fname, 0, 1, &t, 4096, ct, null_txn, toku_default_compare_fun);
r = open_brt(fname, 0, 1, &t, 4096, ct, null_txn, toku_default_compare_fun, null_db);
assert(r==0);
DBT key, val;
......@@ -2083,7 +2083,7 @@ void test_brt_delete_cursor_first(int n) {
k = htonl(i); v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
r = brt_insert(t, &key, &val, 0, 0);
r = brt_insert(t, &key, &val, 0);
assert(r == 0);
}
......@@ -2092,7 +2092,7 @@ void test_brt_delete_cursor_first(int n) {
k = htonl(i);
fill_dbt(&key, &k, sizeof k);
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = brt_lookup(t, &key, &val, 0);
r = brt_lookup(t, &key, &val);
assert(r == 0);
assert(val.size == sizeof (int));
int vv;
......@@ -2105,11 +2105,11 @@ void test_brt_delete_cursor_first(int n) {
for (i=0; i<n-1; i++) {
k = htonl(i);
fill_dbt(&key, &k, sizeof k);
r = brt_delete(t, &key, 0);
r = brt_delete(t, &key);
assert(r == 0);
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = brt_lookup(t, &key, &val, 0);
r = brt_lookup(t, &key, &val);
assert(r == DB_NOTFOUND);
}
......@@ -2118,7 +2118,7 @@ void test_brt_delete_cursor_first(int n) {
k = htonl(i);
fill_dbt(&key, &k, sizeof k);
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = brt_lookup(t, &key, &val, 0);
r = brt_lookup(t, &key, &val);
assert(r == DB_NOTFOUND);
}
......@@ -2130,7 +2130,7 @@ void test_brt_delete_cursor_first(int n) {
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &key, &val, DB_FIRST, null_db, null_txn);
r = brt_cursor_get(cursor, &key, &val, DB_FIRST, null_txn);
assert(r == 0);
int vv;
assert(val.size == sizeof vv);
......@@ -2164,7 +2164,7 @@ void test_insert_delete_lookup(int n) {
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r==0);
unlink(fname);
r = open_brt(fname, 0, 1, &t, 4096, ct, null_txn, toku_default_compare_fun);
r = open_brt(fname, 0, 1, &t, 4096, ct, null_txn, toku_default_compare_fun, null_db);
assert(r==0);
DBT key, val;
......@@ -2175,20 +2175,20 @@ void test_insert_delete_lookup(int n) {
k = htonl(i); v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
r = brt_insert(t, &key, &val, 0, 0);
r = brt_insert(t, &key, &val, 0);
assert(r == 0);
}
if (n > 0) {
k = htonl(n-1);
fill_dbt(&key, &k, sizeof k);
r = brt_delete(t, &key, 0);
r = brt_delete(t, &key);
assert(r == 0);
k = htonl(n-1);
fill_dbt(&key, &k, sizeof k);
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = brt_lookup(t, &key, &val, 0);
r = brt_lookup(t, &key, &val);
assert(r == DB_NOTFOUND);
}
......
......@@ -116,7 +116,7 @@ static void fixup_child_fingerprint(BRTNODE node, int childnum_of_node, BRTNODE
node->dirty=1;
}
static int brt_compare_pivot(BRT brt, DBT *key, DBT *data, bytevec ck, unsigned int cl, DB *db) {
static int brt_compare_pivot(BRT brt, DBT *key, DBT *data, bytevec ck, unsigned int cl) {
int cmp;
DBT mydbt;
if (brt->flags & TOKU_DB_DUPSORT) {
......@@ -128,11 +128,11 @@ static int brt_compare_pivot(BRT brt, DBT *key, DBT *data, bytevec ck, unsigned
kl = cl - dl - (sizeof dl);
k = ck + (sizeof dl);
d = ck + (sizeof dl) + kl;
cmp = brt->compare_fun(db, key, fill_dbt(&mydbt, k, kl));
cmp = brt->compare_fun(brt->db, key, fill_dbt(&mydbt, k, kl));
if (cmp == 0 && data != 0)
cmp = brt->dup_compare(db, data, fill_dbt(&mydbt, d, dl));
cmp = brt->dup_compare(brt->db, data, fill_dbt(&mydbt, d, dl));
} else
cmp = brt->compare_fun(db, key, fill_dbt(&mydbt, ck, cl));
cmp = brt->compare_fun(brt->db, key, fill_dbt(&mydbt, ck, cl));
return cmp;
}
......@@ -199,7 +199,7 @@ int brtnode_fetch_callback (CACHEFILE cachefile, DISKOFF nodename, void **brtnod
BRT t =(BRT)extraargs;
BRTNODE *result=(BRTNODE*)brtnode_pv;
int r = toku_deserialize_brtnode_from(toku_cachefile_fd(cachefile), nodename, result, t->flags, t->nodesize,
t->compare_fun, t->dup_compare);
t->compare_fun, t->dup_compare, t->db, toku_cachefile_filenum(t->cf));
if (r == 0)
*sizep = brtnode_size(*result);
*written_lsn = (*result)->disk_lsn;
......@@ -323,7 +323,7 @@ static void initialize_brtnode (BRT t, BRTNODE n, DISKOFF nodename, int height)
}
n->u.n.n_bytes_in_hashtables = 0;
} else {
int r = toku_pma_create(&n->u.l.buffer, t->compare_fun, n->nodesize);
int r = toku_pma_create(&n->u.l.buffer, t->compare_fun, t->db, toku_cachefile_filenum(t->cf), n->nodesize);
assert(r==0);
toku_pma_set_dup_mode(n->u.l.buffer, t->flags & (TOKU_DB_DUP+TOKU_DB_DUPSORT));
if (t->flags & TOKU_DB_DUPSORT)
......@@ -390,7 +390,7 @@ static int insert_to_hash_in_nonleaf (BRTNODE node, int childnum, DBT *k, DBT *v
}
int brtleaf_split (BRT t, BRTNODE node, BRTNODE *nodea, BRTNODE *nodeb, DBT *splitk, DB *db) {
int brtleaf_split (BRT t, BRTNODE node, BRTNODE *nodea, BRTNODE *nodeb, DBT *splitk) {
BRTNODE A,B;
assert(node->height==0);
assert(t->h->nodesize>=node->nodesize); /* otherwise we might be in trouble because the nodesize shrank. */
......@@ -405,9 +405,9 @@ int brtleaf_split (BRT t, BRTNODE node, BRTNODE *nodea, BRTNODE *nodeb, DBT *spl
//printf("%s:%d B is at %lld nodesize=%d\n", __FILE__, __LINE__, B->thisnodename, B->nodesize);
assert(node->height>0 || node->u.l.buffer!=0);
int r;
r = toku_pma_split(node->u.l.buffer, &node->u.l.n_bytes_in_buffer, splitk, db,
A->u.l.buffer, &A->u.l.n_bytes_in_buffer, A->rand4fingerprint, &A->local_fingerprint,
B->u.l.buffer, &B->u.l.n_bytes_in_buffer, B->rand4fingerprint, &B->local_fingerprint);
r = toku_pma_split(node->u.l.buffer, &node->u.l.n_bytes_in_buffer, splitk,
A->u.l.buffer, &A->u.l.n_bytes_in_buffer, A->rand4fingerprint, &A->local_fingerprint,
B->u.l.buffer, &B->u.l.n_bytes_in_buffer, B->rand4fingerprint, &B->local_fingerprint);
assert(r == 0);
assert(node->height>0 || node->u.l.buffer!=0);
/* Remove it from the cache table, and free its storage. */
......@@ -568,7 +568,7 @@ static int push_brt_cmd_down_only_if_it_wont_push_more_else_put_here (BRT t, BRT
if (childnum_of_node+1<node->u.n.n_children) {
DBT k2;
printf(" nextsplitkey=%s\n", (char*)node->u.n.childkeys[childnum_of_node]);
assert(t->compare_fun(cmd->u.id.db, k, fill_dbt(&k2, node->u.n.childkeys[childnum_of_node], node->u.n.childkeylens[childnum_of_node]))<=0);
assert(t->compare_fun(t->db, k, fill_dbt(&k2, node->u.n.childkeys[childnum_of_node], node->u.n.childkeylens[childnum_of_node]))<=0);
} else {
printf("\n");
}
......@@ -646,7 +646,6 @@ static int handle_split_of_child (BRT t, BRTNODE node, int childnum,
DBT *childsplitk, /* the data in the childsplitk is alloc'd and is consumed by this call. */
int *did_split, BRTNODE *nodea, BRTNODE *nodeb,
DBT *splitk,
DB *db,
TOKUTXN txn) {
assert(node->height>0);
assert(0 <= childnum && childnum < node->u.n.n_children);
......@@ -717,11 +716,11 @@ static int handle_split_of_child (BRT t, BRTNODE node, int childnum,
fill_dbt(&skd, skey, skeylen);
fill_dbt(&svd, sval, svallen);
BRT_CMD brtcmd;
brtcmd.type = type; brtcmd.u.id.key = &skd; brtcmd.u.id.val = &svd; brtcmd.u.id.db = db;
brtcmd.type = type; brtcmd.u.id.key = &skd; brtcmd.u.id.val = &svd;
//verify_local_fingerprint_nonleaf(childa); verify_local_fingerprint_nonleaf(childb);
int tochildnum = childnum;
BRTNODE tochild = childa;
int cmp = brt_compare_pivot(t, &skd, &svd, childsplitk->data, childsplitk->size, db);
int cmp = brt_compare_pivot(t, &skd, &svd, childsplitk->data, childsplitk->size);
if (cmp < 0) {
;
} else if (cmp > 0) {
......@@ -778,7 +777,6 @@ static int push_some_brt_cmds_down (BRT t, BRTNODE node, int childnum,
int *did_split, BRTNODE *nodea, BRTNODE *nodeb,
DBT *splitk,
int debug,
DB *db,
TOKUTXN txn) {
void *childnode_v;
BRTNODE child;
......@@ -824,7 +822,6 @@ static int push_some_brt_cmds_down (BRT t, BRTNODE node, int childnum,
brtcmd.type = type;
brtcmd.u.id.key = &hk;
brtcmd.u.id.val = &hv;
brtcmd.u.id.db = db;
//printf("%s:%d random_picked\n", __FILE__, __LINE__);
init_dbt(&childsplitk);
......@@ -851,7 +848,7 @@ static int push_some_brt_cmds_down (BRT t, BRTNODE node, int childnum,
r=handle_split_of_child (t, node, childnum,
childa, childb, &childsplitk,
did_split, nodea, nodeb, splitk,
db, txn);
txn);
//if (*did_split) {
// verify_local_fingerprint_nonleaf(*nodea);
// verify_local_fingerprint_nonleaf(*nodeb);
......@@ -874,7 +871,7 @@ int debugp1 (int debug) {
return debug ? debug+1 : 0;
}
static int brtnode_maybe_push_down(BRT t, BRTNODE node, int *did_split, BRTNODE *nodea, BRTNODE *nodeb, DBT *splitk, int debug, DB *db, TOKUTXN txn)
static int brtnode_maybe_push_down(BRT t, BRTNODE node, int *did_split, BRTNODE *nodea, BRTNODE *nodeb, DBT *splitk, int debug, TOKUTXN txn)
/* If the buffer is too full, then push down. Possibly the child will split. That may make us split. */
{
assert(node->height>0);
......@@ -890,7 +887,7 @@ static int brtnode_maybe_push_down(BRT t, BRTNODE node, int *did_split, BRTNODE
find_heaviest_child(node, &childnum);
if (0) printf("%s:%d %*spush some down from %lld into %lld (child %d)\n", __FILE__, __LINE__, debug, "", node->thisnodename, node->u.n.children[childnum], childnum);
assert(node->u.n.children[childnum]!=0);
int r = push_some_brt_cmds_down(t, node, childnum, did_split, nodea, nodeb, splitk, debugp1(debug), db, txn);
int r = push_some_brt_cmds_down(t, node, childnum, did_split, nodea, nodeb, splitk, debugp1(debug), txn);
if (r!=0) return r;
assert(*did_split==0 || *did_split==1);
if (debug) printf("%s:%d %*sdid push_some_brt_cmds_down did_split=%d\n", __FILE__, __LINE__, debug, "", *did_split);
......@@ -928,9 +925,8 @@ static int brt_leaf_put_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
if (cmd->type == BRT_INSERT) {
DBT *k = cmd->u.id.key;
DBT *v = cmd->u.id.val;
DB *db = cmd->u.id.db;
int replaced_v_size;
enum pma_errors pma_status = toku_pma_insert_or_replace(node->u.l.buffer, k, v, &replaced_v_size, db, txn, node->thisnodename, node->rand4fingerprint, &node->local_fingerprint);
enum pma_errors pma_status = toku_pma_insert_or_replace(node->u.l.buffer, k, v, &replaced_v_size, txn, node->thisnodename, node->rand4fingerprint, &node->local_fingerprint);
assert(pma_status==BRT_OK);
//printf("replaced_v_size=%d\n", replaced_v_size);
if (replaced_v_size>=0) {
......@@ -944,7 +940,7 @@ static int brt_leaf_put_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
// If it doesn't fit, then split the leaf.
if (toku_serialize_brtnode_size(node) > node->nodesize) {
int r = brtleaf_split (t, node, nodea, nodeb, splitk, db);
int r = brtleaf_split (t, node, nodea, nodeb, splitk);
if (r!=0) return r;
//printf("%s:%d splitkey=%s\n", __FILE__, __LINE__, (char*)*splitkey);
split_count++;
......@@ -962,7 +958,7 @@ static int brt_leaf_put_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
} else if (cmd->type == BRT_DELETE) {
u_int32_t delta;
int r = toku_pma_delete(node->u.l.buffer, cmd->u.id.key, cmd->u.id.db, node->rand4fingerprint, &node->local_fingerprint, &delta);
int r = toku_pma_delete(node->u.l.buffer, cmd->u.id.key, node->rand4fingerprint, &node->local_fingerprint, &delta);
if (r == BRT_OK) {
node->u.l.n_bytes_in_buffer -= delta;
node->dirty = 1;
......@@ -975,12 +971,12 @@ static int brt_leaf_put_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
}
/* find the rightmost child that the key/data will be inserted */
static unsigned int brtnode_right_child (BRTNODE node, DBT *k, DBT *data, BRT t, DB *db) {
static unsigned int brtnode_right_child (BRTNODE node, DBT *k, DBT *data, BRT t) {
assert(node->height>0);
int maybe = -1; /* last pivot that matched the key */
int i;
for (i=node->u.n.n_children-2; i >= 0; i--) {
int cmp = brt_compare_pivot(t, k, data, node->u.n.childkeys[i], node->u.n.childkeylens[i], db);
int cmp = brt_compare_pivot(t, k, data, node->u.n.childkeys[i], node->u.n.childkeylens[i]);
if (cmp < 0) {
continue;
} else if (cmp > 0) {
......@@ -1007,11 +1003,11 @@ static unsigned int brtnode_right_child (BRTNODE node, DBT *k, DBT *data, BRT t,
}
/* find the leftmost child that may contain the key */
static unsigned int brtnode_left_child (BRTNODE node , DBT *k, DBT *d, BRT t, DB *db) {
static unsigned int brtnode_left_child (BRTNODE node , DBT *k, DBT *d, BRT t) {
int i;
assert(node->height>0);
for (i=0; i<node->u.n.n_children-1; i++) {
int cmp = brt_compare_pivot(t, k, d, node->u.n.childkeys[i], node->u.n.childkeylens[i], db);
int cmp = brt_compare_pivot(t, k, d, node->u.n.childkeys[i], node->u.n.childkeylens[i]);
if (cmp > 0) continue;
if (cmp < 0) return i;
if (t->flags & TOKU_DB_DUP) {
......@@ -1025,8 +1021,8 @@ static unsigned int brtnode_left_child (BRTNODE node , DBT *k, DBT *d, BRT t, DB
return node->u.n.n_children-1;
}
static inline unsigned int brtnode_which_child (BRTNODE node , DBT *k, BRT t, DB *db) {
return brtnode_left_child(node, k, 0, t, db);
static inline unsigned int brtnode_which_child (BRTNODE node , DBT *k, BRT t) {
return brtnode_left_child(node, k, 0, t);
}
static int brt_nonleaf_put_cmd_child (BRT t, BRTNODE node, BRT_CMD *cmd,
......@@ -1064,11 +1060,10 @@ static int brt_nonleaf_put_cmd_child (BRT t, BRTNODE node, BRT_CMD *cmd,
if (child_did_split) {
if (0) printf("brt_nonleaf_insert child_split %p\n", child);
assert(cmd->type == BRT_INSERT || cmd->type == BRT_DELETE);
DB *db = cmd->u.id.db;
r = handle_split_of_child(t, node, childnum,
childa, childb, &childsplitk,
did_split, nodea, nodeb, splitk,
db, txn);
txn);
assert(r == 0);
} else {
//verify_local_fingerprint_nonleaf(child);
......@@ -1093,9 +1088,8 @@ static int brt_nonleaf_insert_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
int type = cmd->type;
DBT *k = cmd->u.id.key;
DBT *v = cmd->u.id.val;
DB *db = cmd->u.id.db;
childnum = brtnode_right_child(node, k, v, t, db);
childnum = brtnode_right_child(node, k, v, t);
//rfp printf("nonleaf_insert %d,%d -> %lld %d\n", htonl(*(int*)k->data), *(int*)v->data, node->thisnodename, childnum);
/* non-buffering mode when cursors are open on this child */
......@@ -1160,7 +1154,7 @@ static int brt_nonleaf_insert_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
}
if (debug) printf("%s:%d %*sDoing maybe_push_down\n", __FILE__, __LINE__, debug, "");
//verify_local_fingerprint_nonleaf(node);
int r = brtnode_maybe_push_down(t, node, did_split, nodea, nodeb, splitk, debugp1(debug), db, txn);
int r = brtnode_maybe_push_down(t, node, did_split, nodea, nodeb, splitk, debugp1(debug), txn);
if (r!=0) return r;
if (debug) printf("%s:%d %*sDid maybe_push_down\n", __FILE__, __LINE__, debug, "");
if (*did_split) {
......@@ -1194,7 +1188,6 @@ static int brt_nonleaf_delete_cmd_child (BRT t, BRTNODE node, BRT_CMD *cmd,
int type = cmd->type;
DBT *k = cmd->u.id.key;
DBT *v = cmd->u.id.val;
DB *db = cmd->u.id.db;
/* non-buffering mode when cursors are open on this child */
if (node->u.n.n_cursors[childnum] > 0) {
......@@ -1255,7 +1248,7 @@ static int brt_nonleaf_delete_cmd_child (BRT t, BRTNODE node, BRT_CMD *cmd,
}
if (debug) printf("%s:%d %*sDoing maybe_push_down\n", __FILE__, __LINE__, debug, "");
//verify_local_fingerprint_nonleaf(node);
int r = brtnode_maybe_push_down(t, node, did_split, nodea, nodeb, splitk, debugp1(debug), db, txn);
int r = brtnode_maybe_push_down(t, node, did_split, nodea, nodeb, splitk, debugp1(debug), txn);
if (r!=0) return r;
if (debug) printf("%s:%d %*sDid maybe_push_down\n", __FILE__, __LINE__, debug, "");
if (*did_split) {
......@@ -1295,7 +1288,7 @@ static int brt_nonleaf_delete_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
}
int i;
for (i = 0; i < node->u.n.n_children-1; i++) {
int cmp = brt_compare_pivot(t, cmd->u.id.key, 0, node->u.n.childkeys[i], node->u.n.childkeylens[i], cmd->u.id.db);
int cmp = brt_compare_pivot(t, cmd->u.id.key, 0, node->u.n.childkeys[i], node->u.n.childkeylens[i]);
if (cmp > 0) {
continue;
} else if (cmp < 0) {
......@@ -1344,7 +1337,7 @@ static int brt_nonleaf_delete_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
/* post condition: for all pk(i) == k -> assert pf(i) == 0 */
for (i=0; i < node->u.n.n_children-1; i++) {
int cmp = brt_compare_pivot(t, cmd->u.id.key, 0, node->u.n.childkeys[i], node->u.n.childkeylens[i], cmd->u.id.db);
int cmp = brt_compare_pivot(t, cmd->u.id.key, 0, node->u.n.childkeys[i], node->u.n.childkeylens[i]);
if (cmp == 0)
assert(node->u.n.pivotflags[i] == 0);
......@@ -1690,7 +1683,7 @@ int brt_remove_subdb(BRT brt, const char *dbname, u_int32_t flags) {
// This one has no env
int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt, int nodesize, CACHETABLE cachetable, TOKUTXN txn,
int (*compare_fun)(DB*,const DBT*,const DBT*)) {
int (*compare_fun)(DB*,const DBT*,const DBT*), DB *db) {
BRT brt;
int r;
int only_create = 0;
......@@ -1700,6 +1693,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
return r;
brt_set_nodesize(brt, nodesize);
brt_set_bt_compare(brt, compare_fun);
brt->db = db;
r = brt_open(brt, fname, fname, dbname, is_create, only_create, cachetable, txn);
if (r != 0) {
......@@ -1839,19 +1833,18 @@ static int brt_root_put_cmd(BRT brt, BRT_CMD *cmd, TOKUTXN txn) {
return result;
}
int brt_insert (BRT brt, DBT *key, DBT *val, DB* db, TOKUTXN txn) {
int brt_insert (BRT brt, DBT *key, DBT *val, TOKUTXN txn) {
int r;
BRT_CMD brtcmd;
brtcmd.type = BRT_INSERT;
brtcmd.u.id.key = key;
brtcmd.u.id.val = val;
brtcmd.u.id.db = db;
r = brt_root_put_cmd(brt, &brtcmd, txn);
return r;
}
int brt_lookup_node (BRT brt, DISKOFF off, DBT *k, DBT *v, DB *db, BRTNODE parent_brtnode) {
int brt_lookup_node (BRT brt, DISKOFF off, DBT *k, DBT *v, BRTNODE parent_brtnode) {
int result;
void *node_v;
int r = toku_cachetable_get_and_pin(brt->cf, off, &node_v, NULL,
......@@ -1868,7 +1861,7 @@ int brt_lookup_node (BRT brt, DISKOFF off, DBT *k, DBT *v, DB *db, BRTNODE paren
node->parent_brtnode = parent_brtnode;
if (node->height==0) {
result = toku_pma_lookup(node->u.l.buffer, k, v, db);
result = toku_pma_lookup(node->u.l.buffer, k, v);
//printf("%s:%d looked up something, got answerlen=%d\n", __FILE__, __LINE__, answerlen);
//verify_local_fingerprint_nonleaf(node);
r = toku_cachetable_unpin(brt->cf, off, 0, 0);
......@@ -1876,7 +1869,7 @@ int brt_lookup_node (BRT brt, DISKOFF off, DBT *k, DBT *v, DB *db, BRTNODE paren
return result;
}
childnum = brtnode_which_child(node, k, brt, db);
childnum = brtnode_which_child(node, k, brt);
{
bytevec hanswer;
ITEMLEN hanswerlen;
......@@ -1884,7 +1877,7 @@ int brt_lookup_node (BRT brt, DISKOFF off, DBT *k, DBT *v, DB *db, BRTNODE paren
if (toku_hash_find (node->u.n.htables[childnum], k->data, k->size, &hanswer, &hanswerlen, &type)==0) {
if (type == BRT_INSERT) {
if ((brt->flags & TOKU_DB_DUP)) {
result = brt_lookup_node(brt, node->u.n.children[childnum], k, v, db, node);
result = brt_lookup_node(brt, node->u.n.children[childnum], k, v, node);
if (result != 0) {
ybt_set_value(v, hanswer, hanswerlen, &brt->sval);
result = 0;
......@@ -1912,7 +1905,7 @@ int brt_lookup_node (BRT brt, DISKOFF off, DBT *k, DBT *v, DB *db, BRTNODE paren
}
}
result = brt_lookup_node(brt, node->u.n.children[childnum], k, v, db, node);
result = brt_lookup_node(brt, node->u.n.children[childnum], k, v, node);
//verify_local_fingerprint_nonleaf(node);
r = toku_cachetable_unpin(brt->cf, off, 0, 0);
assert(r == 0);
......@@ -1920,7 +1913,7 @@ int brt_lookup_node (BRT brt, DISKOFF off, DBT *k, DBT *v, DB *db, BRTNODE paren
}
int brt_lookup (BRT brt, DBT *k, DBT *v, DB *db) {
int brt_lookup (BRT brt, DBT *k, DBT *v) {
int r;
CACHEKEY *rootp;
assert(0==toku_cachefile_count_pinned(brt->cf, 1));
......@@ -1932,7 +1925,7 @@ int brt_lookup (BRT brt, DBT *k, DBT *v, DB *db) {
return r;
}
rootp = toku_calculate_root_offset_pointer(brt);
if ((r = brt_lookup_node(brt, *rootp, k, v, db, 0))) {
if ((r = brt_lookup_node(brt, *rootp, k, v, 0))) {
// printf("%s:%d\n", __FILE__, __LINE__);
goto died0;
}
......@@ -1942,7 +1935,7 @@ int brt_lookup (BRT brt, DBT *k, DBT *v, DB *db) {
return 0;
}
int brt_delete(BRT brt, DBT *key, DB *db) {
int brt_delete(BRT brt, DBT *key) {
int r;
BRT_CMD brtcmd;
DBT val;
......@@ -1952,7 +1945,6 @@ int brt_delete(BRT brt, DBT *key, DB *db) {
brtcmd.type = BRT_DELETE;
brtcmd.u.id.key = key;
brtcmd.u.id.val = &val;
brtcmd.u.id.db = db;
r = brt_root_put_cmd(brt, &brtcmd, 0);
return r;
}
......@@ -2072,7 +2064,7 @@ int brt_flush_debug = 0;
* then reflect the node split up the cursor path towards the tree root.
* If the root is reached then create a new root
*/
void brt_flush_child(BRT t, BRTNODE node, int childnum, BRT_CURSOR cursor, DB *db, TOKUTXN txn) {
void brt_flush_child(BRT t, BRTNODE node, int childnum, BRT_CURSOR cursor, TOKUTXN txn) {
int r;
int child_did_split;
BRTNODE childa, childb;
......@@ -2085,7 +2077,7 @@ void brt_flush_child(BRT t, BRTNODE node, int childnum, BRT_CURSOR cursor, DB *d
init_dbt(&child_splitk);
r = push_some_brt_cmds_down(t, node, childnum,
&child_did_split, &childa, &childb, &child_splitk, brt_flush_debug, db, txn);
&child_did_split, &childa, &childb, &child_splitk, brt_flush_debug, txn);
assert(r == 0);
if (brt_flush_debug) {
printf("brt_flush_child done %lld %d\n", node->thisnodename, childnum);
......@@ -2119,7 +2111,7 @@ void brt_flush_child(BRT t, BRTNODE node, int childnum, BRT_CURSOR cursor, DB *d
r = handle_split_of_child(t, upnode, childnum,
childa, childb, &child_splitk,
&child_did_split, &childa, &childb, &child_splitk,
db, txn);
txn);
assert(r == 0);
}
}
......@@ -2397,7 +2389,7 @@ void brt_cursor_print(BRT_CURSOR cursor) {
printf("\n");
}
int brtcurs_set_position_last (BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db, TOKUTXN txn, BRTNODE parent_brtnode) {
int brtcurs_set_position_last (BRT_CURSOR cursor, DISKOFF off, DBT *key, TOKUTXN txn, BRTNODE parent_brtnode) {
BRT brt=cursor->brt;
void *node_v;
......@@ -2421,7 +2413,7 @@ int brtcurs_set_position_last (BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db,
cursor->pathcnum[cursor->path_len-1] = childnum;
brt_node_add_cursor(node, childnum, cursor);
if (node->u.n.n_bytes_in_hashtable[childnum] > 0) {
brt_flush_child(cursor->brt, node, childnum, cursor, db, txn);
brt_flush_child(cursor->brt, node, childnum, cursor, txn);
/*
* the flush may have been partially successfull. it may have also
* changed the tree such that the current node have expanded or been
......@@ -2432,7 +2424,7 @@ int brtcurs_set_position_last (BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db,
brt_node_remove_cursor(node, childnum, cursor);
goto try_last_child;
}
r=brtcurs_set_position_last (cursor, node->u.n.children[childnum], key, db, txn, node);
r=brtcurs_set_position_last (cursor, node->u.n.children[childnum], key, txn, node);
if (r == 0)
return 0;
assert(node == cursor->path[cursor->path_len-1]);
......@@ -2459,7 +2451,7 @@ int brtcurs_set_position_last (BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db,
}
}
int brtcurs_set_position_first (BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db, TOKUTXN txn, BRTNODE parent_brtnode) {
int brtcurs_set_position_first (BRT_CURSOR cursor, DISKOFF off, DBT *key, TOKUTXN txn, BRTNODE parent_brtnode) {
BRT brt=cursor->brt;
void *node_v;
......@@ -2483,7 +2475,7 @@ int brtcurs_set_position_first (BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db
cursor->pathcnum[cursor->path_len-1] = childnum;
brt_node_add_cursor(node, childnum, cursor);
if (node->u.n.n_bytes_in_hashtable[childnum] > 0) {
brt_flush_child(cursor->brt, node, childnum, cursor, db, txn);
brt_flush_child(cursor->brt, node, childnum, cursor, txn);
/*
* the flush may have been partially successfull. it may have also
* changed the tree such that the current node have expanded or been
......@@ -2494,7 +2486,7 @@ int brtcurs_set_position_first (BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db
brt_node_remove_cursor(node, childnum, cursor);
goto try_first_child;
}
r=brtcurs_set_position_first (cursor, node->u.n.children[childnum], key, db, txn, node);
r=brtcurs_set_position_first (cursor, node->u.n.children[childnum], key, txn, node);
if (r == 0)
return r;
assert(node == cursor->path[cursor->path_len-1]);
......@@ -2522,7 +2514,7 @@ int brtcurs_set_position_first (BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db
}
}
int brtcurs_set_position_next2(BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn) {
int brtcurs_set_position_next2(BRT_CURSOR cursor, DBT *key, TOKUTXN txn) {
BRTNODE node;
int childnum;
int r;
......@@ -2554,11 +2546,11 @@ int brtcurs_set_position_next2(BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn)
more = node->u.n.n_bytes_in_hashtable[childnum];
if (more == 0)
break;
brt_flush_child(cursor->brt, node, childnum, cursor, db, txn);
brt_flush_child(cursor->brt, node, childnum, cursor, txn);
node = cursor->path[cursor->path_len-1];
childnum = cursor->pathcnum[cursor->path_len-1];
}
r = brtcurs_set_position_first(cursor, node->u.n.children[childnum], key, db, txn, node);
r = brtcurs_set_position_first(cursor, node->u.n.children[childnum], key, txn, node);
if (r == 0)
return 0;
assert(node == cursor->path[cursor->path_len-1]);
......@@ -2566,11 +2558,11 @@ int brtcurs_set_position_next2(BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn)
childnum += 1;
}
return brtcurs_set_position_next2(cursor, key, db, txn);
return brtcurs_set_position_next2(cursor, key, txn);
}
/* requires that the cursor is initialized. */
int brtcurs_set_position_next (BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn) {
int brtcurs_set_position_next (BRT_CURSOR cursor, DBT *key, TOKUTXN txn) {
int r = toku_pma_cursor_set_position_next(cursor->pmacurs);
if (r==DB_NOTFOUND) {
/* We fell off the end of the pma. */
......@@ -2578,12 +2570,12 @@ int brtcurs_set_position_next (BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn)
/* Part of the trickyness is we need to leave the cursor pointing at the current (possibly deleted) value if there is no next value. */
r = toku_pma_cursor_free(&cursor->pmacurs);
assert(r == 0);
return brtcurs_set_position_next2(cursor, key, db, txn);
return brtcurs_set_position_next2(cursor, key, txn);
}
return 0;
}
int brtcurs_set_position_prev2(BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn) {
int brtcurs_set_position_prev2(BRT_CURSOR cursor, DBT *key, TOKUTXN txn) {
BRTNODE node;
int childnum;
int r;
......@@ -2615,11 +2607,11 @@ int brtcurs_set_position_prev2(BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn)
more = node->u.n.n_bytes_in_hashtable[childnum];
if (more == 0)
break;
brt_flush_child(cursor->brt, node, childnum, cursor, db, txn);
brt_flush_child(cursor->brt, node, childnum, cursor, txn);
node = cursor->path[cursor->path_len-1];
childnum = cursor->pathcnum[cursor->path_len-1];
}
r = brtcurs_set_position_last(cursor, node->u.n.children[childnum], key, db, txn, node);
r = brtcurs_set_position_last(cursor, node->u.n.children[childnum], key, txn, node);
if (r == 0)
return 0;
assert(node == cursor->path[cursor->path_len-1]);
......@@ -2627,22 +2619,22 @@ int brtcurs_set_position_prev2(BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn)
childnum -= 1;
}
return brtcurs_set_position_prev2(cursor, key, db, txn);
return brtcurs_set_position_prev2(cursor, key, txn);
}
int brtcurs_set_position_prev (BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn) {
int brtcurs_set_position_prev (BRT_CURSOR cursor, DBT *key, TOKUTXN txn) {
int r = toku_pma_cursor_set_position_prev(cursor->pmacurs);
if (r==DB_NOTFOUND) {
if (cursor->path_len==1)
return DB_NOTFOUND;
r = toku_pma_cursor_free(&cursor->pmacurs);
assert(r == 0);
return brtcurs_set_position_prev2(cursor, key, db, txn);
return brtcurs_set_position_prev2(cursor, key, txn);
}
return 0;
}
int brtcurs_set_key(BRT_CURSOR cursor, DISKOFF off, DBT *key, DBT *val, int flag, DB *db, TOKUTXN txn, BRTNODE parent_brtnode) {
int brtcurs_set_key(BRT_CURSOR cursor, DISKOFF off, DBT *key, DBT *val, int flag, TOKUTXN txn, BRTNODE parent_brtnode) {
BRT brt = cursor->brt;
void *node_v;
int r;
......@@ -2658,13 +2650,13 @@ int brtcurs_set_key(BRT_CURSOR cursor, DISKOFF off, DBT *key, DBT *val, int flag
if (node->height > 0) {
cursor->path_len += 1;
for (;;) {
childnum = brtnode_which_child(node, key, brt, db);
childnum = brtnode_which_child(node, key, brt);
cursor->path[cursor->path_len-1] = node;
cursor->pathcnum[cursor->path_len-1] = childnum;
brt_node_add_cursor(node, childnum, cursor);
int more = node->u.n.n_bytes_in_hashtable[childnum];
if (more > 0) {
brt_flush_child(cursor->brt, node, childnum, cursor, db, txn);
brt_flush_child(cursor->brt, node, childnum, cursor, txn);
node = cursor->path[cursor->path_len-1];
childnum = cursor->pathcnum[cursor->path_len-1];
brt_node_remove_cursor(node, childnum, cursor);
......@@ -2673,7 +2665,7 @@ int brtcurs_set_key(BRT_CURSOR cursor, DISKOFF off, DBT *key, DBT *val, int flag
}
break;
}
r = brtcurs_set_key(cursor, node->u.n.children[childnum], key, val, flag, db, txn, node);
r = brtcurs_set_key(cursor, node->u.n.children[childnum], key, val, flag, txn, node);
if (r != 0)
brt_node_remove_cursor(node, childnum, cursor);
} else {
......@@ -2682,9 +2674,9 @@ int brtcurs_set_key(BRT_CURSOR cursor, DISKOFF off, DBT *key, DBT *val, int flag
r = toku_pma_cursor(node->u.l.buffer, &cursor->pmacurs);
if (r == 0) {
if (flag == DB_SET)
r = toku_pma_cursor_set_key(cursor->pmacurs, key, db);
r = toku_pma_cursor_set_key(cursor->pmacurs, key);
else if (flag == DB_GET_BOTH)
r = toku_pma_cursor_set_both(cursor->pmacurs, key, val, db);
r = toku_pma_cursor_set_both(cursor->pmacurs, key, val);
else {
assert(0);
r = DB_NOTFOUND;
......@@ -2704,7 +2696,7 @@ int brtcurs_set_key(BRT_CURSOR cursor, DISKOFF off, DBT *key, DBT *val, int flag
return r;
}
int brtcurs_set_range(BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db, TOKUTXN txn, BRTNODE parent_brtnode) {
int brtcurs_set_range(BRT_CURSOR cursor, DISKOFF off, DBT *key, TOKUTXN txn, BRTNODE parent_brtnode) {
BRT brt = cursor->brt;
void *node_v;
int r;
......@@ -2720,7 +2712,7 @@ int brtcurs_set_range(BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db, TOKUTXN
if (node->height > 0) {
cursor->path_len += 1;
/* select a subtree by key */
childnum = brtnode_which_child(node, key, brt, db);
childnum = brtnode_which_child(node, key, brt);
next_child:
for (;;) {
cursor->path[cursor->path_len-1] = node;
......@@ -2728,7 +2720,7 @@ int brtcurs_set_range(BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db, TOKUTXN
brt_node_add_cursor(node, childnum, cursor);
int more = node->u.n.n_bytes_in_hashtable[childnum];
if (more > 0) {
brt_flush_child(cursor->brt, node, childnum, cursor, db, txn);
brt_flush_child(cursor->brt, node, childnum, cursor, txn);
node = cursor->path[cursor->path_len-1];
childnum = cursor->pathcnum[cursor->path_len-1];
brt_node_remove_cursor(node, childnum, cursor);
......@@ -2736,7 +2728,7 @@ int brtcurs_set_range(BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db, TOKUTXN
}
break;
}
r = brtcurs_set_range(cursor, node->u.n.children[childnum], key, db, txn, node);
r = brtcurs_set_range(cursor, node->u.n.children[childnum], key, txn, node);
if (r != 0) {
node = cursor->path[cursor->path_len-1];
childnum = cursor->pathcnum[cursor->path_len-1];
......@@ -2752,7 +2744,7 @@ int brtcurs_set_range(BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db, TOKUTXN
cursor->path[cursor->path_len-1] = node;
r = toku_pma_cursor(node->u.l.buffer, &cursor->pmacurs);
if (r == 0) {
r = toku_pma_cursor_set_range(cursor->pmacurs, key, db);
r = toku_pma_cursor_set_range(cursor->pmacurs, key);
if (r != 0) {
int rr = toku_pma_cursor_free(&cursor->pmacurs);
assert(rr == 0);
......@@ -2805,7 +2797,7 @@ static void assert_cursor_path(BRT_CURSOR cursor) {
assert(node->height == 0);
}
int brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags, DB *db, TOKUTXN txn) {
int brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags, TOKUTXN txn) {
int do_rmw=0;
int r;
CACHEKEY *rootp;
......@@ -2827,7 +2819,7 @@ int brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags, DB *db, TO
do_db_last:
r=unpin_cursor(cursor); if (r!=0) goto died0;
assert(cursor->pmacurs == 0);
r=brtcurs_set_position_last(cursor, *rootp, kbt, db, txn, null_brtnode); if (r!=0) goto died0;
r=brtcurs_set_position_last(cursor, *rootp, kbt, txn, null_brtnode); if (r!=0) goto died0;
r=toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt);
if (r == 0) assert_cursor_path(cursor);
break;
......@@ -2835,28 +2827,28 @@ int brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags, DB *db, TO
do_db_first:
r=unpin_cursor(cursor); if (r!=0) goto died0;
assert(cursor->pmacurs == 0);
r=brtcurs_set_position_first(cursor, *rootp, kbt, db, txn, null_brtnode); if (r!=0) goto died0;
r=brtcurs_set_position_first(cursor, *rootp, kbt, txn, null_brtnode); if (r!=0) goto died0;
r=toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt);
if (r == 0) assert_cursor_path(cursor);
break;
case DB_NEXT:
if (cursor->path_len<=0)
goto do_db_first;
r=brtcurs_set_position_next(cursor, kbt, db, txn); if (r!=0) goto died0;
r=brtcurs_set_position_next(cursor, kbt, txn); if (r!=0) goto died0;
r=toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt); if (r!=0) goto died0;
if (r == 0) assert_cursor_path(cursor);
break;
case DB_PREV:
if (cursor->path_len<= 0)
goto do_db_last;
r = brtcurs_set_position_prev(cursor, kbt, db, txn); if (r!=0) goto died0;
r = brtcurs_set_position_prev(cursor, kbt, txn); if (r!=0) goto died0;
r = toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt); if (r!=0) goto died0;
if (r == 0) assert_cursor_path(cursor);
break;
case DB_SET:
r = unpin_cursor(cursor);
assert(r == 0);
r = brtcurs_set_key(cursor, *rootp, kbt, vbt, DB_SET, db, txn, null_brtnode);
r = brtcurs_set_key(cursor, *rootp, kbt, vbt, DB_SET, txn, null_brtnode);
if (r != 0) goto died0;
r = toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt);
if (r != 0) goto died0;
......@@ -2864,13 +2856,13 @@ int brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags, DB *db, TO
case DB_GET_BOTH:
r = unpin_cursor(cursor);
assert(r == 0);
r = brtcurs_set_key(cursor, *rootp, kbt, vbt, DB_GET_BOTH, db, txn, null_brtnode);
r = brtcurs_set_key(cursor, *rootp, kbt, vbt, DB_GET_BOTH, txn, null_brtnode);
if (r != 0) goto died0;
break;
case DB_SET_RANGE:
r = unpin_cursor(cursor);
assert(r == 0);
r = brtcurs_set_range(cursor, *rootp, kbt, db, txn, null_brtnode);
r = brtcurs_set_range(cursor, *rootp, kbt, txn, null_brtnode);
if (r != 0) goto died0;
r = toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt);
if (r != 0) goto died0;
......
......@@ -9,7 +9,7 @@
#include "cachetable.h"
#include "log.h"
int open_brt (const char *fname, const char *dbname, int is_create, BRT *, int nodesize, CACHETABLE, TOKUTXN, int(*)(DB*,const DBT*,const DBT*));
int open_brt (const char *fname, const char *dbname, int is_create, BRT *, int nodesize, CACHETABLE, TOKUTXN, int(*)(DB*,const DBT*,const DBT*), DB*);
int brt_create(BRT *);
int brt_set_flags(BRT, int flags);
......@@ -21,9 +21,9 @@ int brt_set_cachetable(BRT, CACHETABLE);
int brt_open(BRT, const char *fname, const char *fname_in_env, const char *dbname, int is_create, int only_create, CACHETABLE ct, TOKUTXN txn);
int brt_remove_subdb(BRT brt, const char *dbname, u_int32_t flags);
int brt_insert (BRT, DBT *, DBT *, DB*, TOKUTXN);
int brt_lookup (BRT brt, DBT *k, DBT *v, DB*db);
int brt_delete (BRT brt, DBT *k, DB *db);
int brt_insert (BRT, DBT *, DBT *, TOKUTXN);
int brt_lookup (BRT brt, DBT *k, DBT *v);
int brt_delete (BRT brt, DBT *k);
int close_brt (BRT);
int dump_brt (BRT brt);
void brt_fsync (BRT); /* fsync, but don't clear the caches. */
......@@ -43,7 +43,7 @@ int show_brt_blocknumbers(BRT);
typedef struct brt_cursor *BRT_CURSOR;
int brt_cursor (BRT, BRT_CURSOR*);
int brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int brtc_flags, DB *db, TOKUTXN);
int brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int brtc_flags, TOKUTXN);
int brt_cursor_delete(BRT_CURSOR cursor, int flags);
int brt_cursor_close (BRT_CURSOR curs);
......
......@@ -102,3 +102,7 @@ void toku_test_keycompare (void) {
int toku_default_compare_fun (DB *db __attribute__((__unused__)), const DBT *a, const DBT*b) {
return toku_keycompare(a->data, a->size, b->data, b->size);
}
int dont_call_this_compare_fun (DB *db __attribute__((__unused__)), const DBT *a __attribute__((__unused__)), const DBT*b __attribute__((__unused__))) {
assert(0);
}
......@@ -5,3 +5,4 @@ int toku_keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2le
void toku_test_keycompare (void) ;
int toku_default_compare_fun (DB *, const DBT *, const DBT*);
int dont_call_this_compare_fun (DB *, const DBT *, const DBT*);
......@@ -208,14 +208,8 @@ int tokulogger_log_brt_insert_with_no_overwrite (TOKULOGGER logger,
}
int tokulogger_log_phys_add_or_delete_in_leaf (DB *db, TOKUTXN txn, DISKOFF diskoff, int is_add, const struct kv_pair *pair) {
assert(is_add==0);
if (txn==0) return 0;
if (is_add) {
BYTESTRING key = { pair->keylen, (char*)kv_pair_key_const(pair) };
BYTESTRING data = { pair->vallen, (char*)kv_pair_val_const(pair) };
//printf("Logging insertinleaf\n");
return toku_log_insertinleaf (txn, toku_txn_get_txnid(txn), db->i->fileid, diskoff, key, data);
}
assert(0);
assert(db);
int keylen = pair->keylen;
int vallen = pair->vallen;
......
......@@ -61,6 +61,7 @@ const struct logtype logtypes[] = {
{"insertinleaf", 'I', FA{{"TXNID", "txnid"},
{"FILENUM", "filenum"},
{"DISKOFF", "diskoff"},
{"u_int32_t", "pmaidx"},
{"BYTESTRING", "key"},
{"BYTESTRING", "data"},
NULLFIELD}},
......
......@@ -26,6 +26,8 @@ struct pma {
struct list cursors;
pma_compare_fun_t compare_fun;
pma_compare_fun_t dup_compare_fun;
DB *db; /* Passed to the compare functions. */
FILENUM filenum; /* Passed to logging. */
void *skey, *sval; /* used in dbts */
struct mempool kvspace;
};
......@@ -35,7 +37,7 @@ void toku_pmainternal_calculate_parameters (PMA pma);
int toku_pmainternal_smooth_region (struct kv_pair *pairs[], int n, int idx, int base, PMA pma);
int toku_pmainternal_printpairs (struct kv_pair *pairs[], int N);
int toku_pmainternal_make_space_at (PMA pma, int idx);
int toku_pmainternal_find (PMA pma, DBT *, DB*); // The DB is so the comparison fuction can be called.
int toku_pmainternal_find (PMA pma, DBT *); // The DB is so the comparison fuction can be called.
void toku_print_pma (PMA pma); /* useful for debugging, so keep the name short. I.e., not pmainternal_print_pma() */
/* density thresholds */
......
......@@ -11,8 +11,9 @@
TOKUTXN const null_txn = 0;
DB * const null_db = 0;
const DISKOFF null_diskoff = -1;
const FILENUM null_filenum = {0};
#define NULL_ARGS null_db, null_txn, null_diskoff
#define NULL_ARGS null_txn, null_diskoff
static void test_make_space_at (void) {
PMA pma;
......@@ -25,7 +26,7 @@ static void test_make_space_at (void) {
key = "B";
key_B = kv_pair_malloc(key, strlen(key)+1, 0, 0);
r=toku_pma_create(&pma, toku_default_compare_fun, 0);
r=toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
assert(r==0);
assert(toku_pma_n_entries(pma)==0);
r=toku_pmainternal_make_space_at(pma, 2);
......@@ -96,29 +97,29 @@ static void test_pma_find (void) {
for (i=0; i<N; i++) pma->pairs[i]=0;
assert(toku_pma_index_limit(pma)==N);
pma->compare_fun = toku_default_compare_fun;
r=toku_pmainternal_find(pma, fill_dbt(&k, "hello", 5), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "hello", 5));
assert(r==0);
pma->pairs[5] = kv_pair_malloc("hello", 5, 0, 0);
assert(toku_pma_index_limit(pma)==N);
r=toku_pmainternal_find(pma, fill_dbt(&k, "hello", 5), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "hello", 5));
assert(toku_pma_index_limit(pma)==N);
assert(r==5);
r=toku_pmainternal_find(pma, fill_dbt(&k, "there", 5), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "there", 5));
assert(r==6);
r=toku_pmainternal_find(pma, fill_dbt(&k, "aaa", 3), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "aaa", 3));
assert(r==0);
pma->pairs[N-1] = kv_pair_malloc("there", 5, 0, 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "hello", 5), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "hello", 5));
assert(r==5);
r=toku_pmainternal_find(pma, fill_dbt(&k, "there", 5), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "there", 5));
assert(r==N-1);
r=toku_pmainternal_find(pma, fill_dbt(&k, "aaa", 3), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "aaa", 3));
assert(r==0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "hellob", 6), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "hellob", 6));
assert(r==6);
r=toku_pmainternal_find(pma, fill_dbt(&k, "zzz", 3), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "zzz", 3));
assert(r==N);
for (i=0; i<N; i++)
......@@ -270,7 +271,7 @@ static void do_insert (PMA pma, const void *key, int keylen, const void *data, i
static void do_delete (PMA pma, const void *key, int keylen, const void *data, int datalen, u_int32_t rand4fingerprint, u_int32_t *sum, u_int32_t *expect_fingerprint) {
DBT k;
assert(*sum==*expect_fingerprint);
int r = toku_pma_delete(pma, fill_dbt(&k, key, keylen), 0, rand4fingerprint, sum, 0);
int r = toku_pma_delete(pma, fill_dbt(&k, key, keylen), rand4fingerprint, sum, 0);
assert(r==BRT_OK);
add_fingerprint_and_check(-rand4fingerprint, *sum, expect_fingerprint, key, keylen, data, datalen); // negative rand4 means subtract.
toku_pma_verify_fingerprint(pma, rand4fingerprint, *sum);
......@@ -278,7 +279,7 @@ static void do_delete (PMA pma, const void *key, int keylen, const void *data, i
static void test_pma_random_pick (void) {
PMA pma;
int r = toku_pma_create(&pma, toku_default_compare_fun, 0);
int r = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
bytevec key,val;
ITEMLEN keylen,vallen;
DBT k;
......@@ -297,7 +298,7 @@ static void test_pma_random_pick (void) {
assert(keylen==6); assert(vallen==6);
assert(strcmp(key,"hello")==0);
assert(strcmp(val,"there")==0);
r = toku_pma_delete(pma, fill_dbt(&k, "nothello", 9), 0, rand4fingerprint, &sum, 0);
r = toku_pma_delete(pma, fill_dbt(&k, "nothello", 9), rand4fingerprint, &sum, 0);
assert(r==DB_NOTFOUND);
assert(sum==expect_fingerprint); // didn't change because nothing was deleted.
......@@ -351,14 +352,14 @@ static void test_find_insert (void) {
u_int32_t expect_fingerprint = 0;
toku_pma_create(&pma, toku_default_compare_fun, 0);
r=toku_pma_lookup(pma, fill_dbt(&k, "aaa", 3), &v, 0);
toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
r=toku_pma_lookup(pma, fill_dbt(&k, "aaa", 3), &v);
assert(r==DB_NOTFOUND);
do_insert(pma, "aaa", 3, "aaadata", 7, rand4fingerprint, &sum, &expect_fingerprint);
init_dbt(&v);
r=toku_pma_lookup(pma, fill_dbt(&k, "aaa", 3), &v, 0);
r=toku_pma_lookup(pma, fill_dbt(&k, "aaa", 3), &v);
assert(r==BRT_OK);
assert(v.size==7);
assert(toku_keycompare(v.data,v.size,"aaadata", 7)==0);
......@@ -367,12 +368,12 @@ static void test_find_insert (void) {
do_insert(pma, "bbb", 4, "bbbdata", 8, rand4fingerprint, &sum, &expect_fingerprint);
init_dbt(&v);
r=toku_pma_lookup(pma, fill_dbt(&k, "aaa", 3), &v, 0);
r=toku_pma_lookup(pma, fill_dbt(&k, "aaa", 3), &v);
assert(r==BRT_OK);
assert(toku_keycompare(v.data,v.size,"aaadata", 7)==0);
init_dbt(&v);
r=toku_pma_lookup(pma, fill_dbt(&k, "bbb", 4), &v, 0);
r=toku_pma_lookup(pma, fill_dbt(&k, "bbb", 4), &v);
assert(r==BRT_OK);
assert(toku_keycompare(v.data,v.size,"bbbdata", 8)==0);
......@@ -383,7 +384,7 @@ static void test_find_insert (void) {
assert((unsigned long)pma->pairs[toku_pma_index_limit(pma)]==0xdeadbeefL);
r=toku_pma_free(&pma); assert(r==0); assert(pma==0);
toku_pma_create(&pma, toku_default_compare_fun, 0); assert(pma!=0);
toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0); assert(pma!=0);
rand4fingerprint = random();
sum = expect_fingerprint = 0;
......@@ -426,7 +427,7 @@ static void test_pma_iterate (void) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
toku_pma_create(&pma, toku_default_compare_fun, 0);
toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
do_insert(pma, "42", 3, "-19", 4, rand4fingerprint, &sum, &expect_fingerprint);
test_pma_iterate_internal(pma, 42, -19);
......@@ -449,8 +450,8 @@ static void test_pma_iterate2 (void) {
u_int32_t sum1 = 0;
u_int32_t expect_fingerprint1 = 0;
r=toku_pma_create(&pma0, toku_default_compare_fun, 0); assert(r==0);
r=toku_pma_create(&pma1, toku_default_compare_fun, 0); assert(r==0);
r=toku_pma_create(&pma0, toku_default_compare_fun, null_db, null_filenum, 0); assert(r==0);
r=toku_pma_create(&pma1, toku_default_compare_fun, null_db, null_filenum, 0); assert(r==0);
do_insert(pma0, "a", 2, "aval", 5, rand4fingerprint0, &sum0, &expect_fingerprint0);
do_insert(pma0, "b", 2, "bval", 5, rand4fingerprint0, &sum0, &expect_fingerprint0);
do_insert(pma1, "x", 2, "xval", 5, rand4fingerprint1, &sum1, &expect_fingerprint1);
......@@ -467,7 +468,7 @@ void test_pma_cursor_0 (void) {
PMA pma;
PMA_CURSOR c=0;
int r;
r=toku_pma_create(&pma, toku_default_compare_fun, 0); assert(r==0);
r=toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0); assert(r==0);
r=toku_pma_cursor(pma, &c); assert(r==0); assert(c!=0);
printf("%s:%d\n", __FILE__, __LINE__);
r=toku_pma_free(&pma); assert(r!=0); /* didn't deallocate the cursor. */
......@@ -485,7 +486,7 @@ void test_pma_cursor_1 (void) {
int r;
int order;
for (order=0; order<6; order++) {
r=toku_pma_create(&pma, toku_default_compare_fun, 0); assert(r==0);
r=toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0); assert(r==0);
r=toku_pma_cursor(pma, &c0); assert(r==0); assert(c0!=0);
r=toku_pma_cursor(pma, &c1); assert(r==0); assert(c1!=0);
r=toku_pma_cursor(pma, &c2); assert(r==0); assert(c2!=0);
......@@ -516,7 +517,7 @@ void test_pma_cursor_2 (void) {
DBT key,val;
init_dbt(&key); key.flags=DB_DBT_REALLOC;
init_dbt(&val); val.flags=DB_DBT_REALLOC;
r=toku_pma_create(&pma, toku_default_compare_fun, 0); assert(r==0);
r=toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0); assert(r==0);
r=toku_pma_cursor(pma, &c); assert(r==0); assert(c!=0);
r=toku_pma_cursor_set_position_last(c); assert(r==DB_NOTFOUND);
r=toku_pma_cursor_free(&c); assert(r==0);
......@@ -533,7 +534,7 @@ void test_pma_cursor_3 (void) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r=toku_pma_create(&pma, toku_default_compare_fun, 0); assert(r==0);
r=toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0); assert(r==0);
do_insert(pma, "x", 2, "xx", 3, rand4fingerprint, &sum, &expect_fingerprint);
do_insert(pma, "m", 2, "mm", 3, rand4fingerprint, &sum, &expect_fingerprint);
do_insert(pma, "aa", 3, "a", 2, rand4fingerprint, &sum, &expect_fingerprint);
......@@ -599,7 +600,7 @@ void test_pma_cursor_4 (void) {
u_int32_t expect_fingerprint = 0;
printf("test_pma_cursor_4\n");
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
for (i=1; i<=4; i += 1) {
......@@ -668,7 +669,7 @@ void test_pma_cursor_delete(int n) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
/* insert 1 -> 42 */
......@@ -776,7 +777,9 @@ void test_pma_compare_fun (int wrong_endian_p) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = toku_pma_create(&pma, wrong_endian_p ? wrong_endian_compare_fun : toku_default_compare_fun, 0); assert(r==0);
r = toku_pma_create(&pma, wrong_endian_p ? wrong_endian_compare_fun : toku_default_compare_fun,
null_db, null_filenum,
0); assert(r==0);
do_insert(pma, "10", 3, "10v", 4, rand4fingerprint, &sum, &expect_fingerprint);
do_insert(pma, "00", 3, "00v", 4, rand4fingerprint, &sum, &expect_fingerprint);
do_insert(pma, "01", 3, "01v", 4, rand4fingerprint, &sum, &expect_fingerprint);
......@@ -824,11 +827,11 @@ void test_pma_split_n(int n) {
printf("test_pma_split_n:%d\n", n);
error = toku_pma_create(&pmaa, toku_default_compare_fun, 0);
error = toku_pma_create(&pmaa, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
error = toku_pma_create(&pmab, toku_default_compare_fun, 0);
error = toku_pma_create(&pmab, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
error = toku_pma_create(&pmac, toku_default_compare_fun, 0);
error = toku_pma_create(&pmac, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
/* insert some kv pairs */
......@@ -839,16 +842,16 @@ void test_pma_split_n(int n) {
v = i;
do_insert(pmaa, k, strlen(k)+1, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
toku_pma_verify(pmaa, null_db);
toku_pma_verify(pmaa);
}
printf("a:"); toku_print_pma(pmaa);
error = toku_pma_split(pmaa, 0, 0, null_db, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
error = toku_pma_split(pmaa, 0, 0, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
assert(error == 0);
toku_pma_verify(pmaa, null_db);
toku_pma_verify(pmab, null_db);
toku_pma_verify(pmac, null_db);
toku_pma_verify(pmaa);
toku_pma_verify(pmab);
toku_pma_verify(pmac);
toku_pma_verify_fingerprint(pmab, brand, bsum);
toku_pma_verify_fingerprint(pmac, crand, csum);
......@@ -887,13 +890,13 @@ void test_pma_dup_split_n(int n, int dup_mode) {
printf("test_pma_dup_split_n:%d %d\n", n, dup_mode);
error = toku_pma_create(&pmaa, toku_default_compare_fun, 0);
error = toku_pma_create(&pmaa, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
toku_pma_set_dup_mode(pmaa, dup_mode);
error = toku_pma_create(&pmab, toku_default_compare_fun, 0);
error = toku_pma_create(&pmab, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
toku_pma_set_dup_mode(pmab, dup_mode);
error = toku_pma_create(&pmac, toku_default_compare_fun, 0);
error = toku_pma_create(&pmac, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
toku_pma_set_dup_mode(pmac, dup_mode);
......@@ -903,18 +906,18 @@ void test_pma_dup_split_n(int n, int dup_mode) {
int v = i;
do_insert(pmaa, &dupkey, sizeof dupkey, &v, sizeof v, rand4sum, &sum, &expect_sum);
toku_pma_verify(pmaa, null_db);
toku_pma_verify(pmaa);
}
printf("a:"); toku_print_pma(pmaa);
DBT splitk;
error = toku_pma_split(pmaa, 0, &splitk, null_db, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
error = toku_pma_split(pmaa, 0, &splitk, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
assert(error == 0);
toku_pma_verify(pmaa, null_db);
toku_pma_verify(pmab, null_db);
toku_pma_verify(pmac, null_db);
toku_pma_verify(pmaa);
toku_pma_verify(pmab);
toku_pma_verify(pmac);
toku_pma_verify_fingerprint(pmab, brand, bsum);
toku_pma_verify_fingerprint(pmac, crand, csum);
......@@ -966,11 +969,11 @@ void test_pma_split_varkey(void) {
printf("test_pma_split_varkey\n");
error = toku_pma_create(&pmaa, toku_default_compare_fun, 0);
error = toku_pma_create(&pmaa, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
error = toku_pma_create(&pmab, toku_default_compare_fun, 0);
error = toku_pma_create(&pmab, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
error = toku_pma_create(&pmac, toku_default_compare_fun, 0);
error = toku_pma_create(&pmac, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
/* insert some kv pairs */
......@@ -982,11 +985,11 @@ void test_pma_split_varkey(void) {
printf("a:"); toku_print_pma(pmaa);
error = toku_pma_split(pmaa, 0, 0, null_db, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
error = toku_pma_split(pmaa, 0, 0, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
assert(error == 0);
toku_pma_verify(pmaa, null_db);
toku_pma_verify(pmab, null_db);
toku_pma_verify(pmac, null_db);
toku_pma_verify(pmaa);
toku_pma_verify(pmab);
toku_pma_verify(pmac);
toku_pma_verify_fingerprint(pmab, brand, bsum);
toku_pma_verify_fingerprint(pmac, crand, csum);
......@@ -1084,11 +1087,11 @@ void test_pma_split_cursor(void) {
printf("test_pma_split_cursor\n");
error = toku_pma_create(&pmaa, toku_default_compare_fun, 0);
error = toku_pma_create(&pmaa, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
error = toku_pma_create(&pmab, toku_default_compare_fun, 0);
error = toku_pma_create(&pmab, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
error = toku_pma_create(&pmac, toku_default_compare_fun, 0);
error = toku_pma_create(&pmac, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
/* insert some kv pairs */
......@@ -1126,7 +1129,7 @@ void test_pma_split_cursor(void) {
// print_cursor("cursorc", cursorc);
assert_cursor_val(cursorc, 16);
error = toku_pma_split(pmaa, 0, 0, null_db, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
error = toku_pma_split(pmaa, 0, 0, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
assert(error == 0);
toku_pma_verify_fingerprint(pmab, brand, bsum);
......@@ -1204,7 +1207,7 @@ void test_pma_bulk_insert_n(int n) {
printf("test_pma_bulk_insert_n: %d\n", n);
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
/* init n kv pairs */
......@@ -1239,7 +1242,7 @@ void test_pma_bulk_insert_n(int n) {
error = toku_pma_bulk_insert(pma, keys, vals, n, rand4fingerprint, &sum);
assert(error == 0);
assert(sum==expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
toku_pma_verify_fingerprint(pma, rand4fingerprint, sum);
/* verify */
......@@ -1248,7 +1251,7 @@ void test_pma_bulk_insert_n(int n) {
for (i=0; i<n; i++) {
DBT val;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
error = toku_pma_lookup(pma, &keys[i], &val, 0);
error = toku_pma_lookup(pma, &keys[i], &val);
assert(error == 0);
assert(vals[i].size == val.size);
assert(memcmp(vals[i].data, val.data, val.size) == 0);
......@@ -1287,23 +1290,23 @@ void test_pma_insert_or_replace(void) {
u_int32_t rand4fingerprint = random();
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = toku_pma_create(&pma, toku_default_compare_fun, 0);
r = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
assert(r==0);
r = toku_pma_insert_or_replace(pma, fill_dbt(&dbtk, "aaa", 4), fill_dbt(&dbtv, "zzz", 4), &n_diff, NULL_ARGS, rand4fingerprint, &sum);
assert(r==0); assert(n_diff==-1);
add_fingerprint_and_check(rand4fingerprint, sum, &expect_fingerprint, "aaa", 4, "zzz", 4);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "aaa", 4), init_dbt(&dbtv), 0);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "aaa", 4), init_dbt(&dbtv));
assert(r==0); assert(dbtv.size==4); assert(memcmp(dbtv.data, "zzz", 4)==0);
r = toku_pma_insert_or_replace(pma, fill_dbt(&dbtk, "bbbb", 5), fill_dbt(&dbtv, "ww", 3), &n_diff, NULL_ARGS, rand4fingerprint, &sum);
assert(r==0); assert(n_diff==-1);
add_fingerprint_and_check(rand4fingerprint, sum, &expect_fingerprint, "bbbb", 5, "ww", 3);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "aaa", 4), init_dbt(&dbtv), 0);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "aaa", 4), init_dbt(&dbtv));
assert(r==0); assert(dbtv.size==4); assert(memcmp(dbtv.data, "zzz", 4)==0);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "bbbb", 5), init_dbt(&dbtv), 0);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "bbbb", 5), init_dbt(&dbtv));
assert(r==0); assert(dbtv.size==3); assert(memcmp(dbtv.data, "ww", 3)==0);
// replae bbbb
......@@ -1312,10 +1315,10 @@ void test_pma_insert_or_replace(void) {
expect_fingerprint -= rand4fingerprint*toku_calccrc32_kvpair("bbbb", 5, "ww", 3);
add_fingerprint_and_check(rand4fingerprint, sum, &expect_fingerprint, "bbbb", 5, "xxxx", 5);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "aaa", 4), init_dbt(&dbtv), 0);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "aaa", 4), init_dbt(&dbtv));
assert(r==0); assert(dbtv.size==4); assert(memcmp(dbtv.data, "zzz", 4)==0);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "bbbb", 5), init_dbt(&dbtv), 0);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "bbbb", 5), init_dbt(&dbtv));
assert(r==0); assert(dbtv.size==5); assert(memcmp(dbtv.data, "xxxx", 3)==0);
r=toku_pma_free(&pma);
......@@ -1336,7 +1339,7 @@ void test_pma_delete_shrink(int n) {
printf("test_pma_delete_shrink:%d\n", n);
r = toku_pma_create(&pma, toku_default_compare_fun, n*(8 + 11 + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, n*(8 + 11 + sizeof (int)));
assert(r == 0);
/* insert */
......@@ -1380,7 +1383,7 @@ void test_pma_delete_random(int n) {
printf("test_pma_delete_random:%d\n", n);
r = toku_pma_create(&pma, toku_default_compare_fun, n * (8 + 11 + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, n * (8 + 11 + sizeof (int)));
assert(r == 0);
for (i=0; i<n; i++) {
......@@ -1454,7 +1457,7 @@ void test_pma_delete_cursor(int n) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = toku_pma_create(&pma, toku_default_compare_fun, 0);
r = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
assert(r == 0);
int i;
......@@ -1517,7 +1520,7 @@ void test_pma_delete_insert() {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
PMA_CURSOR pmacursor;
......@@ -1542,7 +1545,7 @@ void test_pma_delete_insert() {
k = 1;
fill_dbt(&key, &k, sizeof k);
init_dbt(&val); val.flags = DB_DBT_MALLOC;
error = toku_pma_lookup(pma, &key, &val, 0);
error = toku_pma_lookup(pma, &key, &val);
assert(error != 0);
k = 1; v = 2;
......@@ -1566,7 +1569,7 @@ void test_pma_double_delete() {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
PMA_CURSOR pmacursor;
......@@ -1590,7 +1593,7 @@ void test_pma_double_delete() {
k = 1;
fill_dbt(&key, &k, sizeof k);
error = toku_pma_delete(pma, &key, 0, rand4fingerprint, &sum, 0);
error = toku_pma_delete(pma, &key, rand4fingerprint, &sum, 0);
assert(error == DB_NOTFOUND);
assert(sum == expect_fingerprint);
......@@ -1611,7 +1614,7 @@ void test_pma_cursor_first_delete_last() {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
int k, v;
......@@ -1658,7 +1661,7 @@ void test_pma_cursor_last_delete_first() {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
int k, v;
......@@ -1714,7 +1717,7 @@ void test_pma_already_there() {
u_int32_t rand4fingerprint = random();
u_int32_t sum = 0;
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
DBT key, val;
......@@ -1740,7 +1743,7 @@ void test_pma_cursor_set_key() {
int error;
PMA pma;
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
DBT key, val;
......@@ -1765,7 +1768,7 @@ void test_pma_cursor_set_key() {
for (i=0; i<n; i += 1) {
k = htonl(i);
fill_dbt(&key, &k, sizeof k);
error = toku_pma_cursor_set_key(cursor, &key, 0);
error = toku_pma_cursor_set_key(cursor, &key);
if (i % 10 == 0) {
assert(error == 0);
init_dbt(&val); val.flags = DB_DBT_MALLOC;
......@@ -1800,7 +1803,7 @@ void test_pma_cursor_set_range() {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, 0);
assert(error == 0);
DBT key, val;
......@@ -1822,7 +1825,7 @@ void test_pma_cursor_set_range() {
for (i=0; i<100; i += 1) {
k = htonl(i);
fill_dbt(&key, &k, sizeof k);
error = toku_pma_cursor_set_range(cursor, &key, 0);
error = toku_pma_cursor_set_range(cursor, &key);
if (error != 0) {
assert(error == DB_NOTFOUND);
assert(i > largest_key);
......@@ -1860,7 +1863,7 @@ void test_pma_cursor_delete_under() {
const int n = 1000;
error = toku_pma_create(&pma, toku_default_compare_fun, n * (8 + sizeof (int) + sizeof (int)));
error = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, n * (8 + sizeof (int) + sizeof (int)));
assert(error == 0);
PMA_CURSOR cursor;
......@@ -1932,7 +1935,7 @@ void test_pma_cursor_set_both() {
const int n = 1000;
error = toku_pma_create(&pma, toku_default_compare_fun, n * (8 + sizeof (int) + sizeof (int)));
error = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, n * (8 + sizeof (int) + sizeof (int)));
assert(error == 0);
PMA_CURSOR cursor;
......@@ -1955,7 +1958,7 @@ void test_pma_cursor_set_both() {
k = n+1; v = 0;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = toku_pma_cursor_set_both(cursor, &key, &val, 0);
error = toku_pma_cursor_set_both(cursor, &key, &val);
assert(error == DB_NOTFOUND);
/* key match, data mismatch should fail */
......@@ -1964,7 +1967,7 @@ void test_pma_cursor_set_both() {
v = i+1;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = toku_pma_cursor_set_both(cursor, &key, &val, 0);
error = toku_pma_cursor_set_both(cursor, &key, &val);
assert(error == DB_NOTFOUND);
}
......@@ -1974,7 +1977,7 @@ void test_pma_cursor_set_both() {
v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = toku_pma_cursor_set_both(cursor, &key, &val, 0);
error = toku_pma_cursor_set_both(cursor, &key, &val);
assert(error == 0);
init_dbt(&key); key.flags = DB_DBT_MALLOC;
......@@ -2007,7 +2010,7 @@ void test_nodup_key_insert(int n) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = toku_pma_create(&pma, toku_default_compare_fun, n * (8 + sizeof (int) + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, n * (8 + sizeof (int) + sizeof (int)));
assert(r == 0);
/* insert 0->0, 0->1, .. 0->n-1 */
......@@ -2044,9 +2047,9 @@ void test_dup_key_insert(int n) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = toku_pma_create(&pma, toku_default_compare_fun, (n + 2) * (8 + sizeof (int) + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, (n + 2) * (8 + sizeof (int) + sizeof (int)));
assert(r == 0);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
r = toku_pma_set_dup_mode(pma, TOKU_DB_DUP);
assert(r == 0);
......@@ -2058,10 +2061,10 @@ void test_dup_key_insert(int n) {
/* insert 1->1, 3->3 */
k = htonl(1); v = 1;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
k = htonl(3); v = 3;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
int i;
/* insert 2->0, 2->1, .. 2->n-1 */
......@@ -2069,7 +2072,7 @@ void test_dup_key_insert(int n) {
k = htonl(2);
v = i;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
}
/* cursor walk from key k should find values 0, 1, .. n-1 */
......@@ -2079,7 +2082,7 @@ void test_dup_key_insert(int n) {
k = htonl(2);
fill_dbt(&key, &k, sizeof k);
r = toku_pma_cursor_set_key(cursor, &key, 0);
r = toku_pma_cursor_set_key(cursor, &key);
if (r != 0) {
assert(n == 0);
} else {
......@@ -2131,9 +2134,9 @@ void test_dup_key_delete(int n, int mode) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = toku_pma_create(&pma, toku_default_compare_fun, (n + 2) * (8 + sizeof (int) + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, (n + 2) * (8 + sizeof (int) + sizeof (int)));
assert(r == 0);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
r = toku_pma_set_dup_mode(pma, mode);
assert(r == 0);
......@@ -2149,10 +2152,10 @@ void test_dup_key_delete(int n, int mode) {
/* insert 1->1, 3->3 */
k = htonl(1); v = 1;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
k = htonl(3); v = 3;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
u_int32_t sum_before_all_the_duplicates = sum;
int i;
......@@ -2161,15 +2164,15 @@ void test_dup_key_delete(int n, int mode) {
k = htonl(2);
v = i;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
}
k = htonl(2);
r = toku_pma_delete(pma, fill_dbt(&key, &k, sizeof k), null_db, rand4fingerprint, &sum, 0);
r = toku_pma_delete(pma, fill_dbt(&key, &k, sizeof k), rand4fingerprint, &sum, 0);
if (r != 0) assert(n == 0);
expect_fingerprint = sum_before_all_the_duplicates;
assert(sum == expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
toku_pma_verify_fingerprint(pma, rand4fingerprint, sum);
/* cursor walk should find keys 1, 3 */
......@@ -2232,9 +2235,9 @@ void test_dupsort_key_insert(int n, int dup_data) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = toku_pma_create(&pma, toku_default_compare_fun, (n + 2) * (8 + sizeof (int) + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, (n + 2) * (8 + sizeof (int) + sizeof (int)));
assert(r == 0);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
r = toku_pma_set_dup_mode(pma, TOKU_DB_DUP+TOKU_DB_DUPSORT);
assert(r == 0);
......@@ -2248,10 +2251,10 @@ void test_dupsort_key_insert(int n, int dup_data) {
/* insert 1->1, 3->3 */
k = htonl(1); v = 1;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
k = htonl(3); v = 3;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
k = htonl(2);
int values[n];
......@@ -2262,7 +2265,7 @@ void test_dupsort_key_insert(int n, int dup_data) {
/* insert 2->n-i */
for (i=0; i<n; i++) {
do_insert(pma, &k, sizeof k, &values[i], sizeof values[i], rand4fingerprint, &sum, &expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
}
/* cursor walk from key k should find values 0, 1, .. n-1 */
......@@ -2271,7 +2274,7 @@ void test_dupsort_key_insert(int n, int dup_data) {
assert(r == 0);
fill_dbt(&key, &k, sizeof k);
r = toku_pma_cursor_set_key(cursor, &key, 0);
r = toku_pma_cursor_set_key(cursor, &key);
if (r != 0) {
assert(n == 0);
} else {
......@@ -2326,9 +2329,9 @@ void test_dup_key_lookup(int n, int mode) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = toku_pma_create(&pma, toku_default_compare_fun, (n + 2) * (8 + sizeof (int) + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, null_db, null_filenum, (n + 2) * (8 + sizeof (int) + sizeof (int)));
assert(r == 0);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
r = toku_pma_set_dup_mode(pma, mode);
assert(r == 0);
......@@ -2344,10 +2347,10 @@ void test_dup_key_lookup(int n, int mode) {
/* insert 1->1, 3->3 */
k = htonl(1); v = 1;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
k = htonl(3); v = 3;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
int i;
/* insert 2->0, 2->1, .. 2->n-1 */
......@@ -2355,12 +2358,12 @@ void test_dup_key_lookup(int n, int mode) {
k = htonl(2);
v = htonl(i);
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
toku_pma_verify(pma, null_db);
toku_pma_verify(pma);
}
/* lookup should find the first insert and smallest value */
k = htonl(2);
r = toku_pma_lookup(pma, fill_dbt(&key, &k, sizeof k), fill_dbt(&val, &v, sizeof v), null_db);
r = toku_pma_lookup(pma, fill_dbt(&key, &k, sizeof k), fill_dbt(&val, &v, sizeof v));
assert(r == 0);
int kk;
assert(key.size == sizeof k);
......
......@@ -15,6 +15,7 @@
#include "kv-pair.h"
#include "pma-internal.h"
#include "log.h"
#include "log_header.h"
/* get KEY_VALUE_OVERHEAD */
#include "brt-internal.h"
......@@ -63,7 +64,7 @@ static void __pma_delete_resume(PMA pma, int here);
*/
static int __pma_count_cursor_refs(PMA pma, int here);
static int __pma_compare_kv(PMA pma, struct kv_pair *a, struct kv_pair *b, DB *db);
static int __pma_compare_kv(PMA pma, struct kv_pair *a, struct kv_pair *b);
/**************************** end of static functions forward declarations. *********************/
......@@ -230,7 +231,7 @@ void toku_pma_show_stats (void) {
}
/* search the index for a matching key */
static int __pma_search(PMA pma, DBT *k, DB *db, int lo, int hi, int *found) {
static int __pma_search(PMA pma, DBT *k, int lo, int hi, int *found) {
assert(0 <= lo && lo <= hi);
if (lo >= hi) {
*found = 0;
......@@ -242,21 +243,21 @@ static int __pma_search(PMA pma, DBT *k, DB *db, int lo, int hi, int *found) {
while (mi < hi && !kv_pair_inuse(pma->pairs[mi]))
mi++;
if (mi >= hi)
return __pma_search(pma, k, db, lo, omi, found);
return __pma_search(pma, k, lo, omi, found);
struct kv_pair *kv = kv_pair_ptr(pma->pairs[mi]);
DBT k2;
int cmp = pma->compare_fun(db, k, fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
int cmp = pma->compare_fun(pma->db, k, fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
if (cmp > 0)
return __pma_search(pma, k, db, mi+1, hi, found);
return __pma_search(pma, k, mi+1, hi, found);
if (cmp < 0)
return __pma_search(pma, k, db, lo, mi, found);
return __pma_search(pma, k, lo, mi, found);
*found = 1;
return mi;
}
}
/* search the index for the rightmost matching key */
static int __pma_right_search(PMA pma, DBT *k, DB *db, int lo, int hi, int *found) {
static int __pma_right_search(PMA pma, DBT *k, int lo, int hi, int *found) {
assert(0 <= lo && lo <= hi);
if (lo >= hi) {
*found = 0;
......@@ -268,18 +269,18 @@ static int __pma_right_search(PMA pma, DBT *k, DB *db, int lo, int hi, int *foun
while (mi < hi && !kv_pair_inuse(pma->pairs[mi]))
mi++;
if (mi >= hi)
return __pma_right_search(pma, k, db, lo, omi, found);
return __pma_right_search(pma, k, lo, omi, found);
struct kv_pair *kv = kv_pair_ptr(pma->pairs[mi]);
DBT k2;
int cmp = pma->compare_fun(db, k, fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
int cmp = pma->compare_fun(pma->db, k, fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
if (cmp > 0)
return __pma_right_search(pma, k, db, mi+1, hi, found);
return __pma_right_search(pma, k, mi+1, hi, found);
if (cmp < 0)
return __pma_right_search(pma, k, db, lo, mi, found);
return __pma_right_search(pma, k, lo, mi, found);
/* we have a match, try to find a match on the right tree */
int here;
here = __pma_right_search(pma, k, db, mi+1, hi, found);
here = __pma_right_search(pma, k, mi+1, hi, found);
if (*found == 0)
here = mi;
*found = 1;
......@@ -288,7 +289,7 @@ static int __pma_right_search(PMA pma, DBT *k, DB *db, int lo, int hi, int *foun
}
/* search the index for the left most matching key */
static int __pma_left_search(PMA pma, DBT *k, DB *db, int lo, int hi, int *found) {
static int __pma_left_search(PMA pma, DBT *k, int lo, int hi, int *found) {
assert(0 <= lo && lo <= hi);
if (lo >= hi) {
*found = 0;
......@@ -300,18 +301,18 @@ static int __pma_left_search(PMA pma, DBT *k, DB *db, int lo, int hi, int *found
while (mi < hi && !kv_pair_inuse(pma->pairs[mi]))
mi++;
if (mi >= hi)
return __pma_left_search(pma, k, db, lo, omi, found);
return __pma_left_search(pma, k, lo, omi, found);
struct kv_pair *kv = kv_pair_ptr(pma->pairs[mi]);
DBT k2;
int cmp = pma->compare_fun(db, k, fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
int cmp = pma->compare_fun(pma->db, k, fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
if (cmp > 0)
return __pma_left_search(pma, k, db, mi+1, hi, found);
return __pma_left_search(pma, k, mi+1, hi, found);
if (cmp < 0)
return __pma_left_search(pma, k, db, lo, mi, found);
return __pma_left_search(pma, k, lo, mi, found);
/* we have a match, try to find a match on the left tree */
int here;
here = __pma_left_search(pma, k, db, lo, mi, found);
here = __pma_left_search(pma, k, lo, mi, found);
if (*found == 0)
here = mi;
*found = 1;
......@@ -320,7 +321,7 @@ static int __pma_left_search(PMA pma, DBT *k, DB *db, int lo, int hi, int *found
}
/* search the index for the right most matching key and value */
static int __pma_dup_search(PMA pma, DBT *k, DBT *v, DB *db, int lo, int hi, int *found) {
static int __pma_dup_search(PMA pma, DBT *k, DBT *v, int lo, int hi, int *found) {
assert(0 <= lo && lo <= hi);
if (lo >= hi) {
*found = 0;
......@@ -332,20 +333,20 @@ static int __pma_dup_search(PMA pma, DBT *k, DBT *v, DB *db, int lo, int hi, int
while (mi < hi && !kv_pair_inuse(pma->pairs[mi]))
mi++;
if (mi >= hi)
return __pma_dup_search(pma, k, v, db, lo, omi, found);
return __pma_dup_search(pma, k, v, lo, omi, found);
struct kv_pair *kv = kv_pair_ptr(pma->pairs[mi]);
DBT k2, v2;
int cmp = pma->compare_fun(db, k, fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
int cmp = pma->compare_fun(pma->db, k, fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
if (cmp == 0)
cmp = pma->dup_compare_fun(db, v, fill_dbt(&v2, kv_pair_val(kv), kv_pair_vallen(kv)));
cmp = pma->dup_compare_fun(pma->db, v, fill_dbt(&v2, kv_pair_val(kv), kv_pair_vallen(kv)));
if (cmp > 0)
return __pma_dup_search(pma, k, v, db, mi+1, hi, found);
return __pma_dup_search(pma, k, v, mi+1, hi, found);
if (cmp < 0)
return __pma_dup_search(pma, k, v, db, lo, mi, found);
return __pma_dup_search(pma, k, v, lo, mi, found);
/* we have a match, try to find a match on the right tree */
int here;
here = __pma_dup_search(pma, k, v, db, mi+1, hi, found);
here = __pma_dup_search(pma, k, v, mi+1, hi, found);
if (*found == 0)
here = mi;
*found = 1;
......@@ -359,7 +360,7 @@ static int __pma_dup_search(PMA pma, DBT *k, DBT *v, DB *db, int lo, int hi, int
// For example: if the array is empty, that means we return 0.
// For example: if the array is full of small keys, that means we return toku_pma_index_limit(pma), which is off the end of teh array.
// For example: if the array is full of large keys, then we return 0.
int toku_pmainternal_find (PMA pma, DBT *k, DB *db) {
int toku_pmainternal_find (PMA pma, DBT *k) {
#if 1
int lo=0, hi=toku_pma_index_limit(pma);
/* lo and hi are the minimum and maximum values (inclusive) that we could possibly return. */
......@@ -373,7 +374,7 @@ int toku_pmainternal_find (PMA pma, DBT *k, DB *db) {
// Found one.
kv = kv_pair_ptr(kv);
DBT k2;
int cmp = pma->compare_fun(db, k, fill_dbt(&k2, kv->key, kv->keylen));
int cmp = pma->compare_fun(pma->db, k, fill_dbt(&k2, kv->key, kv->keylen));
if (cmp==0) return mid;
else if (cmp<0) {
/* key is smaller than the midpoint, so look in the low half. */
......@@ -557,7 +558,7 @@ int toku_pmainternal_count_region (struct kv_pair *pairs[], int lo, int hi) {
return n;
}
int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, int maxsize) {
int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, DB *db, FILENUM filenum, int maxsize) {
int error;
TAGMALLOC(PMA, result);
if (result==0) return -1;
......@@ -566,6 +567,8 @@ int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, int maxsize) {
result->pairs = 0;
list_init(&result->cursors);
result->compare_fun = compare_fun;
result->db = db;
result->filenum = filenum;
result->skey = 0;
result->sval = 0;
result->N = PMA_MIN_ARRAY_SIZE;
......@@ -731,20 +734,20 @@ int toku_pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val) {
return 0;
}
int toku_pma_cursor_set_key(PMA_CURSOR c, DBT *key, DB *db) {
int toku_pma_cursor_set_key(PMA_CURSOR c, DBT *key) {
PMA pma = c->pma;
int here, found;
if (pma->dup_mode & TOKU_DB_DUP) {
here = __pma_left_search(pma, key, db, 0, pma->N, &found);
here = __pma_left_search(pma, key, 0, pma->N, &found);
} else
here = toku_pmainternal_find(pma, key, db);
here = toku_pmainternal_find(pma, key);
assert(0<=here ); assert(here<=toku_pma_index_limit(pma));
int r = DB_NOTFOUND;
if (here < pma->N) {
DBT k2;
struct kv_pair *pair = pma->pairs[here];
if (kv_pair_valid(pair) &&
pma->compare_fun(db, key, fill_dbt(&k2, kv_pair_key(pair), kv_pair_keylen(pair)))==0) {
pma->compare_fun(pma->db, key, fill_dbt(&k2, kv_pair_key(pair), kv_pair_keylen(pair)))==0) {
__pma_delete_resume(c->pma, c->position);
c->position = here;
r = 0;
......@@ -753,17 +756,17 @@ int toku_pma_cursor_set_key(PMA_CURSOR c, DBT *key, DB *db) {
return r;
}
int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val, DB *db) {
int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val) {
PMA pma = c->pma;
int here = toku_pmainternal_find(pma, key, db);
int here = toku_pmainternal_find(pma, key);
assert(0<=here ); assert(here<=toku_pma_index_limit(pma));
int r = DB_NOTFOUND;
if (here < pma->N) {
DBT k2, v2;
struct kv_pair *pair = pma->pairs[here];
if (kv_pair_valid(pair) &&
pma->compare_fun(db, key, fill_dbt(&k2, kv_pair_key(pair), kv_pair_keylen(pair))) == 0 &&
pma->compare_fun(db, val, fill_dbt(&v2, kv_pair_val(pair), kv_pair_vallen(pair))) == 0) {
pma->compare_fun(pma->db, key, fill_dbt(&k2, kv_pair_key(pair), kv_pair_keylen(pair))) == 0 &&
pma->compare_fun(pma->db, val, fill_dbt(&v2, kv_pair_val(pair), kv_pair_vallen(pair))) == 0) {
__pma_delete_resume(c->pma, c->position);
c->position = here;
r = 0;
......@@ -772,13 +775,13 @@ int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val, DB *db) {
return r;
}
int toku_pma_cursor_set_range(PMA_CURSOR c, DBT *key, DB *db) {
int toku_pma_cursor_set_range(PMA_CURSOR c, DBT *key) {
PMA pma = c->pma;
int here, found;
if (pma->dup_mode & TOKU_DB_DUP)
here = __pma_left_search(pma, key, db, 0, pma->N, &found);
here = __pma_left_search(pma, key, 0, pma->N, &found);
else
here = toku_pmainternal_find(pma, key, db);
here = toku_pmainternal_find(pma, key);
assert(0<=here ); assert(here<=toku_pma_index_limit(pma));
/* find the first valid pair where key[here] >= key */
......@@ -883,18 +886,18 @@ int toku_pmainternal_make_space_at (PMA pma, int idx) {
}
}
enum pma_errors toku_pma_lookup (PMA pma, DBT *k, DBT *v, DB *db) {
enum pma_errors toku_pma_lookup (PMA pma, DBT *k, DBT *v) {
int here, found;
if (pma->dup_mode & TOKU_DB_DUP) {
here = __pma_left_search(pma, k, db, 0, pma->N, &found);
here = __pma_left_search(pma, k, 0, pma->N, &found);
} else
here = toku_pmainternal_find(pma, k, db);
here = toku_pmainternal_find(pma, k);
assert(0<=here ); assert(here<=toku_pma_index_limit(pma));
if (here==toku_pma_index_limit(pma)) return DB_NOTFOUND;
DBT k2;
struct kv_pair *pair;
pair = pma->pairs[here];
if (kv_pair_valid(pair) && pma->compare_fun(db, k, fill_dbt(&k2, pair->key, pair->keylen))==0) {
if (kv_pair_valid(pair) && pma->compare_fun(pma->db, k, fill_dbt(&k2, pair->key, pair->keylen))==0) {
return ybt_set_value(v, pair->key + pair->keylen, pair->vallen, &pma->sval);
} else {
return DB_NOTFOUND;
......@@ -935,29 +938,29 @@ int toku_pma_free (PMA *pmap) {
/* Copies keylen and datalen */
/* returns an error if the key is already present. */
int toku_pma_insert (PMA pma, DBT *k, DBT *v, DB* db, TOKUTXN txn, DISKOFF diskoff, u_int32_t rand4fingerprint, u_int32_t *fingerprint) {
int toku_pma_insert (PMA pma, DBT *k, DBT *v, TOKUTXN txn, DISKOFF diskoff, u_int32_t rand4fingerprint, u_int32_t *fingerprint) {
int found, idx;
if (pma->dup_mode & TOKU_DB_DUPSORT) {
idx = __pma_dup_search(pma, k, v, db, 0, pma->N, &found);
idx = __pma_dup_search(pma, k, v, 0, pma->N, &found);
if (found)
idx += 1;
} else if (pma->dup_mode & TOKU_DB_DUP) {
idx = __pma_right_search(pma, k, db, 0, pma->N, &found);
idx = __pma_right_search(pma, k, 0, pma->N, &found);
if (found)
idx += 1;
} else {
idx = toku_pmainternal_find(pma, k, db);
idx = toku_pmainternal_find(pma, k);
if (idx < toku_pma_index_limit(pma) && pma->pairs[idx]) {
DBT k2;
struct kv_pair *kv = kv_pair_ptr(pma->pairs[idx]);
if (0==pma->compare_fun(db, k, fill_dbt(&k2, kv->key, kv->keylen))) {
if (0==pma->compare_fun(pma->db, k, fill_dbt(&k2, kv->key, kv->keylen))) {
if (kv_pair_deleted(pma->pairs[idx])) {
pma_mfree_kv_pair(pma, pma->pairs[idx]);
pma->pairs[idx] = pma_malloc_kv_pair(pma, k->data, k->size, v->data, v->size);
assert(pma->pairs[idx]);
*fingerprint += rand4fingerprint*toku_calccrc32_kvpair(k->data, k->size, v->data, v->size);
int r = tokulogger_log_phys_add_or_delete_in_leaf(db, txn, diskoff, 0, pma->pairs[idx]);
int r = tokulogger_log_phys_add_or_delete_in_leaf(pma->db, txn, diskoff, 0, pma->pairs[idx]);
return r;
} else
return BRT_ALREADY_THERE; /* It is already here. Return an error. */
......@@ -973,11 +976,16 @@ int toku_pma_insert (PMA pma, DBT *k, DBT *v, DB* db, TOKUTXN txn, DISKOFF disko
assert(pma->pairs[idx]);
pma->n_pairs_present++;
*fingerprint += rand4fingerprint*toku_calccrc32_kvpair(k->data, k->size, v->data, v->size);
return tokulogger_log_phys_add_or_delete_in_leaf(db, txn, diskoff, 1, pma->pairs[idx]);
{
const struct kv_pair *pair = pma->pairs[idx];
const BYTESTRING key = { pair->keylen, (char*)kv_pair_key_const(pair) };
const BYTESTRING data = { pair->vallen, (char*)kv_pair_val_const(pair) };
return toku_log_insertinleaf (txn, toku_txn_get_txnid(txn), pma->filenum, diskoff, idx, key, data);
}
}
/* find the next matching key in the pma starting from index here */
static int pma_next_key(PMA pma, DBT *k, DB *db, int here, int n, int *found) {
static int pma_next_key(PMA pma, DBT *k, int here, int n, int *found) {
assert(0 <= here);
*found = 0;
while (here < n && !kv_pair_inuse(pma->pairs[here]))
......@@ -985,16 +993,16 @@ static int pma_next_key(PMA pma, DBT *k, DB *db, int here, int n, int *found) {
if (here < n) {
struct kv_pair *kv = kv_pair_ptr(pma->pairs[here]);
DBT k2;
if (0 == pma->compare_fun(db, k, fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv))))
if (0 == pma->compare_fun(pma->db, k, fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv))))
*found = 1;
}
return here;
}
static int pma_delete_dup (PMA pma, DBT *k, DB *db, u_int32_t rand4sem, u_int32_t *fingerprint, u_int32_t *deleted_size) {
static int pma_delete_dup (PMA pma, DBT *k, u_int32_t rand4sem, u_int32_t *fingerprint, u_int32_t *deleted_size) {
/* find the left most matching key in the pma */
int found, lefthere;
lefthere = __pma_left_search(pma, k, db, 0, pma->N, &found);
lefthere = __pma_left_search(pma, k, 0, pma->N, &found);
int rightfound = found, righthere = lefthere;
while (rightfound) {
struct kv_pair *kv = pma->pairs[righthere];
......@@ -1010,7 +1018,7 @@ static int pma_delete_dup (PMA pma, DBT *k, DB *db, u_int32_t rand4sem, u_int32_
}
}
/* find the next matching key in the pma */
righthere = pma_next_key(pma, k, db, righthere+1, pma->N, &rightfound);
righthere = pma_next_key(pma, k, righthere+1, pma->N, &rightfound);
}
if (found) {
/* check the density of the region centered around the deleted pairs */
......@@ -1019,8 +1027,8 @@ static int pma_delete_dup (PMA pma, DBT *k, DB *db, u_int32_t rand4sem, u_int32_
return found ? BRT_OK : DB_NOTFOUND;
}
static int pma_delete_nodup (PMA pma, DBT *k, DB *db, u_int32_t rand4sem, u_int32_t *fingerprint, u_int32_t *deleted_size) {
int idx = toku_pmainternal_find(pma, k, db);
static int pma_delete_nodup (PMA pma, DBT *k, u_int32_t rand4sem, u_int32_t *fingerprint, u_int32_t *deleted_size) {
int idx = toku_pmainternal_find(pma, k);
struct kv_pair *kv = pma->pairs[idx];
if (!kv_pair_valid(kv)) {
if (0) printf("%s:%d l=%d r=%d\n", __FILE__, __LINE__, idx, DB_NOTFOUND);
......@@ -1034,15 +1042,15 @@ static int pma_delete_nodup (PMA pma, DBT *k, DB *db, u_int32_t rand4sem, u_int3
return BRT_OK;
}
int toku_pma_delete (PMA pma, DBT *k, DB *db, u_int32_t rand4sem, u_int32_t *fingerprint, u_int32_t *deleted_size) {
int toku_pma_delete (PMA pma, DBT *k, u_int32_t rand4sem, u_int32_t *fingerprint, u_int32_t *deleted_size) {
u_int32_t my_deleted_size;
if (!deleted_size)
deleted_size = &my_deleted_size;
*deleted_size = 0;
if (pma->dup_mode & TOKU_DB_DUP)
return pma_delete_dup(pma, k, db, rand4sem, fingerprint, deleted_size);
return pma_delete_dup(pma, k, rand4sem, fingerprint, deleted_size);
else
return pma_delete_nodup(pma, k, db, rand4sem, fingerprint, deleted_size);
return pma_delete_nodup(pma, k, rand4sem, fingerprint, deleted_size);
}
void __pma_delete_resume(PMA pma, int here) {
......@@ -1130,32 +1138,32 @@ static void __pma_delete_at(PMA pma, int here) {
}
int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
int *replaced_v_size, /* If it is a replacement, set to the size of the old value, otherwise set to -1. */
DB *db, TOKUTXN txn, DISKOFF diskoff,
u_int32_t rand4fingerprint, u_int32_t *fingerprint) {
int *replaced_v_size, /* If it is a replacement, set to the size of the old value, otherwise set to -1. */
TOKUTXN txn, DISKOFF diskoff,
u_int32_t rand4fingerprint, u_int32_t *fingerprint) {
//printf("%s:%d v->size=%d\n", __FILE__, __LINE__, v->size);
int r;
int idx, found;
if (pma->dup_mode & TOKU_DB_DUPSORT) {
idx = __pma_dup_search(pma, k, v, db, 0, pma->N, &found);
idx = __pma_dup_search(pma, k, v, 0, pma->N, &found);
if (found)
idx += 1;
} else if (pma->dup_mode & TOKU_DB_DUP) {
idx = __pma_right_search(pma, k, db, 0, pma->N, &found);
idx = __pma_right_search(pma, k, 0, pma->N, &found);
if (found)
idx += 1;
} else {
idx = toku_pmainternal_find(pma, k, db);
idx = toku_pmainternal_find(pma, k);
struct kv_pair *kv;
if (idx < toku_pma_index_limit(pma) && (kv = pma->pairs[idx])) {
DBT k2;
// printf("%s:%d\n", __FILE__, __LINE__);
kv = kv_pair_ptr(kv);
if (0==pma->compare_fun(db, k, fill_dbt(&k2, kv->key, kv->keylen))) {
if (0==pma->compare_fun(pma->db, k, fill_dbt(&k2, kv->key, kv->keylen))) {
if (!kv_pair_deleted(pma->pairs[idx])) {
*replaced_v_size = kv->vallen;
*fingerprint -= rand4fingerprint*toku_calccrc32_kvpair(kv_pair_key_const(kv), kv_pair_keylen(kv), kv_pair_val_const(kv), kv_pair_vallen(kv));
r=tokulogger_log_phys_add_or_delete_in_leaf(db, txn, diskoff, 0, kv);
r=tokulogger_log_phys_add_or_delete_in_leaf(pma->db, txn, diskoff, 0, kv);
if (r!=0) return r;
}
if (v->size == (unsigned int) kv_pair_vallen(kv)) {
......@@ -1165,7 +1173,7 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
pma->pairs[idx] = pma_malloc_kv_pair(pma, k->data, k->size, v->data, v->size);
assert(pma->pairs[idx]);
}
r = tokulogger_log_phys_add_or_delete_in_leaf(db, txn, diskoff, 0, pma->pairs[idx]);
r = tokulogger_log_phys_add_or_delete_in_leaf(pma->db, txn, diskoff, 0, pma->pairs[idx]);
*fingerprint += rand4fingerprint*toku_calccrc32_kvpair(k->data, k->size, v->data, v->size);
return r;
}
......@@ -1181,7 +1189,12 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
pma->n_pairs_present++;
*replaced_v_size = -1;
//printf("%s:%d txn=%p\n", __FILE__, __LINE__, txn);
r = tokulogger_log_phys_add_or_delete_in_leaf(db, txn, diskoff, 1, pma->pairs[idx]);
{
const struct kv_pair *pair = pma->pairs[idx];
const BYTESTRING key = { pair->keylen, (char*)kv_pair_key_const(pair) };
const BYTESTRING data = { pair->vallen, (char*)kv_pair_val_const(pair) };
r = toku_log_insertinleaf (txn, toku_txn_get_txnid(txn), pma->filenum, diskoff, idx, key, data);
}
*fingerprint += rand4fingerprint*toku_calccrc32_kvpair(k->data, k->size, v->data, v->size);
return r;
}
......@@ -1298,18 +1311,18 @@ static void __pma_relocate_kvpairs(PMA pma) {
#endif
static int __pma_compare_kv(PMA pma, struct kv_pair *a, struct kv_pair *b, DB *db) {
static int __pma_compare_kv(PMA pma, struct kv_pair *a, struct kv_pair *b) {
DBT dbta, dbtb;
int cmp = pma->compare_fun(db, fill_dbt(&dbta, kv_pair_key(a), kv_pair_keylen(a)), fill_dbt(&dbtb, kv_pair_key(b), kv_pair_keylen(b)));
int cmp = pma->compare_fun(pma->db, fill_dbt(&dbta, kv_pair_key(a), kv_pair_keylen(a)), fill_dbt(&dbtb, kv_pair_key(b), kv_pair_keylen(b)));
if (cmp == 0 && (pma->dup_mode & TOKU_DB_DUPSORT)) {
cmp = pma->dup_compare_fun(db, fill_dbt(&dbta, kv_pair_val(a), kv_pair_vallen(b)), fill_dbt(&dbtb, kv_pair_val(b), kv_pair_vallen(b)));
cmp = pma->dup_compare_fun(pma->db, fill_dbt(&dbta, kv_pair_val(a), kv_pair_vallen(b)), fill_dbt(&dbtb, kv_pair_val(b), kv_pair_vallen(b)));
}
return cmp;
}
int toku_pma_split(PMA origpma, unsigned int *origpma_size, DBT *splitk, DB *db,
PMA leftpma, unsigned int *leftpma_size, u_int32_t leftrand4fp, u_int32_t *leftfingerprint,
PMA rightpma, unsigned int *rightpma_size, u_int32_t rightrand4fp, u_int32_t *rightfingerprint) {
int toku_pma_split(PMA origpma, unsigned int *origpma_size, DBT *splitk,
PMA leftpma, unsigned int *leftpma_size, u_int32_t leftrand4fp, u_int32_t *leftfingerprint,
PMA rightpma, unsigned int *rightpma_size, u_int32_t rightrand4fp, u_int32_t *rightfingerprint) {
int error;
int npairs;
struct kv_pair_tag *pairs;
......@@ -1393,7 +1406,7 @@ int toku_pma_split(PMA origpma, unsigned int *origpma_size, DBT *splitk, DB *db,
splitk->data = memdup(kv_pair_key(a), splitk->size);
}
splitk->flags = BRT_PIVOT_PRESENT_L;
if (spliti < npairs && __pma_compare_kv(origpma, a, pairs[spliti].pair, db) == 0) {
if (spliti < npairs && __pma_compare_kv(origpma, a, pairs[spliti].pair) == 0) {
splitk->flags += BRT_PIVOT_PRESENT_R;
}
}
......@@ -1493,7 +1506,7 @@ int toku_pma_bulk_insert(PMA pma, DBT *keys, DBT *vals, int n_newpairs, u_int32_
* no duplications, duplicates, sorted duplicates.
*/
void toku_pma_verify(PMA pma, DB *db) {
void toku_pma_verify(PMA pma) {
int i;
struct kv_pair *kv;
......@@ -1516,7 +1529,7 @@ void toku_pma_verify(PMA pma, DB *db) {
DBT kv_dbt, nextkv_dbt;
fill_dbt(&kv_dbt, kv_pair_key(kv), kv_pair_keylen(kv));
fill_dbt(&nextkv_dbt, kv_pair_key(nextkv), kv_pair_keylen(nextkv));
int r = pma->compare_fun(db, &kv_dbt, &nextkv_dbt);
int r = pma->compare_fun(pma->db, &kv_dbt, &nextkv_dbt);
if (pma->dup_mode == 0)
assert(r < 0);
else if (pma->dup_mode & TOKU_DB_DUP)
......@@ -1524,7 +1537,7 @@ void toku_pma_verify(PMA pma, DB *db) {
if (r == 0 && (pma->dup_mode & TOKU_DB_DUPSORT)) {
fill_dbt(&kv_dbt, kv_pair_val(kv), kv_pair_vallen(kv));
fill_dbt(&nextkv_dbt, kv_pair_val(nextkv), kv_pair_vallen(nextkv));
r = pma->dup_compare_fun(db, &kv_dbt, &nextkv_dbt);
r = pma->dup_compare_fun(pma->db, &kv_dbt, &nextkv_dbt);
assert(r <= 0);
}
kv = nextkv;
......
......@@ -19,7 +19,7 @@ typedef struct pma_cursor *PMA_CURSOR;
return a value < 0, = 0, > 0 if a < b, a == b, a > b respectively */
typedef int (*pma_compare_fun_t)(DB *, const DBT *a, const DBT *b);
int toku_pma_create(PMA *, pma_compare_fun_t compare_fun, int maxsize);
int toku_pma_create(PMA *, pma_compare_fun_t compare_fun, DB *, FILENUM filenum, int maxsize);
int toku_pma_set_compare(PMA pma, pma_compare_fun_t compare_fun);
......@@ -31,7 +31,7 @@ int toku_pma_set_dup_mode(PMA pma, int mode);
int toku_pma_set_dup_compare(PMA pma, pma_compare_fun_t dup_compare_fun);
/* verify the integrity of a pma */
void toku_pma_verify(PMA pma, DB *db);
void toku_pma_verify(PMA pma);
/* returns 0 if OK.
* You must have freed all the cursors, otherwise returns nonzero and does nothing. */
......@@ -45,21 +45,21 @@ int toku_pma_n_entries (PMA);
/* Duplicates the key and keylen. */
//enum pma_errors toku_pma_insert (PMA, bytevec key, ITEMLEN keylen, bytevec data, ITEMLEN datalen);
// The DB pointer is there so that the comparison function can be called.
enum pma_errors toku_pma_insert (PMA, DBT*, DBT*, DB*, TOKUTXN txn, DISKOFF, u_int32_t /*random for fingerprint */, u_int32_t */*fingerprint*/);
enum pma_errors toku_pma_insert (PMA, DBT*, DBT*, TOKUTXN txn, DISKOFF, u_int32_t /*random for fingerprint */, u_int32_t */*fingerprint*/);
/* This returns an error if the key is NOT present. */
int pma_replace (PMA, bytevec key, ITEMLEN keylen, bytevec data, ITEMLEN datalen);
/* This returns an error if the key is NOT present. */
int toku_pma_delete (PMA, DBT *, DB*, u_int32_t /*random for fingerprint*/, u_int32_t */*fingerprint*/, u_int32_t *deleted_size);
int toku_pma_delete (PMA, DBT *, u_int32_t /*random for fingerprint*/, u_int32_t */*fingerprint*/, u_int32_t *deleted_size);
int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
int *replaced_v_size, /* If it is a replacement, set to the size of the old value, otherwise set to -1. */
DB *db, TOKUTXN txn, DISKOFF,
TOKUTXN txn, DISKOFF,
u_int32_t /*random for fingerprint*/, u_int32_t */*fingerprint*/);
/* Exposes internals of the PMA by returning a pointer to the guts.
* Don't modify the returned data. Don't free it. */
enum pma_errors toku_pma_lookup (PMA, DBT*, DBT*, DB*);
enum pma_errors toku_pma_lookup (PMA, DBT*, DBT*);
/*
* The kv pairs in the original pma are split into 2 equal sized sets
......@@ -71,7 +71,7 @@ enum pma_errors toku_pma_lookup (PMA, DBT*, DBT*, DB*);
* leftpma - the pma assigned keys <= pivot key
* rightpma - the pma assigned keys > pivot key
*/
int toku_pma_split(PMA origpma, unsigned int *origpma_size, DBT *splitk, DB *db,
int toku_pma_split(PMA origpma, unsigned int *origpma_size, DBT *splitk,
PMA leftpma, unsigned int *leftpma_size, u_int32_t leftrand4sum, u_int32_t *leftfingerprint,
PMA rightpma, unsigned int *rightpma_size, u_int32_t rightrand4sum, u_int32_t *rightfingerprint);
......@@ -103,13 +103,13 @@ int toku_pma_cursor_set_position_prev (PMA_CURSOR c);
int toku_pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val);
/* set the cursor to the matching key and value pair */
int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val, DB *db);
int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val);
/* move the cursor to the kv pair matching the key */
int toku_pma_cursor_set_key(PMA_CURSOR c, DBT *key, DB *db);
int toku_pma_cursor_set_key(PMA_CURSOR c, DBT *key);
/* set the cursor to the smallest key in the pma >= key */
int toku_pma_cursor_set_range(PMA_CURSOR c, DBT *key, DB *db);
int toku_pma_cursor_set_range(PMA_CURSOR c, DBT *key);
/* 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);
......
......@@ -21,6 +21,8 @@ struct cf_pair {
} *cf_pairs;
int n_cf_pairs=0, max_cf_pairs=0;
DB * const null_db=0;
CACHEFILE find_cachefile (FILENUM fnum) {
int i;
for (i=0; i<n_cf_pairs; i++) {
......@@ -86,7 +88,7 @@ static void toku_recover_newbrtnode (struct logtype_newbrtnode *c) {
n->local_fingerprint = 0; // nothing there yet
n->dirty = 1;
if (c->height==0) {
r=toku_pma_create(&n->u.l.buffer, toku_default_compare_fun, c->nodesize);
r=toku_pma_create(&n->u.l.buffer, dont_call_this_compare_fun, null_db, c->filenum, c->nodesize);
assert(r==0);
n->u.l.n_bytes_in_buffer=0;
} else {
......
......@@ -91,6 +91,10 @@ NO_VGRIND = \
db_open_notexist_reopen \
db_remove_subdb \
db_subdb \
dup_delete \
dup_flags \
dup_insert \
dup_search \
rand_insert \
reverse_compare_fun \
# Comment to terminate list so the previous line can end with a slash
......
......@@ -515,7 +515,7 @@ struct __toku_dbc_internal {
};
int __toku_c_get(DBC * c, DBT * key, DBT * data, u_int32_t flag) {
int r = brt_cursor_get(c->i->c, key, data, flag, c->i->db, c->i->txn ? c->i->txn->i->tokutxn : 0);
int r = brt_cursor_get(c->i->c, key, data, flag, c->i->txn ? c->i->txn->i->tokutxn : 0);
return r;
}
......@@ -550,7 +550,7 @@ int __toku_db_cursor(DB * db, DB_TXN * txn, DBC ** c, u_int32_t flags) {
}
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, db);
int r = brt_delete(db->i->brt, key);
return r;
}
......@@ -567,7 +567,7 @@ int __toku_db_get(DB * db, DB_TXN * txn __attribute__ ((unused)), DBT * key, DBT
dbc->c_close(dbc);
}
} else
r = brt_lookup(db->i->brt, key, data, db);
r = brt_lookup(db->i->brt, key, data);
return r;
}
......@@ -689,7 +689,7 @@ int __toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *dbname,
}
int __toku_db_put(DB * db, DB_TXN * txn, DBT * key, DBT * data, u_int32_t flags) {
int r = brt_insert(db->i->brt, key, data, db, txn ? txn->i->tokutxn : 0);
int r = brt_insert(db->i->brt, key, data, txn ? txn->i->tokutxn : 0);
//printf("%s:%d %d=__toku_db_put(...)\n", __FILE__, __LINE__, r);
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