Commit a9e1d296 authored by Rich Prohaska's avatar Rich Prohaska

add Db::fd closes #231

git-svn-id: file:///svn/tokudb@1601 c7de825b-a66e-492c-adef-691d508d4ae1
parent 8bed7715
......@@ -170,7 +170,8 @@ struct __toku_db {
int (*close) (DB*, u_int32_t); /* 32-bit offset=260 size=4, 64=bit offset=424 size=8 */
int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t); /* 32-bit offset=264 size=4, 64=bit offset=432 size=8 */
int (*del) (DB *, DB_TXN *, DBT *, u_int32_t); /* 32-bit offset=268 size=4, 64=bit offset=440 size=8 */
void* __toku_dummy4[3];
void* __toku_dummy4[2];
int (*fd) (DB *, int *); /* 32-bit offset=280 size=4, 64=bit offset=464 size=8 */
int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t); /* 32-bit offset=284 size=4, 64=bit offset=472 size=8 */
int (*pget) (DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t); /* 32-bit offset=288 size=4, 64=bit offset=480 size=8 */
void* __toku_dummy5[3];
......
......@@ -179,7 +179,8 @@ struct __toku_db {
int (*close) (DB*, u_int32_t); /* 32-bit offset=272 size=4, 64=bit offset=448 size=8 */
int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t); /* 32-bit offset=276 size=4, 64=bit offset=456 size=8 */
int (*del) (DB *, DB_TXN *, DBT *, u_int32_t); /* 32-bit offset=280 size=4, 64=bit offset=464 size=8 */
void* __toku_dummy4[4];
void* __toku_dummy4[3];
int (*fd) (DB *, int *); /* 32-bit offset=296 size=4, 64=bit offset=496 size=8 */
int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t); /* 32-bit offset=300 size=4, 64=bit offset=504 size=8 */
int (*pget) (DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t); /* 32-bit offset=304 size=4, 64=bit offset=512 size=8 */
void* __toku_dummy5[7];
......
......@@ -178,7 +178,8 @@ struct __toku_db {
void* __toku_dummy4[1];
int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t); /* 32-bit offset=288 size=4, 64=bit offset=480 size=8 */
int (*del) (DB *, DB_TXN *, DBT *, u_int32_t); /* 32-bit offset=292 size=4, 64=bit offset=488 size=8 */
void* __toku_dummy5[3];
void* __toku_dummy5[2];
int (*fd) (DB *, int *); /* 32-bit offset=304 size=4, 64=bit offset=512 size=8 */
int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t); /* 32-bit offset=308 size=4, 64=bit offset=520 size=8 */
void* __toku_dummy6[8];
int (*get_flags) (DB *, u_int32_t *); /* 32-bit offset=344 size=4, 64=bit offset=592 size=8 */
......
......@@ -177,7 +177,8 @@ struct __toku_db {
void* __toku_dummy4[1];
int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t); /* 32-bit offset=300 size=4, 64=bit offset=504 size=8 */
int (*del) (DB *, DB_TXN *, DBT *, u_int32_t); /* 32-bit offset=304 size=4, 64=bit offset=512 size=8 */
void* __toku_dummy5[3];
void* __toku_dummy5[2];
int (*fd) (DB *, int *); /* 32-bit offset=316 size=4, 64=bit offset=536 size=8 */
int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t); /* 32-bit offset=320 size=4, 64=bit offset=544 size=8 */
void* __toku_dummy6[8];
int (*get_flags) (DB *, u_int32_t *); /* 32-bit offset=356 size=4, 64=bit offset=616 size=8 */
......
......@@ -181,7 +181,8 @@ struct __toku_db {
void* __toku_dummy5[1];
int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t); /* 32-bit offset=308 size=4, 64=bit offset=528 size=8 */
int (*del) (DB *, DB_TXN *, DBT *, u_int32_t); /* 32-bit offset=312 size=4, 64=bit offset=536 size=8 */
void* __toku_dummy6[4];
void* __toku_dummy6[3];
int (*fd) (DB *, int *); /* 32-bit offset=328 size=4, 64=bit offset=568 size=8 */
int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t); /* 32-bit offset=332 size=4, 64=bit offset=576 size=8 */
void* __toku_dummy7[8];
int (*get_flags) (DB *, u_int32_t *); /* 32-bit offset=368 size=4, 64=bit offset=648 size=8 */
......
......@@ -128,6 +128,7 @@ void sample_db_offsets (void) {
STRUCT_SETUP(DB, cursor, "int (*%s) (DB *, DB_TXN *, DBC **, u_int32_t)");
STRUCT_SETUP(DB, dbenv, "DB_ENV *%s");
STRUCT_SETUP(DB, del, "int (*%s) (DB *, DB_TXN *, DBT *, u_int32_t)");
STRUCT_SETUP(DB, fd, "int (*%s) (DB *, int *)");
STRUCT_SETUP(DB, get, "int (*%s) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)");
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3
STRUCT_SETUP(DB, get_flags, "int (*%s) (DB *, u_int32_t *)");
......
......@@ -50,6 +50,7 @@ struct fieldinfo db_fields32[] = {
{"int (*close) (DB*, u_int32_t)", 260, 4},
{"int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t)", 264, 4},
{"int (*del) (DB *, DB_TXN *, DBT *, u_int32_t)", 268, 4},
{"int (*fd) (DB *, int *)", 280, 4},
{"int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 284, 4},
{"int (*pget) (DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t)", 288, 4},
{"int (*key_range) (DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t)", 304, 4},
......
......@@ -52,6 +52,7 @@ struct fieldinfo db_fields32[] = {
{"int (*close) (DB*, u_int32_t)", 272, 4},
{"int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t)", 276, 4},
{"int (*del) (DB *, DB_TXN *, DBT *, u_int32_t)", 280, 4},
{"int (*fd) (DB *, int *)", 296, 4},
{"int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 300, 4},
{"int (*pget) (DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t)", 304, 4},
{"int (*get_flags) (DB *, u_int32_t *)", 336, 4},
......
......@@ -52,6 +52,7 @@ struct fieldinfo db_fields32[] = {
{"int (*close) (DB*, u_int32_t)", 280, 4},
{"int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t)", 288, 4},
{"int (*del) (DB *, DB_TXN *, DBT *, u_int32_t)", 292, 4},
{"int (*fd) (DB *, int *)", 304, 4},
{"int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 308, 4},
{"int (*get_flags) (DB *, u_int32_t *)", 344, 4},
{"int (*get_pagesize) (DB *, u_int32_t *)", 372, 4},
......
......@@ -51,6 +51,7 @@ struct fieldinfo db_fields32[] = {
{"int (*close) (DB*, u_int32_t)", 292, 4},
{"int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t)", 300, 4},
{"int (*del) (DB *, DB_TXN *, DBT *, u_int32_t)", 304, 4},
{"int (*fd) (DB *, int *)", 316, 4},
{"int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 320, 4},
{"int (*get_flags) (DB *, u_int32_t *)", 356, 4},
{"int (*get_pagesize) (DB *, u_int32_t *)", 384, 4},
......
......@@ -51,6 +51,7 @@ struct fieldinfo db_fields32[] = {
{"int (*close) (DB*, u_int32_t)", 300, 4},
{"int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t)", 308, 4},
{"int (*del) (DB *, DB_TXN *, DBT *, u_int32_t)", 312, 4},
{"int (*fd) (DB *, int *)", 328, 4},
{"int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 332, 4},
{"int (*get_flags) (DB *, u_int32_t *)", 368, 4},
{"int (*get_pagesize) (DB *, u_int32_t *)", 400, 4},
......
......@@ -50,6 +50,7 @@ struct fieldinfo db_fields64[] = {
{"int (*close) (DB*, u_int32_t)", 424, 8},
{"int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t)", 432, 8},
{"int (*del) (DB *, DB_TXN *, DBT *, u_int32_t)", 440, 8},
{"int (*fd) (DB *, int *)", 464, 8},
{"int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 472, 8},
{"int (*pget) (DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t)", 480, 8},
{"int (*key_range) (DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t)", 512, 8},
......
......@@ -52,6 +52,7 @@ struct fieldinfo db_fields64[] = {
{"int (*close) (DB*, u_int32_t)", 448, 8},
{"int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t)", 456, 8},
{"int (*del) (DB *, DB_TXN *, DBT *, u_int32_t)", 464, 8},
{"int (*fd) (DB *, int *)", 496, 8},
{"int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 504, 8},
{"int (*pget) (DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t)", 512, 8},
{"int (*get_flags) (DB *, u_int32_t *)", 576, 8},
......
......@@ -52,6 +52,7 @@ struct fieldinfo db_fields64[] = {
{"int (*close) (DB*, u_int32_t)", 464, 8},
{"int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t)", 480, 8},
{"int (*del) (DB *, DB_TXN *, DBT *, u_int32_t)", 488, 8},
{"int (*fd) (DB *, int *)", 512, 8},
{"int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 520, 8},
{"int (*get_flags) (DB *, u_int32_t *)", 592, 8},
{"int (*get_pagesize) (DB *, u_int32_t *)", 648, 8},
......
......@@ -51,6 +51,7 @@ struct fieldinfo db_fields64[] = {
{"int (*close) (DB*, u_int32_t)", 488, 8},
{"int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t)", 504, 8},
{"int (*del) (DB *, DB_TXN *, DBT *, u_int32_t)", 512, 8},
{"int (*fd) (DB *, int *)", 536, 8},
{"int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 544, 8},
{"int (*get_flags) (DB *, u_int32_t *)", 616, 8},
{"int (*get_pagesize) (DB *, u_int32_t *)", 672, 8},
......
......@@ -51,6 +51,7 @@ struct fieldinfo db_fields64[] = {
{"int (*close) (DB*, u_int32_t)", 512, 8},
{"int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t)", 528, 8},
{"int (*del) (DB *, DB_TXN *, DBT *, u_int32_t)", 536, 8},
{"int (*fd) (DB *, int *)", 568, 8},
{"int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)", 576, 8},
{"int (*get_flags) (DB *, u_int32_t *)", 648, 8},
{"int (*get_pagesize) (DB *, u_int32_t *)", 712, 8},
......
......@@ -131,6 +131,11 @@ int Db::set_dup_compare(dup_compare_fcn_type dup_compare_fcn) {
return the_Env->maybe_throw_error(ret);
}
int Db::fd(int *fdp) {
int ret = the_db->fd(the_db, fdp);
return the_Env->maybe_throw_error(ret);
}
extern "C" int toku_dup_compare_callback_c(DB *db_c, const DBT *a, const DBT *b) {
Db *db_cxx=Db::get_Db(db_c);
return db_cxx->dup_compare_callback_cxx(db_cxx, Dbt::get_const_Dbt(a), Dbt::get_const_Dbt(b));
......
......@@ -35,4 +35,5 @@ check: $(TARGETS)
$(VGRIND) ./test_db_assoc3
$(VGRIND) ./test_db_assoc3 --more
$(VGRIND) ./test_cursor_count
$(VGRIND) ./test_fd
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <db_cxx.h>
int verbose;
int test_fd(const char *dbfile) {
int r;
int fd;
Db db(0, DB_CXX_NO_EXCEPTIONS);
r = db.fd(&fd); assert(r == EINVAL);
unlink(dbfile);
if (verbose) { printf("opening %s\n", dbfile); fflush(stdout); }
r = db.open(0, dbfile, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
r = db.fd(&fd); assert(r == 0); assert(fd >= 0);
if (verbose) { printf("fd=%d\n", fd); fflush(stdout); }
if (verbose) { printf("closing\n"); fflush(stdout); }
r = db.close(0); assert(r == 0);
if (verbose) { printf("closed\n"); fflush(stdout); }
return 0;
}
int usage() {
printf("test_fd [-v] [--verbose]\n");
return 1;
}
int main(int argc, char *argv[]) {
for (int i=1; i<argc; i++) {
char *arg = argv[i];
if (0 == strcmp(arg, "-h") || 0 == strcmp(arg, "--help"))
return usage();
if (0 == strcmp(arg, "-v") || 0 == strcmp(arg, "--verbose"))
verbose += 1;
}
return test_fd("test.db");
}
......@@ -178,7 +178,8 @@ struct __toku_db {
void* __toku_dummy4[1];
int (*cursor) (DB *, DB_TXN *, DBC **, u_int32_t); /* 32-bit offset=288 size=4, 64=bit offset=480 size=8 */
int (*del) (DB *, DB_TXN *, DBT *, u_int32_t); /* 32-bit offset=292 size=4, 64=bit offset=488 size=8 */
void* __toku_dummy5[3];
void* __toku_dummy5[2];
int (*fd) (DB *, int *); /* 32-bit offset=304 size=4, 64=bit offset=512 size=8 */
int (*get) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t); /* 32-bit offset=308 size=4, 64=bit offset=520 size=8 */
void* __toku_dummy6[8];
int (*get_flags) (DB *, u_int32_t *); /* 32-bit offset=344 size=4, 64=bit offset=592 size=8 */
......
......@@ -124,6 +124,8 @@ class Db {
int associate(DbTxn *, Db *, int (*)(Db *, const Dbt *, const Dbt *, Dbt *), u_int32_t);
int fd(int *);
/* 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 *);
......
......@@ -1333,6 +1333,11 @@ int toku_brt_set_dup_compare(BRT brt, int (*dup_compare)(DB *, const DBT*, const
return 0;
}
int toku_brt_get_fd(BRT brt, int *fdp) {
*fdp = toku_cachefile_fd(brt->cf);
return 0;
}
int toku_brt_open(BRT t, const char *fname, const char *fname_in_env, const char *dbname, int is_create, int only_create, int load_flags, CACHETABLE cachetable, TOKUTXN txn) {
/* If dbname is NULL then we setup to hold a single tree. Otherwise we setup an array. */
......
......@@ -60,4 +60,6 @@ extern int toku_brt_do_push_cmd; // control whether push occurs eagerly.
int toku_brt_dbt_set_key (BRT, DBT*, bytevec val, ITEMLEN vallen);
int toku_brt_dbt_set_value (BRT, DBT*, bytevec val, ITEMLEN vallen);
int toku_brt_get_fd(BRT, int *);
#endif
......@@ -37,7 +37,7 @@ clean:
cd tests;make clean
ydb.o: ../include/db.h ../newbrt/cachetable.h ../newbrt/brt.h ../newbrt/log.c
DBBINS = ydb.o ../newbrt/brt.o ../newbrt/brt-serialize.o ../newbrt/brt-verify.o ../newbrt/cachetable.o ../newbrt/hashtable.o ../newbrt/key.o ../newbrt/memory.o ../newbrt/mempool.o ../newbrt/pma.o ../newbrt/ybt.o ../newbrt/primes.o ../newbrt/log.o ../newbrt/fingerprint.o ../newbrt/log_code.o ../newbrt/roll.o
DBBINS = ydb.o ../newbrt/brt.o ../newbrt/brt-serialize.o ../newbrt/brt-verify.o ../newbrt/cachetable.o ../newbrt/fifo.o ../newbrt/key.o ../newbrt/memory.o ../newbrt/mempool.o ../newbrt/pma.o ../newbrt/ybt.o ../newbrt/primes.o ../newbrt/log.o ../newbrt/fingerprint.o ../newbrt/log_code.o ../newbrt/roll.o
$(LIBNAME).$(LIBEXT): $(DBBINS)
cc $(CPPFLAGS) $(DBBINS) $(SHARED) -o $@ $(CFLAGS) -lz
......
......@@ -1852,6 +1852,12 @@ static int toku_db_stat(DB * db, void *v, u_int32_t flags) {
abort();
}
static int toku_db_fd(DB *db, int *fdp) {
HANDLE_PANICKED_DB(db);
if (!db_opened(db)) return EINVAL;
return toku_brt_get_fd(db->i->brt, fdp);
}
int db_create(DB ** db, DB_ENV * env, u_int32_t flags) {
int r;
......@@ -1900,6 +1906,7 @@ int db_create(DB ** db, DB_ENV * env, u_int32_t flags) {
result->set_flags = toku_db_set_flags;
result->get_flags = toku_db_get_flags;
result->stat = toku_db_stat;
result->fd = toku_db_fd;
MALLOC(result->i);
if (result->i == 0) {
toku_free(result);
......
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