Commit 30c35032 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Make it work with replace-or-insert

git-svn-id: file:///svn/tokudb@114 c7de825b-a66e-492c-adef-691d508d4ae1
parent b5d05c3f
...@@ -798,23 +798,24 @@ static int brtnode_maybe_push_down(BRT t, BRTNODE node, int *did_split, BRTNODE ...@@ -798,23 +798,24 @@ static int brtnode_maybe_push_down(BRT t, BRTNODE node, int *did_split, BRTNODE
return 0; return 0;
} }
//#define INSERT_ALL_AT_ONCE #define INSERT_ALL_AT_ONCE
static int brt_leaf_insert (BRT t, BRTNODE node, DBT *k, DBT *v, static int brt_leaf_insert (BRT t, BRTNODE node, DBT *k, DBT *v,
int *did_split, BRTNODE *nodea, BRTNODE *nodeb, DBT *splitk, int *did_split, BRTNODE *nodea, BRTNODE *nodeb, DBT *splitk,
int debug, int debug,
DB *db) { DB *db) {
DBT v2;
#ifdef INSERT_ALL_AT_ONCE #ifdef INSERT_ALL_AT_ONCE
int replaced_v_size; int replaced_v_size;
enum pma_errors pma_status = pma_insert_or_replace(node->u.l.buffer, k, init_dbt(&v2), db, &replaced_v_size); enum pma_errors pma_status = pma_insert_or_replace(node->u.l.buffer, k, v, db, &replaced_v_size);
assert(pma_status==BRT_OK); assert(pma_status==BRT_OK);
//printf("replaced_v_size=%d\n", replaced_v_size);
if (replaced_v_size>=0) { if (replaced_v_size>=0) {
node->u.l.n_bytes_in_buffer += v->size - replaced_v_size; node->u.l.n_bytes_in_buffer += v->size - replaced_v_size;
} else { } else {
node->u.l.n_bytes_in_buffer += k->size + v->size + KEY_VALUE_OVERHEAD; node->u.l.n_bytes_in_buffer += k->size + v->size + KEY_VALUE_OVERHEAD;
} }
#else #else
DBT v2;
enum pma_errors pma_status = pma_lookup(node->u.l.buffer, k, init_dbt(&v2), db); enum pma_errors pma_status = pma_lookup(node->u.l.buffer, k, init_dbt(&v2), db);
if (pma_status==BRT_OK) { if (pma_status==BRT_OK) {
pma_status = pma_delete(node->u.l.buffer, k, db); pma_status = pma_delete(node->u.l.buffer, k, db);
......
...@@ -578,6 +578,7 @@ int pma_delete (PMA pma, DBT *k, DB *db) { ...@@ -578,6 +578,7 @@ int pma_delete (PMA pma, DBT *k, DB *db) {
int pma_insert_or_replace (PMA pma, DBT *k, DBT *v, DB *db, int pma_insert_or_replace (PMA pma, DBT *k, DBT *v, DB *db,
int *replaced_v_size /* If it is a replacement, set to the size of the old value, otherwise set to -1. */ int *replaced_v_size /* If it is a replacement, set to the size of the old value, otherwise set to -1. */
) { ) {
//printf("%s:%d v->size=%d\n", __FILE__, __LINE__, v->size);
int idx = pmainternal_find(pma, k, db); int idx = pmainternal_find(pma, k, db);
struct kv_pair *pair; struct kv_pair *pair;
if (idx < pma_index_limit(pma) && (pair=pma->pairs[idx])) { if (idx < pma_index_limit(pma) && (pair=pma->pairs[idx])) {
...@@ -592,6 +593,7 @@ int pma_insert_or_replace (PMA pma, DBT *k, DBT *v, DB *db, ...@@ -592,6 +593,7 @@ int pma_insert_or_replace (PMA pma, DBT *k, DBT *v, DB *db,
idx = pmainternal_make_space_at (pma, idx); /* returns the new idx. */ idx = pmainternal_make_space_at (pma, idx); /* returns the new idx. */
} }
assert(!pma->pairs[idx]); assert(!pma->pairs[idx]);
//printf("%s:%d v->size=%d\n", __FILE__, __LINE__, v->size);
pma->pairs[idx] = kv_pair_malloc(k->data, k->size, v->data, v->size); pma->pairs[idx] = kv_pair_malloc(k->data, k->size, v->data, v->size);
assert(pma->pairs[idx]); assert(pma->pairs[idx]);
pma->n_pairs_present++; pma->n_pairs_present++;
......
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