row-store cursor code, but completely broken column-store cursors (I haven't done any work on them yet). I'm about to try and re-work the general-purpose walk code, and I want to have a solid reference point to revert to. Here's the laundry list: Re-write the row-store cursor-next/cursor-prev functions to interact cleanly with the other cursor functions, specifically after any cursor operation returns successfully, a subsequent cursor-next/prev call is supported. The fundamental trick here is choosing the fields that a cursor-search call sets, and then filling in the rest of the fields a traversal requires as soon as cursor-next/prev is called. The state of a cursor is set in the WT_CURSOR_BTREE->iter_state field. There's a new "walk" function that fills in the walk stack from the root to a specified page. As part of this, the SESSION.srch structure will go away, replaced by the WT_CURSOR_BTREE structure. Implement cursor semantics for row-store: update fails if the key doesn't exist, otherwise overwrites the value; insert fails if the key exists, otherwise inserts a new record, unless the configuration boolean "overwrite" is set, in which case insert inserts a new record if the record doesn't exist, and overwrites any existing record; remove fails if the key doesn't exist, otherwise removes the record. Fail in all cases if the application hasn't yet set a cursor key. Flush memory after reading the page's write-generation value to ensure that we do the read before reading anything from the page. This is necessary but not sufficient: the page's write-generation value could still be cache, and that would be bad. We need to either do an additional memory flush before the read, in order to flush our registers, or mark the write-generation field volatile. Cursors now hold hazard references across calls (the page cannot be discarded if a cursor references it). This is necessary for the future change where cursor will return pointers to in-memory page data. The __wt_walk_first/__wt_walk_last functions no longer support starting at a random page, no current callers of those functions used that feature. Write versions of the serial insert/update functions that don't take SESSION.srch pointers, instead, they pass the specific fields they need, in some cases taken from the WT_CURSOR_BTREE structure. Write a version of the return-value function to use information from the WT_CURSOR_BTREE structure instead of information from the SESSION.srch structure. Delete the WT_CURSOR structure WT_CURSTD_POSITIONED flag (never used), add the WT_CURSTD_OVERWRITE flag to support the cursor->insert boolean "overwrite". Delete the WT_TOOSMALL error, no longer used by compression. Add support to the format test program to test prev/next cursor movements after operations. Configure the format test program to configure the boolean "overwrite" value on its cursors, that matches the old BDB DB.put semantics the test program wants. Change the format test program to close its cursor before calling WT_SESSION.sync, now that cursors hold hazard references across calls, WT_SESSION.sync will hang. Add statistics to track read-next/read-prev calls, separate from read (search-near) calls. --HG-- extra : rebase_source : a7b386152cef2a2744df26121b06536e7066fc95
184 lines
3.6 KiB
C
184 lines
3.6 KiB
C
/*-
|
|
* See the file LICENSE for redistribution information.
|
|
*
|
|
* Copyright (c) 2008-2011 WiredTiger, Inc.
|
|
* All rights reserved.
|
|
*/
|
|
|
|
#define BDB 1 /* Berkeley DB header files */
|
|
#include "format.h"
|
|
|
|
void
|
|
bdb_startup(void)
|
|
{
|
|
DB *db;
|
|
DBC *dbc;
|
|
DB_ENV *dbenv;
|
|
|
|
assert(db_env_create(&dbenv, 0) == 0);
|
|
dbenv->set_errpfx(dbenv, "bdb");
|
|
dbenv->set_errfile(dbenv, stderr);
|
|
assert(dbenv->mutex_set_max(dbenv, 10000) == 0);
|
|
assert(dbenv->set_cachesize(dbenv, 0, 50 * 1024 * 1024, 1) == 0);
|
|
assert(dbenv->open(dbenv, NULL,
|
|
DB_CREATE |
|
|
(g.c_delete_pct == 0 && g.c_insert_pct == 0 && g.c_write_pct == 0 ?
|
|
0 : DB_INIT_LOCK) |
|
|
DB_INIT_MPOOL | DB_PRIVATE, 0) == 0);
|
|
assert(db_create(&db, dbenv, 0) == 0);
|
|
|
|
assert(db->open(db, NULL, "__bdb", NULL, DB_BTREE, DB_CREATE, 0) == 0);
|
|
g.bdb = db;
|
|
assert(db->cursor(db, NULL, &dbc, 0) == 0);
|
|
g.dbc = dbc;
|
|
}
|
|
|
|
void
|
|
bdb_teardown(void)
|
|
{
|
|
DB *db;
|
|
DBC *dbc;
|
|
DB_ENV *dbenv;
|
|
|
|
dbc = g.dbc;
|
|
db = g.bdb;
|
|
dbenv = db->dbenv;
|
|
assert(dbc->close(dbc) == 0);
|
|
assert(db->close(db, 0) == 0);
|
|
assert(dbenv->close(dbenv, 0) == 0);
|
|
}
|
|
|
|
void
|
|
bdb_insert(
|
|
const void *key_data, uint32_t key_size,
|
|
const void *value_data, uint32_t value_size)
|
|
{
|
|
static DBT key, value;
|
|
DBC *dbc;
|
|
|
|
key.data = (void *)key_data;
|
|
key.size = key_size;
|
|
value.data = (void *)value_data;
|
|
value.size = value_size;
|
|
|
|
dbc = g.dbc;
|
|
|
|
assert(dbc->put(dbc, &key, &value, DB_KEYFIRST) == 0);
|
|
}
|
|
|
|
int
|
|
bdb_np(int next,
|
|
void *keyp, uint32_t *keysizep,
|
|
void *valuep, uint32_t *valuesizep, int *notfoundp)
|
|
{
|
|
static DBT key, value;
|
|
DB *db = g.bdb;
|
|
DBC *dbc = g.dbc;
|
|
int ret;
|
|
|
|
*notfoundp = 0;
|
|
|
|
if ((ret =
|
|
dbc->get(dbc, &key, &value, next ? DB_NEXT : DB_PREV)) != 0) {
|
|
if (ret == DB_NOTFOUND) {
|
|
*notfoundp = 1;
|
|
return (0);
|
|
}
|
|
db->err(db, ret,
|
|
"dbc->get: %s: {%.*s}",
|
|
next ? "DB_NEXT" : "DB_PREV",
|
|
(int)key.size, (char *)key.data);
|
|
return (1);
|
|
}
|
|
*(void **)keyp = key.data;
|
|
*keysizep = key.size;
|
|
*(void **)valuep = value.data;
|
|
*valuesizep = value.size;
|
|
return (0);
|
|
}
|
|
|
|
int
|
|
bdb_read(uint64_t keyno, void *valuep, uint32_t *valuesizep, int *notfoundp)
|
|
{
|
|
static DBT key, value;
|
|
DB *db = g.bdb;
|
|
DBC *dbc = g.dbc;
|
|
int ret;
|
|
|
|
*notfoundp = 0;
|
|
|
|
key_gen(&key.data, &key.size, keyno, 0);
|
|
|
|
if ((ret = dbc->get(dbc, &key, &value, DB_SET)) != 0) {
|
|
if (ret == DB_NOTFOUND) {
|
|
*notfoundp = 1;
|
|
return (0);
|
|
}
|
|
db->err(db, ret,
|
|
"dbc->get: DB_SET: {%.*s}",
|
|
(int)key.size, (char *)key.data);
|
|
return (1);
|
|
}
|
|
*(void **)valuep = value.data;
|
|
*valuesizep = value.size;
|
|
return (0);
|
|
}
|
|
|
|
int
|
|
bdb_put(const void *arg_key, uint32_t arg_key_size,
|
|
const void *arg_value, uint32_t arg_value_size, int *notfoundp)
|
|
{
|
|
static DBT key, value;
|
|
DB *db = g.bdb;
|
|
DBC *dbc = g.dbc;
|
|
int ret;
|
|
|
|
*notfoundp = 0;
|
|
|
|
key.data = (void *)arg_key;
|
|
key.size = arg_key_size;
|
|
value.data = (void *)arg_value;
|
|
value.size = arg_value_size;
|
|
|
|
if ((ret = dbc->put(dbc, &key, &value, DB_KEYFIRST)) != 0) {
|
|
if (ret == DB_NOTFOUND) {
|
|
*notfoundp = 1;
|
|
return (0);
|
|
}
|
|
db->err(db, ret, "dbc->put: DB_KEYFIRST: {%.*s}{%.*s}",
|
|
(int)key.size, (char *)key.data,
|
|
(int)value.size, (char *)value.data);
|
|
return (1);
|
|
}
|
|
return (0);
|
|
}
|
|
|
|
int
|
|
bdb_del(uint64_t keyno, int *notfoundp)
|
|
{
|
|
static DBT value;
|
|
static DBT key;
|
|
DB *db = g.bdb;
|
|
DBC *dbc = g.dbc;
|
|
int ret;
|
|
|
|
*notfoundp = 0;
|
|
|
|
key_gen(&key.data, &key.size, keyno, 0);
|
|
|
|
if ((ret = bdb_read(keyno, &value.data, &value.size, notfoundp)) != 0)
|
|
return (1);
|
|
if (*notfoundp)
|
|
return (0);
|
|
if ((ret = dbc->del(dbc, 0)) != 0) {
|
|
if (ret == DB_NOTFOUND) {
|
|
*notfoundp = 1;
|
|
return (0);
|
|
}
|
|
db->err(db, ret,
|
|
"dbc->del: {%.*s}", (int)key.size, (char *)key.data);
|
|
return (1);
|
|
}
|
|
return (0);
|
|
}
|