Commit 70eb6eba authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

Close #2945 (get rid of {{{db->set_bt_compare}}} in favor of {{{env->set_default_bt_compare}}}).

Closes #2945.  close[t:2945]
{{{
svn merge -r 24888:24894 https://svn.tokutek.com/tokudb/toku/tokudb.2945
}}}
.


git-svn-id: file:///svn/toku/tokudb@24931 c7de825b-a66e-492c-adef-691d508d4ae1
parent 55d84fcb
......@@ -396,8 +396,7 @@ struct __toku_db {
int (*stat) (DB *, void *, u_int32_t); /* 32-bit offset=384 size=4, 64=bit offset=672 size=8 */
void* __toku_dummy9[2];
int (*verify) (DB *, const char *, const char *, FILE *, u_int32_t); /* 32-bit offset=396 size=4, 64=bit offset=696 size=8 */
int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *)); /* 32-bit offset=400 size=4, 64=bit offset=704 size=8 */
void* __toku_dummy10[15]; /* Padding at the end */
void* __toku_dummy10[16]; /* Padding at the end */
char __toku_dummy11[8]; /* Padding at the end */
};
struct __toku_db_txn_active {
......
......@@ -410,10 +410,8 @@ struct __toku_db {
int (*stat) (DB *, void *, u_int32_t); /* 32-bit offset=452 size=4, 64=bit offset=808 size=8 */
void* __toku_dummy11[3];
int (*verify) (DB *, const char *, const char *, FILE *, u_int32_t); /* 32-bit offset=468 size=4, 64=bit offset=840 size=8 */
void* __toku_dummy12[1];
int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *)); /* 32-bit offset=476 size=4, 64=bit offset=856 size=8 */
void* __toku_dummy13[23]; /* Padding at the end */
char __toku_dummy14[8]; /* Padding at the end */
void* __toku_dummy12[25]; /* Padding at the end */
char __toku_dummy13[8]; /* Padding at the end */
};
struct __toku_db_txn_active {
u_int32_t txnid; /* 32-bit offset=0 size=4, 64=bit offset=0 size=4 */
......
......@@ -403,22 +403,20 @@ struct __toku_db {
int (*put) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t); /* 32-bit offset=420 size=4, 64=bit offset=744 size=8 */
int (*remove) (DB *, const char *, const char *, u_int32_t); /* 32-bit offset=424 size=4, 64=bit offset=752 size=8 */
int (*rename) (DB *, const char *, const char *, const char *, u_int32_t); /* 32-bit offset=428 size=4, 64=bit offset=760 size=8 */
void* __toku_dummy9[2];
int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *)); /* 32-bit offset=440 size=4, 64=bit offset=784 size=8 */
void* __toku_dummy10[6];
void* __toku_dummy9[9];
void (*set_errfile) (DB *, FILE*); /* 32-bit offset=468 size=4, 64=bit offset=840 size=8 */
void* __toku_dummy11[2];
void* __toku_dummy10[2];
int (*set_flags) (DB *, u_int32_t); /* 32-bit offset=480 size=4, 64=bit offset=864 size=8 */
void* __toku_dummy12[6];
void* __toku_dummy11[6];
int (*set_pagesize) (DB *, u_int32_t); /* 32-bit offset=508 size=4, 64=bit offset=920 size=8 */
void* __toku_dummy13[6];
void* __toku_dummy12[6];
int (*stat) (DB *, void *, u_int32_t); /* 32-bit offset=536 size=4, 64=bit offset=976 size=8 */
void* __toku_dummy14[2];
void* __toku_dummy13[2];
int (*truncate) (DB *, DB_TXN *, u_int32_t *, u_int32_t); /* 32-bit offset=548 size=4, 64=bit offset=1000 size=8 */
void* __toku_dummy15[1];
void* __toku_dummy14[1];
int (*verify) (DB *, const char *, const char *, FILE *, u_int32_t); /* 32-bit offset=556 size=4, 64=bit offset=1016 size=8 */
void* __toku_dummy16[5]; /* Padding at the end */
char __toku_dummy17[16]; /* Padding at the end */
void* __toku_dummy15[5]; /* Padding at the end */
char __toku_dummy16[16]; /* Padding at the end */
};
struct __toku_db_txn_active {
u_int32_t txnid; /* 32-bit offset=0 size=4, 64=bit offset=0 size=4 */
......
......@@ -403,22 +403,20 @@ struct __toku_db {
int (*put) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t); /* 32-bit offset=432 size=4, 64=bit offset=768 size=8 */
int (*remove) (DB *, const char *, const char *, u_int32_t); /* 32-bit offset=436 size=4, 64=bit offset=776 size=8 */
int (*rename) (DB *, const char *, const char *, const char *, u_int32_t); /* 32-bit offset=440 size=4, 64=bit offset=784 size=8 */
void* __toku_dummy9[2];
int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *)); /* 32-bit offset=452 size=4, 64=bit offset=808 size=8 */
void* __toku_dummy10[6];
void* __toku_dummy9[9];
void (*set_errfile) (DB *, FILE*); /* 32-bit offset=480 size=4, 64=bit offset=864 size=8 */
void* __toku_dummy11[2];
void* __toku_dummy10[2];
int (*set_flags) (DB *, u_int32_t); /* 32-bit offset=492 size=4, 64=bit offset=888 size=8 */
void* __toku_dummy12[6];
void* __toku_dummy11[6];
int (*set_pagesize) (DB *, u_int32_t); /* 32-bit offset=520 size=4, 64=bit offset=944 size=8 */
void* __toku_dummy13[6];
void* __toku_dummy12[6];
int (*stat) (DB *, void *, u_int32_t); /* 32-bit offset=548 size=4, 64=bit offset=1000 size=8 */
void* __toku_dummy14[2];
void* __toku_dummy13[2];
int (*truncate) (DB *, DB_TXN *, u_int32_t *, u_int32_t); /* 32-bit offset=560 size=4, 64=bit offset=1024 size=8 */
void* __toku_dummy15[1];
void* __toku_dummy14[1];
int (*verify) (DB *, const char *, const char *, FILE *, u_int32_t); /* 32-bit offset=568 size=4, 64=bit offset=1040 size=8 */
void* __toku_dummy16[5]; /* Padding at the end */
char __toku_dummy17[16]; /* Padding at the end */
void* __toku_dummy15[5]; /* Padding at the end */
char __toku_dummy16[16]; /* Padding at the end */
};
struct __toku_db_txn_active {
u_int32_t txnid; /* 32-bit offset=0 size=4, 64=bit offset=0 size=4 */
......
......@@ -406,22 +406,20 @@ struct __toku_db {
int (*put) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t); /* 32-bit offset=452 size=4, 64=bit offset=816 size=8 */
int (*remove) (DB *, const char *, const char *, u_int32_t); /* 32-bit offset=456 size=4, 64=bit offset=824 size=8 */
int (*rename) (DB *, const char *, const char *, const char *, u_int32_t); /* 32-bit offset=460 size=4, 64=bit offset=832 size=8 */
void* __toku_dummy10[2];
int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *)); /* 32-bit offset=472 size=4, 64=bit offset=856 size=8 */
void* __toku_dummy11[6];
void* __toku_dummy10[9];
void (*set_errfile) (DB *, FILE*); /* 32-bit offset=500 size=4, 64=bit offset=912 size=8 */
void* __toku_dummy12[2];
void* __toku_dummy11[2];
int (*set_flags) (DB *, u_int32_t); /* 32-bit offset=512 size=4, 64=bit offset=936 size=8 */
void* __toku_dummy13[7];
void* __toku_dummy12[7];
int (*set_pagesize) (DB *, u_int32_t); /* 32-bit offset=544 size=4, 64=bit offset=1000 size=8 */
void* __toku_dummy14[7];
void* __toku_dummy13[7];
int (*stat) (DB *, void *, u_int32_t); /* 32-bit offset=576 size=4, 64=bit offset=1064 size=8 */
void* __toku_dummy15[2];
void* __toku_dummy14[2];
int (*truncate) (DB *, DB_TXN *, u_int32_t *, u_int32_t); /* 32-bit offset=588 size=4, 64=bit offset=1088 size=8 */
void* __toku_dummy16[1];
void* __toku_dummy15[1];
int (*verify) (DB *, const char *, const char *, FILE *, u_int32_t); /* 32-bit offset=596 size=4, 64=bit offset=1104 size=8 */
void* __toku_dummy17[5]; /* Padding at the end */
char __toku_dummy18[16]; /* Padding at the end */
void* __toku_dummy16[5]; /* Padding at the end */
char __toku_dummy17[16]; /* Padding at the end */
};
struct __toku_db_txn_active {
u_int32_t txnid; /* 32-bit offset=0 size=4, 64=bit offset=0 size=4 */
......
......@@ -8,8 +8,8 @@
#include <db.h>
#include <stdio.h>
#include <stdlib.h>
#include <toku_assert.h>
// Don't include toku_assert.h. Just use assert.h
#include <assert.h>
#define DECL_LIMIT 100
#define FIELD_LIMIT 100
......@@ -143,7 +143,6 @@ void sample_db_offsets (void) {
STRUCT_SETUP(DB, put, "int (*%s) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)");
STRUCT_SETUP(DB, remove, "int (*%s) (DB *, const char *, const char *, u_int32_t)");
STRUCT_SETUP(DB, rename, "int (*%s) (DB *, const char *, const char *, const char *, u_int32_t)");
STRUCT_SETUP(DB, set_bt_compare, "int (*%s) (DB *, int (*)(DB *, const DBT *, const DBT *))");
STRUCT_SETUP(DB, set_errfile, "void (*%s) (DB *, FILE*)");
STRUCT_SETUP(DB, set_flags, "int (*%s) (DB *, u_int32_t)");
STRUCT_SETUP(DB, set_pagesize, "int (*%s) (DB *, u_int32_t)");
......
......@@ -65,7 +65,6 @@ struct fieldinfo db_fields32[] = {
{"int (*set_pagesize) (DB *, u_int32_t)", 376, 4},
{"int (*stat) (DB *, void *, u_int32_t)", 384, 4},
{"int (*verify) (DB *, const char *, const char *, FILE *, u_int32_t)", 396, 4},
{"int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *))", 400, 4},
{0, 472, 472} /* size of whole struct */
};
struct fieldinfo db_txn_active_fields32[] = {
......
......@@ -71,7 +71,6 @@ struct fieldinfo db_fields32[] = {
{"int (*set_pagesize) (DB *, u_int32_t)", 444, 4},
{"int (*stat) (DB *, void *, u_int32_t)", 452, 4},
{"int (*verify) (DB *, const char *, const char *, FILE *, u_int32_t)", 468, 4},
{"int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *))", 476, 4},
{0, 580, 580} /* size of whole struct */
};
struct fieldinfo db_txn_active_fields32[] = {
......
......@@ -65,7 +65,6 @@ struct fieldinfo db_fields32[] = {
{"int (*put) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 420, 4},
{"int (*remove) (DB *, const char *, const char *, u_int32_t)", 424, 4},
{"int (*rename) (DB *, const char *, const char *, const char *, u_int32_t)", 428, 4},
{"int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *))", 440, 4},
{"void (*set_errfile) (DB *, FILE*)", 468, 4},
{"int (*set_flags) (DB *, u_int32_t)", 480, 4},
{"int (*set_pagesize) (DB *, u_int32_t)", 508, 4},
......
......@@ -64,7 +64,6 @@ struct fieldinfo db_fields32[] = {
{"int (*put) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 432, 4},
{"int (*remove) (DB *, const char *, const char *, u_int32_t)", 436, 4},
{"int (*rename) (DB *, const char *, const char *, const char *, u_int32_t)", 440, 4},
{"int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *))", 452, 4},
{"void (*set_errfile) (DB *, FILE*)", 480, 4},
{"int (*set_flags) (DB *, u_int32_t)", 492, 4},
{"int (*set_pagesize) (DB *, u_int32_t)", 520, 4},
......
......@@ -64,7 +64,6 @@ struct fieldinfo db_fields32[] = {
{"int (*put) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 452, 4},
{"int (*remove) (DB *, const char *, const char *, u_int32_t)", 456, 4},
{"int (*rename) (DB *, const char *, const char *, const char *, u_int32_t)", 460, 4},
{"int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *))", 472, 4},
{"void (*set_errfile) (DB *, FILE*)", 500, 4},
{"int (*set_flags) (DB *, u_int32_t)", 512, 4},
{"int (*set_pagesize) (DB *, u_int32_t)", 544, 4},
......
......@@ -65,7 +65,6 @@ struct fieldinfo db_fields64[] = {
{"int (*set_pagesize) (DB *, u_int32_t)", 656, 8},
{"int (*stat) (DB *, void *, u_int32_t)", 672, 8},
{"int (*verify) (DB *, const char *, const char *, FILE *, u_int32_t)", 696, 8},
{"int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *))", 704, 8},
{0, 840, 840} /* size of whole struct */
};
struct fieldinfo db_txn_active_fields64[] = {
......
......@@ -71,7 +71,6 @@ struct fieldinfo db_fields64[] = {
{"int (*set_pagesize) (DB *, u_int32_t)", 792, 8},
{"int (*stat) (DB *, void *, u_int32_t)", 808, 8},
{"int (*verify) (DB *, const char *, const char *, FILE *, u_int32_t)", 840, 8},
{"int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *))", 856, 8},
{0, 1056, 1056} /* size of whole struct */
};
struct fieldinfo db_txn_active_fields64[] = {
......
......@@ -65,7 +65,6 @@ struct fieldinfo db_fields64[] = {
{"int (*put) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 744, 8},
{"int (*remove) (DB *, const char *, const char *, u_int32_t)", 752, 8},
{"int (*rename) (DB *, const char *, const char *, const char *, u_int32_t)", 760, 8},
{"int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *))", 784, 8},
{"void (*set_errfile) (DB *, FILE*)", 840, 8},
{"int (*set_flags) (DB *, u_int32_t)", 864, 8},
{"int (*set_pagesize) (DB *, u_int32_t)", 920, 8},
......
......@@ -64,7 +64,6 @@ struct fieldinfo db_fields64[] = {
{"int (*put) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 768, 8},
{"int (*remove) (DB *, const char *, const char *, u_int32_t)", 776, 8},
{"int (*rename) (DB *, const char *, const char *, const char *, u_int32_t)", 784, 8},
{"int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *))", 808, 8},
{"void (*set_errfile) (DB *, FILE*)", 864, 8},
{"int (*set_flags) (DB *, u_int32_t)", 888, 8},
{"int (*set_pagesize) (DB *, u_int32_t)", 944, 8},
......
......@@ -64,7 +64,6 @@ struct fieldinfo db_fields64[] = {
{"int (*put) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 816, 8},
{"int (*remove) (DB *, const char *, const char *, u_int32_t)", 824, 8},
{"int (*rename) (DB *, const char *, const char *, const char *, u_int32_t)", 832, 8},
{"int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *))", 856, 8},
{"void (*set_errfile) (DB *, FILE*)", 912, 8},
{"int (*set_flags) (DB *, u_int32_t)", 936, 8},
{"int (*set_pagesize) (DB *, u_int32_t)", 1000, 8},
......
......@@ -64,7 +64,6 @@ struct fieldinfo db_fields64[] = {
{"int (*put) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 856, 8},
{"int (*remove) (DB *, const char *, const char *, u_int32_t)", 864, 8},
{"int (*rename) (DB *, const char *, const char *, const char *, u_int32_t)", 872, 8},
{"int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *))", 896, 8},
{"void (*set_errfile) (DB *, FILE*)", 952, 8},
{"int (*set_flags) (DB *, u_int32_t)", 976, 8},
{"int (*set_pagesize) (DB *, u_int32_t)", 1040, 8},
......
......@@ -366,7 +366,6 @@ struct __toku_db {
int (*put) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t);
int (*remove) (DB *, const char *, const char *, u_int32_t);
int (*rename) (DB *, const char *, const char *, const char *, u_int32_t);
int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *));
void (*set_errfile) (DB *, FILE*);
int (*set_flags) (DB *, u_int32_t);
int (*set_pagesize) (DB *, u_int32_t);
......
......@@ -111,9 +111,14 @@ int Db::remove(const char *file, const char *database, u_int32_t flags) {
return the_Env->maybe_throw_error(ret);
}
#if 0
extern "C" int toku_bt_compare_callback_c(DB *db_c, const DBT *a, const DBT *b) {
Db *db_cxx=Db::get_Db(db_c);
return db_cxx->bt_compare_callback_cxx(db_cxx, Dbt::get_const_Dbt(a), Dbt::get_const_Dbt(b));
return db_cxx->do_bt_compare_callback_cxx(db_cxx, Dbt::get_const_Dbt(a), Dbt::get_const_Dbt(b));
}
int Db::do_bt_compare_callback_cxx(Db *db, const Dbt *a, const Dbt *b) {
return the_Env->bt_compare_callback_cxx(db, a, b);
}
int Db::set_bt_compare(int (*bt_compare_callback)(Db *, const Dbt *, const Dbt *)) {
......@@ -126,6 +131,7 @@ int Db::set_bt_compare(bt_compare_fcn_type bt_compare_fcn) {
int ret = the_db->set_bt_compare(the_db, bt_compare_fcn);
return the_Env->maybe_throw_error(ret);
}
#endif
int Db::fd(int *fdp) {
int ret = the_db->fd(the_db, fdp);
......
......@@ -79,6 +79,11 @@ int DbEnv::txn_begin(DbTxn *parenttxn, DbTxn **txnp, u_int32_t flags) {
return maybe_throw_error(ret);
}
int DbEnv::set_default_bt_compare(bt_compare_fcn_type bt_compare_fcn) {
int ret = the_env->set_default_bt_compare(the_env, bt_compare_fcn);
return maybe_throw_error(ret);
}
int DbEnv::set_data_dir(const char *dir) {
int ret = the_env->set_data_dir(the_env, dir);
return maybe_throw_error(ret);
......
......@@ -30,12 +30,12 @@ int cmp(DB *db, const DBT *dbt1, const DBT *dbt2) {
void test_db(void) {
DbEnv env(DB_CXX_NO_EXCEPTIONS);
{ int r = env.set_redzone(0); assert(r==0); }
{ int r = env.set_redzone(0); assert(r==0); }
{ int r = env.set_default_bt_compare(cmp); assert(r == 0); }
int r = env.open("test1.dir", DB_CREATE|DB_PRIVATE, 0666);
assert(r==0);
Db db(&env, 0);
r = db.set_bt_compare(cmp); assert(r == 0);
r = db.remove("DoesNotExist.db", NULL, 0); assert(r == ENOENT);
// The db is closed
r = env.close(0); assert(r== 0);
......
......@@ -17,13 +17,13 @@ void test_db(void) {
system("rm -rf " DIR);
mkdir(DIR, 0777);
DbEnv env(0);
{ int r = env.set_redzone(0); assert(r==0); }
{ int r = env.set_redzone(0); assert(r==0); }
{ int r = env.set_default_bt_compare(cmp); assert(r == 0); }
env.open(DIR, DB_CREATE|DB_PRIVATE, 0666);
Db db(&env, 0);
int r;
r = db.set_bt_compare(cmp); assert(r == 0);
try {
r = db.remove("DoesNotExist.db", NULL, 0);
abort(); // must not make it here.
......
......@@ -30,8 +30,8 @@ int keycompare (const void *key1, unsigned int key1len, const void *key2, unsign
}
}
int reverse_compare(Db *db __attribute__((__unused__)), const Dbt *a, const Dbt*b) {
return -keycompare(a->get_data(), a->get_size(), b->get_data(), b->get_size());
extern "C" int reverse_compare(DB *db __attribute__((__unused__)), const DBT *a, const DBT*b) {
return -keycompare(a->data, a->size, b->data, b->size);
}
void expect(Dbc *cursor, int k, int v) {
......@@ -69,13 +69,13 @@ void test_reverse_compare(int n) {
/* create the dup database file */
DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.set_redzone(0); assert(r==0);
r = env.set_default_bt_compare(reverse_compare);
assert(r == 0);
r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
db = new Db(&env, DB_CXX_NO_EXCEPTIONS);
assert(db);
r = db->set_pagesize(4096);
assert(r == 0);
r = db->set_bt_compare(reverse_compare);
assert(r == 0);
r = db->open(null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666);
assert(r == 0);
......@@ -99,8 +99,6 @@ void test_reverse_compare(int n) {
assert(db);
r = db->set_pagesize(4096);
assert(r == 0);
r = db->set_bt_compare(reverse_compare);
assert(r == 0);
r = db->open(null_txn, fname, "main", DB_BTREE, 0, 0666);
assert(r == 0);
......
......@@ -168,6 +168,11 @@ static int mysql_key_compare(DB *mydb __attribute__((unused)),
static void scanscan_setup (void) {
int r;
r = db_env_create(&env, 0); assert(r==0);
#ifdef TOKUDB
if (do_mysql) {
r = env->set_default_bt_compare(env, mysql_key_compare); assert(r == 0);
}
#endif
r = env->set_cachesize(env, 0, cachesize, 1); assert(r==0);
if (log_dir) {
r = env->set_lg_dir(env, log_dir); assert(r==0);
......@@ -178,9 +183,11 @@ static void scanscan_setup (void) {
if (verbose)
printf("env open %f seconds\n", tend-tstart);
r = db_create(&db, env, 0); assert(r==0);
#ifndef TOKUDB
if (do_mysql) {
r = db->set_bt_compare(db, mysql_key_compare); assert(r == 0);
}
#endif
if (do_txns) {
r = env->txn_begin(env, 0, &tid, 0); assert(r==0);
}
......
......@@ -366,7 +366,6 @@ struct __toku_db {
int (*put) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t);
int (*remove) (DB *, const char *, const char *, u_int32_t);
int (*rename) (DB *, const char *, const char *, const char *, u_int32_t);
int (*set_bt_compare) (DB *, int (*)(DB *, const DBT *, const DBT *));
void (*set_errfile) (DB *, FILE*);
int (*set_flags) (DB *, u_int32_t);
int (*set_pagesize) (DB *, u_int32_t);
......
......@@ -119,8 +119,10 @@ class Db {
int remove(const char *file, const char *database, u_int32_t flags);
#if 0
int set_bt_compare(bt_compare_fcn_type bt_compare_fcn);
int set_bt_compare(int (*)(Db *, const Dbt *, const Dbt *));
#endif
int set_dup_compare(dup_compare_fcn_type dup_compare_fcn);
int set_dup_compare(int (*)(Db *, const Dbt *, const Dbt *));
......@@ -134,9 +136,11 @@ class Db {
/* the cxx callbacks must be public so they can be called by the c callback. But it's really private. */
int (*associate_callback_cxx)(Db *, const Dbt *, const Dbt *, Dbt*);
int (*bt_compare_callback_cxx)(Db *, const Dbt *, const Dbt *);
int (*dup_compare_callback_cxx)(Db *, const Dbt *, const Dbt *);
//int (do_bt_compare_callback_cxx)(Db *, const Dbt *, const Dbt *);
private:
DB *the_db;
DbEnv *the_Env;
......@@ -172,6 +176,10 @@ class DbEnv {
void set_error_stream(std::ostream *);
int get_flags(u_int32_t *flagsp);
int set_default_bt_compare(bt_compare_fcn_type bt_compare_fcn);
// Don't support this one for now. It's a little tricky.
// int set_default_bt_compare(int (*)(Db *, const Dbt *, const Dbt *));
// locking
#if DB_VERSION_MAJOR<4 || (DB_VERSION_MAJOR==4 && DB_VERSION_MINOR<=4)
// set_lk_max is only defined for versions up to 4.4
......@@ -185,6 +193,8 @@ class DbEnv {
void (*errcall)(const DbEnv *, const char *, const char *);
std::ostream *_error_stream;
//int (*bt_compare_callback_cxx)(Db *, const Dbt *, const Dbt *);
private:
DB_ENV *the_env;
......
......@@ -1401,7 +1401,7 @@ brt_leaf_delete_leafentry (BRTNODE node, u_int32_t idx, LEAFENTRY le)
}
static int
brt_leaf_apply_cmd_once (BRTNODE node, BRT_MSG cmd,
brt_leaf_apply_cmd_once (BRTNODE node, const BRT_MSG cmd,
u_int32_t idx, LEAFENTRY le, TOKULOGGER logger)
// Effect: Apply cmd to leafentry
// idx is the location where it goes
......@@ -2362,7 +2362,7 @@ flush_this_child (BRT t, BRTNODE node, int childnum, enum reactivity *child_re,
//TODO: Factor out (into a function) conversion of fifo_entry to message
BRT_MSG_S brtcmd = { (enum brt_msg_type)type, xids, .u.id= {toku_fill_dbt(&hk, key, keylen),
toku_fill_dbt(&hv, val, vallen)} };
toku_fill_dbt(&hv, val, vallen)} };
int n_bytes_removed = (hk.size + hv.size + KEY_VALUE_OVERHEAD + BRT_CMD_OVERHEAD + xids_get_serialize_size(xids));
u_int32_t old_from_fingerprint = node->local_fingerprint;
......@@ -3610,7 +3610,7 @@ toku_brt_get_dictionary_id(BRT brt) {
}
int toku_brt_set_flags(BRT brt, unsigned int flags) {
lazy_assert(flags==(flags&TOKU_DB_KEYCMP_BUILTIN)); // make sure there are no extranious flags
lazy_assert(flags==(flags&TOKU_DB_KEYCMP_BUILTIN)); // make sure there are no extraneous flags
brt->did_set_flags = TRUE;
brt->flags = flags;
return 0;
......
......@@ -814,7 +814,7 @@ static void test_new_brt_cursor_create_close (void) {
r = toku_close_brt(brt, 0); assert(r == 0);
}
static void test_new_brt_cursor_first(int n, int dup_mode) {
static void test_new_brt_cursor_first(int n) {
if (verbose) printf("test_brt_cursor_first:%d\n", n);
BRT t=0;
......@@ -825,7 +825,6 @@ static void test_new_brt_cursor_first(int n, int dup_mode) {
r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
unlink(fname);
r = toku_brt_create(&t); assert(r == 0);
r = toku_brt_set_flags(t, dup_mode); assert(r == 0);
r = toku_brt_set_nodesize(t, 4096); assert(r == 0);
r = toku_brt_open(t, fname, 1, 1, ct, null_txn, 0); assert(r==0);
......@@ -867,7 +866,7 @@ static void test_new_brt_cursor_first(int n, int dup_mode) {
r = toku_cachetable_close(&ct);assert(r==0);
}
static void test_new_brt_cursor_last(int n, int dup_mode) {
static void test_new_brt_cursor_last(int n) {
if (verbose) printf("test_brt_cursor_last:%d\n", n);
BRT t=0;
......@@ -878,7 +877,6 @@ static void test_new_brt_cursor_last(int n, int dup_mode) {
r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
unlink(fname);
r = toku_brt_create(&t); assert(r == 0);
r = toku_brt_set_flags(t, dup_mode); assert(r == 0);
r = toku_brt_set_nodesize(t, 4096); assert(r == 0);
r = toku_brt_open(t, fname, 1, 1, ct, null_txn, 0); assert(r==0);
......@@ -921,7 +919,7 @@ static void test_new_brt_cursor_last(int n, int dup_mode) {
r = toku_cachetable_close(&ct);assert(r==0);
}
static void test_new_brt_cursor_next(int n, int dup_mode) {
static void test_new_brt_cursor_next(int n) {
if (verbose) printf("test_brt_cursor_next:%d\n", n);
BRT t=0;
......@@ -932,7 +930,6 @@ static void test_new_brt_cursor_next(int n, int dup_mode) {
r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
unlink(fname);
r = toku_brt_create(&t); assert(r == 0);
r = toku_brt_set_flags(t, dup_mode); assert(r == 0);
r = toku_brt_set_nodesize(t, 4096); assert(r == 0);
r = toku_brt_open(t, fname, 1, 1, ct, null_txn, 0); assert(r==0);
......@@ -965,7 +962,7 @@ static void test_new_brt_cursor_next(int n, int dup_mode) {
r = toku_cachetable_close(&ct);assert(r==0);
}
static void test_new_brt_cursor_prev(int n, int dup_mode) {
static void test_new_brt_cursor_prev(int n) {
if (verbose) printf("test_brt_cursor_prev:%d\n", n);
BRT t=0;
......@@ -976,7 +973,6 @@ static void test_new_brt_cursor_prev(int n, int dup_mode) {
r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
unlink(fname);
r = toku_brt_create(&t); assert(r == 0);
r = toku_brt_set_flags(t, dup_mode); assert(r == 0);
r = toku_brt_set_nodesize(t, 4096); assert(r == 0);
r = toku_brt_open(t, fname, 1, 1, ct, null_txn, 0); assert(r==0);
......@@ -1009,7 +1005,7 @@ static void test_new_brt_cursor_prev(int n, int dup_mode) {
r = toku_cachetable_close(&ct);assert(r==0);
}
static void test_new_brt_cursor_current(int n, int dup_mode) {
static void test_new_brt_cursor_current(int n) {
if (verbose) printf("test_brt_cursor_current:%d\n", n);
BRT t=0;
......@@ -1020,7 +1016,6 @@ static void test_new_brt_cursor_current(int n, int dup_mode) {
r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
unlink(fname);
r = toku_brt_create(&t); assert(r == 0);
r = toku_brt_set_flags(t, dup_mode); assert(r == 0);
r = toku_brt_set_nodesize(t, 4096); assert(r == 0);
r = toku_brt_open(t, fname, 1, 1, ct, null_txn, 0); assert(r==0);
......@@ -1092,8 +1087,8 @@ static void test_new_brt_cursor_current(int n, int dup_mode) {
r = toku_cachetable_close(&ct);assert(r==0);
}
static void test_new_brt_cursor_set_range(int n, int dup_mode) {
if (verbose) printf("test_brt_cursor_set_range:%d %d\n", n, dup_mode);
static void test_new_brt_cursor_set_range(int n) {
if (verbose) printf("test_brt_cursor_set_range:%d\n", n);
int r;
CACHETABLE ct;
......@@ -1103,7 +1098,6 @@ static void test_new_brt_cursor_set_range(int n, int dup_mode) {
r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
unlink(fname);
r = toku_brt_create(&brt); assert(r == 0);
r = toku_brt_set_flags(brt, dup_mode); assert(r == 0);
r = toku_brt_set_nodesize(brt, 4096); assert(r == 0);
r = toku_brt_open(brt, fname, 1, 1, ct, null_txn, 0); assert(r==0);
......@@ -1210,17 +1204,16 @@ static void test_new_brt_cursor_set(int n, int cursor_op, DB *db) {
r = toku_cachetable_close(&ct); assert(r==0);
}
static void test_new_brt_cursors(int dup_mode) {
assert(dup_mode==0);
test_new_brt_cursor_create_close();
test_new_brt_cursor_first(8, dup_mode);
test_new_brt_cursor_last(8, dup_mode);
test_new_brt_cursor_last(512, dup_mode);
test_new_brt_cursor_next(8, dup_mode);
test_new_brt_cursor_prev(8, dup_mode);
test_new_brt_cursor_current(8, dup_mode);
test_new_brt_cursor_next(512, dup_mode);
test_new_brt_cursor_set_range(512, dup_mode);
static void test_new_brt_cursors(void) {
test_new_brt_cursor_create_close();
test_new_brt_cursor_first(8);
test_new_brt_cursor_last(8);
test_new_brt_cursor_last(512);
test_new_brt_cursor_next(8);
test_new_brt_cursor_prev(8);
test_new_brt_cursor_current(8);
test_new_brt_cursor_next(512);
test_new_brt_cursor_set_range(512);
test_new_brt_cursor_set(512, DB_SET, 0);
}
......@@ -1230,7 +1223,7 @@ static void brt_blackbox_test (void) {
test_wrongendian_compare(1, 2);
test_wrongendian_compare(1, 257);
test_wrongendian_compare(1, 1000);
test_new_brt_cursors(0);
test_new_brt_cursors();
test_read_what_was_written(); if (verbose) printf("did read_what_was_written\n");
test_cursor_next();
......
......@@ -174,7 +174,7 @@ int toku_loader_create_loader(DB_ENV *env,
{
brt_compare_func compare_functions[N];
for (int i=0; i<N; i++) {
compare_functions[i] = dbs[i]->i->key_compare_was_set ? toku_brt_get_bt_compare(dbs[i]->i->brt) : env->i->bt_compare;
compare_functions[i] = env->i->bt_compare;
}
// time to open the big kahuna
......
......@@ -20,6 +20,7 @@ setup (void) {
r=db_env_create(&env, 0); CKERR(r);
#ifdef TOKUDB
r=env->set_redzone(env, 0); CKERR(r);
r=env->set_default_bt_compare(env, int_dbt_cmp); CKERR(r);
#endif
env->set_errfile(env, stderr);
#ifdef USE_BDB
......@@ -30,7 +31,9 @@ setup (void) {
r=db_create(&db, env, 0); CKERR(r);
r=env->txn_begin(env, 0, &txn, 0); assert(r==0);
#ifdef USE_BDB
r=db->set_bt_compare(db, int_dbt_cmp); CKERR(r);
#endif
r=db->open(db, txn, "foo.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r=txn->commit(txn, 0); assert(r==0);
}
......
......@@ -51,6 +51,9 @@ setup_db (u_int32_t dup_mode) {
toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
r = db_env_create(&env, 0); CKERR(r);
#ifdef TOKUDB
r = env->set_default_bt_compare(env, int_dbt_cmp); CKERR(r);
#endif
r = env->open(env, ENVDIR, DB_INIT_MPOOL | DB_INIT_LOG | DB_INIT_LOCK | DB_INIT_TXN | DB_PRIVATE | DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
......@@ -59,7 +62,9 @@ setup_db (u_int32_t dup_mode) {
r = env->txn_begin(env, 0, &txn, 0); CKERR(r);
r = db_create(&db, env, 0); CKERR(r);
#ifndef TOKUDB
r=db->set_bt_compare(db, int_dbt_cmp); CKERR(r);
#endif
r = db->set_flags(db, dup_mode); assert(r == 0); CKERR(r);
r = db->open(db, txn, "test.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
......
......@@ -78,8 +78,6 @@ open_db(int descriptor, int which) {
CKERR(r);
dbs[which] = db;
r = db->set_bt_compare(db, verify_int_cmp);
CKERR(r);
assert(abort_type >=0 && abort_type <= 2);
if (abort_type==2 && !txn) {
r = env->txn_begin(env, null_txn, &txn, 0);
......@@ -162,6 +160,7 @@ close_db(int which) {
static void
setup_data(void) {
int r = db_env_create(&env, 0); CKERR(r);
r = env->set_default_bt_compare(env, verify_int_cmp); CKERR(r);
const int envflags = DB_CREATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOCK |DB_THREAD |DB_PRIVATE;
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
int i;
......
......@@ -162,6 +162,10 @@ setup_dbs (void) {
/* Open/create primary */
r = db_env_create(&dbenv, 0);
CKERR(r);
#ifdef TOKUDB
r = dbenv->set_default_bt_compare(dbenv, int_dbt_cmp);
CKERR(r);
#endif
u_int32_t env_txn_flags = DB_INIT_TXN | DB_INIT_LOCK;
u_int32_t env_open_flags = DB_CREATE | DB_PRIVATE | DB_INIT_MPOOL;
r = dbenv->open(dbenv, ENVDIR, env_open_flags | env_txn_flags, 0600);
......@@ -169,8 +173,10 @@ setup_dbs (void) {
r = db_create(&db, dbenv, 0);
CKERR(r);
#ifndef TOKUDB
r = db->set_bt_compare( db, int_dbt_cmp);
CKERR(r);
#endif
char a;
for (a = 'a'; a <= 'z'; a++) init_txn(a);
......
......@@ -92,6 +92,10 @@ setup_dbs (void) {
/* Open/create primary */
r = db_env_create(&dbenv, 0);
CKERR(r);
#ifdef TOKUDB
r = dbenv->set_default_bt_compare(dbenv, int_dbt_cmp);
CKERR(r);
#endif
u_int32_t env_txn_flags = DB_INIT_TXN | DB_INIT_LOCK;
u_int32_t env_open_flags = DB_CREATE | DB_PRIVATE | DB_INIT_MPOOL;
r = dbenv->open(dbenv, ENVDIR, env_open_flags | env_txn_flags, 0600);
......@@ -99,8 +103,10 @@ setup_dbs (void) {
r = db_create(&db, dbenv, 0);
CKERR(r);
#ifndef TOKUDB
r = db->set_bt_compare( db, int_dbt_cmp);
CKERR(r);
#endif
char a;
for (a = 'a'; a <= 'z'; a++) init_txn(a, 0);
......
......@@ -69,6 +69,10 @@ test_reverse_compare (int n) {
/* create the dup database file */
DB_ENV *env;
r = db_env_create(&env, 0); assert(r == 0);
#ifdef TOKUDB
r = env->set_default_bt_compare(env, reverse_compare);
CKERR(r);
#endif
r = env->open(env, ENVDIR, DB_CREATE+DB_PRIVATE+DB_INIT_MPOOL, 0); assert(r == 0);
DB *db;
......@@ -76,8 +80,10 @@ test_reverse_compare (int n) {
CKERR(r);
r = db->set_pagesize(db, 4096);
CKERR(r);
#ifndef TOKUDB
r = db->set_bt_compare(db, reverse_compare);
CKERR(r);
#endif
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666);
CKERR(r);
......@@ -100,8 +106,10 @@ test_reverse_compare (int n) {
CKERR(r);
r = db->set_pagesize(db, 4096);
CKERR(r);
#ifndef TOKUDB
r = db->set_bt_compare(db, reverse_compare);
CKERR(r);
#endif
r = db->open(db, null_txn, fname, "main", DB_BTREE, 0, 0666);
CKERR(r);
......
......@@ -39,6 +39,9 @@ setup_db (void) {
toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
r = db_env_create(&env, 0); CKERR(r);
#ifdef TOKUDB
r = env->set_default_bt_compare(env, int_dbt_cmp); CKERR(r);
#endif
r = env->open(env, ENVDIR, DB_INIT_MPOOL | DB_INIT_LOG | DB_INIT_LOCK | DB_INIT_TXN | DB_PRIVATE | DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
......@@ -47,7 +50,9 @@ setup_db (void) {
r = env->txn_begin(env, 0, &txn, 0); CKERR(r);
r = db_create(&db, env, 0); CKERR(r);
#ifndef TOKUDB
r = db->set_bt_compare(db, int_dbt_cmp); CKERR(r);
#endif
r = db->open(db, txn, "test.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
}
......
......@@ -27,7 +27,7 @@ struct __toku_db_internal {
DICTIONARY_ID dict_id; // unique identifier used by locktree logic
struct __toku_lock_tree* lt;
struct simple_dbt skey, sval; // static key and value
BOOL key_compare_was_set; // true if a comparison function was provided before call to db->open() (if false, use environment's comparison function)
BOOL key_compare_was_set; // true if a comparison function was provided before call to db->open() (if false, use environment's comparison function).
char *dname; // dname is constant for this handle (handle must be closed before file is renamed)
BOOL is_zombie; // True if DB->close has been called on this DB
struct toku_list dbs_that_must_close_before_abort;
......
......@@ -385,7 +385,6 @@ static int needs_recovery (DB_ENV *env) {
}
static int toku_db_create(DB ** db, DB_ENV * env, u_int32_t flags);
static int toku_db_set_bt_compare(DB * db, int (*bt_compare) (DB *, const DBT *, const DBT *));
static int toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *dbname, DBTYPE dbtype, u_int32_t flags, int mode);
static int toku_env_txn_checkpoint(DB_ENV * env, u_int32_t kbyte, u_int32_t min, u_int32_t flags);
static int toku_db_close(DB * db, u_int32_t flags);
......@@ -4312,25 +4311,6 @@ toku_db_rename(DB * db, const char *fname, const char *dbname, const char *newna
return r;
}
// set key comparison function to function provided by user (pre-empting environment key comparison function)
static int
toku_db_set_bt_compare(DB * db, int (*bt_compare) (DB *, const DBT *, const DBT *)) {
HANDLE_PANICKED_DB(db);
int r;
if (db_opened(db))
r = toku_ydb_do_error(db->dbenv, EINVAL, "Comparison functions cannot be set after DB open.\n");
else if (!bt_compare)
r = toku_ydb_do_error(db->dbenv, EINVAL, "Comparison functions cannot be NULL.\n");
else if (db->i->key_compare_was_set)
r = toku_ydb_do_error(db->dbenv, EINVAL, "Key comparison function already set.\n");
else {
r = toku_brt_set_bt_compare(db->i->brt, bt_compare);
if (!r)
db->i->key_compare_was_set = TRUE;
}
return r;
}
static int toku_db_set_descriptor(DB *db, u_int32_t version, const DBT* descriptor) {
HANDLE_PANICKED_DB(db);
int r;
......@@ -4673,10 +4653,6 @@ static int locked_db_rename(DB * db, const char *namea, const char *nameb, const
return r;
}
static int locked_db_set_bt_compare(DB * db, int (*bt_compare) (DB *, const DBT *, const DBT *)) {
toku_ydb_lock(); int r = toku_db_set_bt_compare(db, bt_compare); toku_ydb_unlock(); return r;
}
static int locked_db_set_descriptor(DB *db, u_int32_t version, const DBT* descriptor) {
toku_ydb_lock();
int r = toku_db_set_descriptor(db, version, descriptor);
......@@ -4813,7 +4789,6 @@ static int toku_db_create(DB ** db, DB_ENV * env, u_int32_t flags) {
SDB(put);
SDB(remove);
SDB(rename);
SDB(set_bt_compare);
SDB(set_descriptor);
SDB(set_errfile);
SDB(set_pagesize);
......
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