Commit f35e999b authored by Yoni Fogel's avatar Yoni Fogel

Split db_put into two functions (noassociate/regular)

addresses #116

git-svn-id: file:///svn/tokudb@931 c7de825b-a66e-492c-adef-691d508d4ae1
parent 31323157
...@@ -947,6 +947,30 @@ static int toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *db ...@@ -947,6 +947,30 @@ static int toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *db
return r; return r;
} }
static int toku_db_put_noassociate(DB * db, DB_TXN * txn, DBT * key, DBT * data, u_int32_t flags) {
int r;
unsigned int brtflags;
unsigned int nodesize;
if (flags != 0) return EINVAL;
r = toku_brt_get_flags(db->i->brt, &brtflags); assert(r == 0);
r = toku_brt_get_nodesize(db->i->brt, &nodesize); assert(r == 0);
if (brtflags & TOKU_DB_DUPSORT) {
unsigned int limit = nodesize / (2*BRT_FANOUT-1);
if (key->size + data->size >= limit)
return EINVAL;
} else {
unsigned int limit = nodesize / (3*BRT_FANOUT-1);
if (key->size >= limit || data->size >= limit)
return EINVAL;
}
r = toku_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;
}
static int do_associated_inserts (DB_TXN *txn, DBT *key, DBT *data, DB *secondary) { static int do_associated_inserts (DB_TXN *txn, DBT *key, DBT *data, DB *secondary) {
DBT idx; DBT idx;
memset(&idx, 0, sizeof(idx)); memset(&idx, 0, sizeof(idx));
...@@ -957,7 +981,7 @@ static int do_associated_inserts (DB_TXN *txn, DBT *key, DBT *data, DB *secondar ...@@ -957,7 +981,7 @@ static int do_associated_inserts (DB_TXN *txn, DBT *key, DBT *data, DB *secondar
return EINVAL; // We aren't ready for this return EINVAL; // We aren't ready for this
} }
#endif #endif
r = secondary->put(secondary, txn, &idx, key, DB_NO_ASSOCIATE); r = toku_db_put_noassociate(secondary, txn, &idx, key, 0);
if (idx.flags & DB_DBT_APPMALLOC) { if (idx.flags & DB_DBT_APPMALLOC) {
free(idx.data); free(idx.data);
} }
...@@ -967,29 +991,12 @@ static int do_associated_inserts (DB_TXN *txn, DBT *key, DBT *data, DB *secondar ...@@ -967,29 +991,12 @@ static int do_associated_inserts (DB_TXN *txn, DBT *key, DBT *data, DB *secondar
static int toku_db_put(DB * db, DB_TXN * txn, DBT * key, DBT * data, u_int32_t flags) { static int toku_db_put(DB * db, DB_TXN * txn, DBT * key, DBT * data, u_int32_t flags) {
int r; int r;
if (db->i->primary == 0 && flags != 0) return EINVAL; if (flags != 0) return EINVAL;
//Cannot put directly into a secondary. //Cannot put directly into a secondary.
if (db->i->primary != 0 && flags != DB_NO_ASSOCIATE) return EINVAL; if (db->i->primary != 0) return EINVAL;
unsigned int brtflags;
r = toku_brt_get_flags(db->i->brt, &brtflags); assert(r == 0);
unsigned int nodesize;
r = toku_brt_get_nodesize(db->i->brt, &nodesize); assert(r == 0);
if (brtflags & TOKU_DB_DUPSORT) {
unsigned int limit = nodesize / (2*BRT_FANOUT-1);
if (key->size + data->size >= limit)
return EINVAL;
} else {
unsigned int limit = nodesize / (3*BRT_FANOUT-1);
if (key->size >= limit || data->size >= limit)
return EINVAL;
}
r = toku_brt_insert(db->i->brt, key, data, txn ? txn->i->tokutxn : 0); r = toku_db_put_noassociate(db, txn, key, data, flags);
//printf("%s:%d %d=__toku_db_put(...)\n", __FILE__, __LINE__, r);
if (r!=0) return r; if (r!=0) return r;
// For each secondary add the relevant records. // For each secondary add the relevant records.
if (db->i->primary==0) { // Only do it if it is a primary. This loop would run an unknown number of times if we tried it on a secondary. if (db->i->primary==0) { // Only do it if it is a primary. This loop would run an unknown number of times if we tried it on a secondary.
struct list *h; struct list *h;
......
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