diff --git a/buildheader/db.h_4_4 b/buildheader/db.h_4_4 index fc1c862022a..5e3bc8f1fcd 100644 --- a/buildheader/db.h_4_4 +++ b/buildheader/db.h_4_4 @@ -232,8 +232,9 @@ struct __toku_db_txn_stat { char __toku_dummy4[8]; /* Padding at the end */ }; struct __toku_dbc { + DB *dbp; /* 32-bit offset=0 size=4, 64=bit offset=0 size=8 */ struct __toku_dbc_internal *i; - void* __toku_dummy0[20]; + void* __toku_dummy0[19]; char __toku_dummy1[104]; int (*c_close) (DBC *); /* 32-bit offset=188 size=4, 64=bit offset=272 size=8 */ void* __toku_dummy2[1]; diff --git a/cxx/dbc.cpp b/cxx/dbc.cpp index 10ae3684350..b2bff97b949 100644 --- a/cxx/dbc.cpp +++ b/cxx/dbc.cpp @@ -3,11 +3,13 @@ int Dbc::close (void) { DBC *dbc = this; int ret = dbc->c_close(dbc); - return ret; + DbEnv *env = (DbEnv*)dbc->dbp->api_internal; + return env->maybe_throw_error(ret); } int Dbc::get(Dbt* key, Dbt *data, u_int32_t flags) { DBC *dbc = this; int ret = dbc->c_get(dbc, key, data, flags); - return ret; + DbEnv *env = (DbEnv*)dbc->dbp->api_internal; + return env->maybe_throw_error(ret); } diff --git a/cxx/tests/Makefile b/cxx/tests/Makefile index 0a49f872889..e577838b86a 100644 --- a/cxx/tests/Makefile +++ b/cxx/tests/Makefile @@ -13,3 +13,7 @@ $(DBCXX): clean: rm -rf $(TARGETS) + +check: $(TARGETS) + ./test1 + ./test1e diff --git a/include/db.h b/include/db.h index fc1c862022a..5e3bc8f1fcd 100644 --- a/include/db.h +++ b/include/db.h @@ -232,8 +232,9 @@ struct __toku_db_txn_stat { char __toku_dummy4[8]; /* Padding at the end */ }; struct __toku_dbc { + DB *dbp; /* 32-bit offset=0 size=4, 64=bit offset=0 size=8 */ struct __toku_dbc_internal *i; - void* __toku_dummy0[20]; + void* __toku_dummy0[19]; char __toku_dummy1[104]; int (*c_close) (DBC *); /* 32-bit offset=188 size=4, 64=bit offset=272 size=8 */ void* __toku_dummy2[1]; diff --git a/include/db_cxx.h b/include/db_cxx.h index f3428cfb9a5..67846513608 100644 --- a/include/db_cxx.h +++ b/include/db_cxx.h @@ -116,6 +116,7 @@ class Db { class DbEnv { friend class Db; + friend class Dbc; public: DbEnv(u_int32_t flags); @@ -167,5 +168,4 @@ class Dbc : protected DBC public: int close(void); int get(Dbt*, Dbt *, u_int32_t); - }; diff --git a/src/ydb.c b/src/ydb.c index c2f641ec67d..8644549e71b 100644 --- a/src/ydb.c +++ b/src/ydb.c @@ -690,7 +690,6 @@ static int toku_db_close(DB * db, u_int32_t flags) { struct __toku_dbc_internal { BRT_CURSOR c; - DB *db; DB_TXN *txn; }; @@ -770,7 +769,7 @@ static int toku_c_pget(DBC * c, DBT *key, DBT *pkey, DBT *data, u_int32_t flag) int r; int r2; int r3; - DB *db = c->i->db; + DB *db = c->dbp; DB *pdb = db->i->primary; @@ -851,7 +850,7 @@ delete_silently_and_retry: } static int toku_c_get(DBC * c, DBT * key, DBT * data, u_int32_t flag) { - DB *db = c->i->db; + DB *db = c->dbp; int r; if (db->i->primary==0) r = toku_c_get_noassociate(c, key, data, flag); @@ -954,7 +953,7 @@ cleanup: static int toku_c_del(DBC * c, u_int32_t flags) { int r; - DB* db = c->i->db; + DB* db = c->dbp; //It is a primary with secondaries, or is a secondary. if (db->i->primary != 0 || !list_empty(&db->i->associated)) { @@ -995,7 +994,7 @@ static int toku_c_del(DBC * c, u_int32_t flags) { } static int toku_c_put(DBC *dbc, DBT *key, DBT *data, u_int32_t flags) { - DB* db = dbc->i->db; + DB* db = dbc->dbp; unsigned int brtflags; int r; DBT* put_key = key; @@ -1073,7 +1072,7 @@ static int toku_db_cursor(DB * db, DB_TXN * txn, DBC ** c, u_int32_t flags) { result->c_del = toku_c_del; MALLOC(result->i); assert(result->i); - result->i->db = db; + result->dbp = db; result->i->txn = txn; int r = toku_brt_cursor(db->i->brt, &result->i->c); assert(r == 0); @@ -1234,7 +1233,7 @@ static char *construct_full_name(const char *dir, const char *fname) { } } -int find_db_file(DB_ENV* dbenv, const char *fname, char** full_name_out) { +static int find_db_file(DB_ENV* dbenv, const char *fname, char** full_name_out) { u_int32_t i; int r; struct stat statbuf;