Commit 18afd505 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

make secondary work a little longer. Addresses #48.

git-svn-id: file:///svn/tokudb@863 c7de825b-a66e-492c-adef-691d508d4ae1
parent cec87512
...@@ -5,13 +5,7 @@ ...@@ -5,13 +5,7 @@
#include <db.h> #include <db.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
/*#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>*/
#include "test.h" #include "test.h"
...@@ -60,7 +54,7 @@ void second_setup() { ...@@ -60,7 +54,7 @@ void second_setup() {
/* Open/create primary */ /* Open/create primary */
r = db_create(&dbp, dbenv, 0); CKERR(r); r = db_create(&dbp, dbenv, 0); CKERR(r);
r = dbp->open(dbp, NULL, "students.db", NULL, DB_BTREE, DB_CREATE, 0600); CKERR(r); r = dbp->open(dbp, NULL, DIR "/students.db", NULL, DB_BTREE, DB_CREATE, 0600); CKERR(r);
/* /*
* Open/create secondary. Note that it supports duplicate data * Open/create secondary. Note that it supports duplicate data
...@@ -68,7 +62,7 @@ void second_setup() { ...@@ -68,7 +62,7 @@ void second_setup() {
*/ */
r = db_create(&sdbp, dbenv, 0); CKERR(r); r = db_create(&sdbp, dbenv, 0); CKERR(r);
r = sdbp->set_flags(sdbp, DB_DUP | DB_DUPSORT); CKERR(r); r = sdbp->set_flags(sdbp, DB_DUP | DB_DUPSORT); CKERR(r);
r = sdbp->open(sdbp, NULL, "lastname.db", NULL, DB_BTREE, DB_CREATE, 0600); CKERR(r); r = sdbp->open(sdbp, NULL, DIR "/lastname.db", NULL, DB_BTREE, DB_CREATE, 0600); CKERR(r);
/* Associate the secondary with the primary. */ /* Associate the secondary with the primary. */
...@@ -181,6 +175,9 @@ void verify_gone() { ...@@ -181,6 +175,9 @@ void verify_gone() {
int main() { int main() {
int r; int r;
system("rm -rf " DIR);
mkdir(DIR, 0777);
second_setup(); second_setup();
insert_test(); insert_test();
delete_from_primary(); delete_from_primary();
......
...@@ -616,39 +616,50 @@ static int toku_db_del(DB * db, DB_TXN * txn, DBT * key, u_int32_t flags) { ...@@ -616,39 +616,50 @@ static int toku_db_del(DB * db, DB_TXN * txn, DBT * key, u_int32_t flags) {
return r; return r;
} }
static int toku_db_get(DB * db, DB_TXN * txn, DBT * key, DBT * data, u_int32_t flags) {
assert(flags == 0); // Internal flag for when doing a get, don't do the work for associate.
#define DB_NO_ASSOCIATE 42
static int toku_db_get (DB * db, DB_TXN * txn, DBT * key, DBT * data, u_int32_t flags) {
int r; int r;
unsigned int brtflags; unsigned int brtflags;
DBT primary_key; assert(flags == 0 || flags==DB_NO_ASSOCIATE); // We aren't ready to handle flags such as DB_GET_BOTH or DB_READ_COMMITTED or DB_READ_UNCOMMITTED or DB_RMW
DBT *sdata; if (db->i->primary==0 || flags==DB_NO_ASSOCIATE) {
DB *primary = db->i->primary; // It's a get on a primary
int is_secondary = primary!=0;
if (is_secondary) {
memset(&primary_key, 0, sizeof(primary_key));
sdata=&primary_key;
} else {
sdata=data;
}
toku_brt_get_flags(db->i->brt, &brtflags); toku_brt_get_flags(db->i->brt, &brtflags);
if (brtflags & TOKU_DB_DUPSORT) { if (brtflags & TOKU_DB_DUPSORT) {
DBC *dbc; DBC *dbc;
r = db->cursor(db, txn, &dbc, 0); r = db->cursor(db, txn, &dbc, 0);
if (r == 0) {
r = dbc->c_get(dbc, key, sdata, DB_SET);
dbc->c_close(dbc);
}
} else
r = toku_brt_lookup(db->i->brt, key, sdata);
if (r!=0) return r; if (r!=0) return r;
if (is_secondary) { r = dbc->c_get(dbc, key, data, DB_SET);
// Time to do a get on the primary int r2 = dbc->c_close(dbc);
return primary->get(primary, txn, &primary_key, data, 0); if (r!=0) return r;
return r2;
} else
return toku_brt_lookup(db->i->brt, key, data);
} else { } else {
return r; // It's a get on a secondary.
DBT primary_key;
memset(&primary_key, 0, sizeof(primary_key));
r = toku_db_get (db, txn, key, &primary_key, DB_NO_ASSOCIATE); // Lookup the primary
if (r!=0) return r;
// If data and primary_key are both zeroed, the temporary storage used to fill in data is different in the two cases because they come from different trees.
assert(db->i->brt != db->i->primary->i->brt); // Make sure they realy are different trees.
return toku_db_get (db->i->primary, txn, &primary_key, data, 0);
} }
} }
static int toku_db_pget (DB *db, DB_TXN *txn, DBT *key, DBT *pkey, DBT *data, u_int32_t flags) {
int r;
if (!db->i->primary) return EINVAL; // pget doesn't work on a primary.
assert(flags==0); // not ready to handle all those other options
r = toku_db_get (db, txn, key, pkey, DB_NO_ASSOCIATE);
if (r!=0) return r;
assert(db!=db->i->primary);
r = toku_db_get (db->i->primary, txn, pkey, data, 0);
return r;
}
static int toku_db_key_range(DB * db, DB_TXN * txn, DBT * dbt, DB_KEY_RANGE * kr, u_int32_t flags) { static int toku_db_key_range(DB * db, DB_TXN * txn, DBT * dbt, DB_KEY_RANGE * kr, u_int32_t flags) {
db=db; txn=txn; dbt=dbt; kr=kr; flags=flags; db=db; txn=txn; dbt=dbt; kr=kr; flags=flags;
barf(); barf();
...@@ -931,6 +942,7 @@ int db_create(DB ** db, DB_ENV * env, u_int32_t flags) { ...@@ -931,6 +942,7 @@ int db_create(DB ** db, DB_ENV * env, u_int32_t flags) {
result->get = toku_db_get; result->get = toku_db_get;
result->key_range = toku_db_key_range; result->key_range = toku_db_key_range;
result->open = toku_db_open; result->open = toku_db_open;
result->pget = toku_db_pget;
result->put = toku_db_put; result->put = toku_db_put;
result->remove = toku_db_remove; result->remove = toku_db_remove;
result->rename = toku_db_rename; result->rename = toku_db_rename;
......
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