Commit 3e73ec58 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Get db-benchmark-test to run with transactions

git-svn-id: file:///svn/tokudb@376 c7de825b-a66e-492c-adef-691d508d4ae1
parent bb99881c
......@@ -2,7 +2,7 @@
# build with Berkeley DB 4.1: make BDB=/usr/local/BerkeleyDB.4.1
# build with TokuDB: make BDB=~/svn/tokudb
BENCHDB = bench.db
BENCHDBS = bench.bdb/ bench.tokudb
CFLAGS = -Wall -Werror -g
# CFLAGS += -pg
......@@ -16,9 +16,14 @@ CPPFLAGS =
LDFLAGS = -ldb
endif
TARGET = db-benchmark-test
TARGETS = db-benchmark-test-bdb db-benchmark-test-tokudb
$(TARGET):
default: $(TARGETS)
clean:
rm -rf $(TARGET) $(BENCHDB)
rm -rf $(TARGETS) $(BENCHDBS)
db-benchmark-test-tokudb: db-benchmark-test.c
cc -Wall -Werror -g -O2 -I../include -L../lib -ldb -Wl,-rpath,../lib $< -o $@ -DDIRSUF=tokudb
db-benchmark-test-bdb: db-benchmark-test.c
cc -Wall -Werror -g -O2 -ldb $< -o $@ -DDIRSUF=bdb
......@@ -10,14 +10,18 @@
#include <db.h>
enum { SERIAL_SPACING = 1<<6 };
enum { ITEMS_TO_INSERT_PER_ITERATION = 1<<15 };
enum { ITEMS_TO_INSERT_PER_ITERATION = 1<<20 };
enum { ITEMS_PER_TRANSACTION = 1<<14 };
//enum { ITEMS_TO_INSERT_PER_ITERATION = 1<<14 };
enum { BOUND_INCREASE_PER_ITERATION = SERIAL_SPACING*ITEMS_TO_INSERT_PER_ITERATION };
#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
char *dbdir = "./bench/";
#define STRINGIFY2(s) #s
#define STRINGIFY(s) STRINGIFY2(s)
char *dbdir = "./bench." STRINGIFY(DIRSUF) "/"; /* DIRSUF is passed in as a -D argument to the compiler. */;
char *dbfilename = "bench.db";
char *dbname;
......@@ -26,19 +30,28 @@ DB *db;
DB_TXN *tid=0;
int do_transactions = 0;
int n_insertions_since_txn_began=0;
void setup (void) {
int r;
char fullname[strlen(dbdir) + strlen("/") + strlen(dbfilename) + 1];
sprintf(fullname, "%s/%s", dbdir, dbfilename);
unlink(fullname);
{
char unlink_cmd[strlen(dbdir) + strlen("rf -rf ") + 1];
snprintf(unlink_cmd, sizeof(unlink_cmd), "rm -rf %s", dbdir);
//printf("unlink_cmd=%s\n", unlink_cmd);
system(unlink_cmd);
}
if (strcmp(dbdir, ".") != 0)
mkdir(dbdir, 0755);
r = db_env_create(&dbenv, 0);
assert(r == 0);
if (dbenv->set_lk_max) {
r = dbenv->set_lk_max(dbenv, ITEMS_PER_TRANSACTION*2);
assert(r==0);
}
if (dbenv->set_cachesize) {
r = dbenv->set_cachesize(dbenv, 0, 128*1024*1024, 1);
if (r != 0)
......@@ -64,24 +77,6 @@ void setup (void) {
r=tid->commit(tid, 0); assert(r==0);
}
if (do_transactions) {
DBT key,data;
r=dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data="hello";
key.size=6;
data.data="there";
data.size=6;
r=db->put(db, tid, &key, &data, 0);
CKERR(r);
r=tid->commit(tid, 0); assert(r==0);
}
}
void shutdown (void) {
......@@ -113,6 +108,15 @@ void insert (long long v) {
long_long_to_array(vc, v);
int r = db->put(db, tid, fill_dbt(&kt, kc, 8), fill_dbt(&vt, vc, 8), 0);
CKERR(r);
if (do_transactions) {
if (n_insertions_since_txn_began>=ITEMS_PER_TRANSACTION) {
n_insertions_since_txn_began=0;
r = tid->commit(tid, 0); assert(r==0);
r=dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0);
n_insertions_since_txn_began=0;
}
n_insertions_since_txn_began++;
}
}
void serial_insert_from (long long from) {
......
......@@ -58,8 +58,8 @@ int tokulogger_log_bytes(TOKULOGGER logger, int nbytes, void *bytes) {
printf("%s:%d creat(%s, ...)\n", __FILE__, __LINE__, fname);
logger->fd = creat(fname, O_EXCL | 0700);
if (logger->fd==-1) return errno;
}
logger->next_log_file_number++;
}
if (logger->n_in_buf + nbytes > LOGGER_BUF_SIZE) {
struct iovec v[2];
v[0].iov_base = logger->buf;
......@@ -73,7 +73,7 @@ int tokulogger_log_bytes(TOKULOGGER logger, int nbytes, void *bytes) {
if (logger->n_in_file > 100<<20) {
r = close(logger->fd);
if (r!=0) return errno;
logger->fd=0;
logger->fd=-1;
logger->n_in_file = 0;
}
} else {
......
......@@ -171,7 +171,7 @@ int __toku_db_env_set_lk_detect (DB_ENV *env, u_int32_t detect) {
}
int __toku_db_env_set_lk_max (DB_ENV *env, u_int32_t lk_max) {
barf();
return 1;
return 0;
}
void __toku_db_env_set_noticecall (DB_ENV *env, void (*noticecall)(DB_ENV *, db_notices)) {
env->i->noticecall = noticecall;
......@@ -241,7 +241,7 @@ int db_env_create (DB_ENV **envp, u_int32_t flags) {
int __toku_db_txn_commit (DB_TXN *txn, u_int32_t flags) {
notef("flags=%d\n", flags);
//notef("flags=%d\n", flags);
if (!txn) return -1;
int r = tokulogger_log_commit(txn->i->tokutxn);
if (r!=0) return r;
......@@ -259,7 +259,7 @@ static TXNID next_txn=0;
int txn_begin (DB_ENV *env, DB_TXN *stxn, DB_TXN **txn, u_int32_t flags) {
DB_TXN *result = malloc_zero(sizeof(*result));
notef("parent=%p flags=0x%x\n", stxn, flags);
//notef("parent=%p flags=0x%x\n", stxn, flags);
result->commit = __toku_db_txn_commit;
result->id = __toku_db_txn_id;
result->i = malloc(sizeof(*result->i));
......
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