Commit f28b2fed authored by Rich Prohaska's avatar Rich Prohaska

there was a path through the pma_insert_or_replace function that did not set...

there was a path through the pma_insert_or_replace function that did not set the replace_v_size parameter.  this occurred when inserting a key that had been deleted with a cursor reference.  closes #191



git-svn-id: file:///svn/tokudb@1148 c7de825b-a66e-492c-adef-691d508d4ae1
parent 57a54715
......@@ -1293,7 +1293,7 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
if (found) idx += 1;
#else
if (found) {
kv = pma->pairs[idx]; goto replaceit;
kv = kv_pair_ptr(pma->pairs[idx]); goto replaceit;
}
#endif
} else if (pma->dup_mode & TOKU_DB_DUP) {
......@@ -1307,7 +1307,10 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
kv = kv_pair_ptr(kv);
if (0==pma->compare_fun(pma->db, k, toku_fill_dbt(&k2, kv->key, kv->keylen))) {
replaceit:
if (!kv_pair_deleted(pma->pairs[idx])) {
if (kv_pair_deleted(pma->pairs[idx])) {
*replaced_v_size = -1;
pma->pairs[idx] = kv;
} else {
*replaced_v_size = kv->vallen;
*fingerprint -= rand4fingerprint*toku_calccrc32_kvpair(kv_pair_key_const(kv), kv_pair_keylen(kv), kv_pair_val_const(kv), kv_pair_vallen(kv));
r=toku_logger_log_phys_add_or_delete_in_leaf(pma->db, txn, diskoff, 0, kv);
......
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <db.h>
#include "test.h"
void test_insert_delete_insert(int dup_mode) {
if (verbose) printf("test_insert_delete_insert:%d\n", dup_mode);
DB_ENV * const null_env = 0;
DB *db;
DB_TXN * const null_txn = 0;
const char * const fname = DIR "/" "test.cursor.insert.delete.insert.brt";
int r;
unlink(fname);
/* create the dup database file */
r = db_create(&db, null_env, 0); assert(r == 0);
r = db->set_flags(db, dup_mode); assert(r == 0);
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666); assert(r == 0);
DBC *cursor;
r = db->cursor(db, null_txn, &cursor, 0); assert(r == 0);
int k = htonl(1), v = 2;
DBT key, val;
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
r = cursor->c_get(cursor, dbt_init(&key, &k, sizeof k), dbt_init_malloc(&val), DB_SET);
assert(r == 0);
free(val.data);
r = cursor->c_del(cursor, 0);
assert(r == 0);
r = cursor->c_get(cursor, dbt_init_malloc(&key), dbt_init_malloc(&val), DB_CURRENT);
assert(r == DB_KEYEMPTY);
if (key.data) free(key.data);
if (val.data) free(val.data);
r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0);
r = cursor->c_get(cursor, dbt_init_malloc(&key), dbt_init_malloc(&val), DB_CURRENT);
assert(r == 0);
if (key.data) free(key.data);
if (val.data) free(val.data);
r = cursor->c_close(cursor); assert(r == 0);
r = db->close(db, 0); assert(r == 0);
}
int main(int argc, const char *argv[]) {
parse_args(argc, argv);
system("rm -rf " DIR);
mkdir(DIR, 0777);
test_insert_delete_insert(0);
test_insert_delete_insert(DB_DUP + DB_DUPSORT);
return 0;
}
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