Commit d074a42e authored by Rich Prohaska's avatar Rich Prohaska

cursor DB_SET op should not change the key. closes #73

git-svn-id: file:///svn/tokudb@804 c7de825b-a66e-492c-adef-691d508d4ae1
parent ca6ac478
......@@ -1569,6 +1569,7 @@ void test_brt_cursor_set(int n, int cursor_op, DB *db) {
memcpy(&vv, val.data, val.size);
assert(vv == v);
toku_free(val.data);
if (cursor_op == DB_SET) assert(key.data == &k);
}
/* try to set cursor to keys not in the tree, all should fail */
......@@ -1580,6 +1581,7 @@ void test_brt_cursor_set(int n, int cursor_op, DB *db) {
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = brt_cursor_get(cursor, &key, &val, DB_SET, null_txn);
assert(r == DB_NOTFOUND);
assert(key.data == &k);
}
r = brt_cursor_close(cursor);
......
......@@ -2848,7 +2848,7 @@ int brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags, TOKUTXN tx
assert(r == 0);
r = brtcurs_set_key(cursor, *rootp, kbt, vbt, DB_SET, txn, null_brtnode);
if (r != 0) goto died0;
r = toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt);
r = toku_pma_cursor_get_current_data(cursor->pmacurs, vbt);
if (r != 0) goto died0;
break;
case DB_GET_BOTH:
......
......@@ -748,6 +748,17 @@ int toku_pma_cursor_set_position_next (PMA_CURSOR c) {
return DB_NOTFOUND;
}
int toku_pma_cursor_get_current_data(PMA_CURSOR c, DBT *data) {
if (c->position == -1)
return DB_NOTFOUND;
PMA pma = c->pma;
struct kv_pair *pair = pma->pairs[c->position];
if (!kv_pair_valid(pair))
return BRT_KEYEMPTY;
ybt_set_value(data, kv_pair_val(pair), kv_pair_vallen(pair), &c->sval);
return 0;
}
int toku_pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val) {
if (c->position == -1)
return DB_NOTFOUND;
......@@ -755,8 +766,8 @@ int toku_pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val) {
struct kv_pair *pair = pma->pairs[c->position];
if (!kv_pair_valid(pair))
return BRT_KEYEMPTY;
ybt_set_value(key, pair->key, pair->keylen, &c->skey);
ybt_set_value(val, pair->key + pair->keylen, pair->vallen, &c->sval);
ybt_set_value(key, kv_pair_key(pair), kv_pair_keylen(pair), &c->skey);
ybt_set_value(val, kv_pair_val(pair), kv_pair_vallen(pair), &c->sval);
return 0;
}
......
......@@ -101,6 +101,9 @@ int toku_pma_cursor_set_position_prev (PMA_CURSOR c);
/* get the key and data under the cursor */
int toku_pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val);
int toku_pma_cursor_get_current_key(PMA_CURSOR c, DBT *key);
int toku_pma_cursor_get_current_data(PMA_CURSOR c, DBT *val);
/* set the cursor to the matching key and value pair */
int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val);
......
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