Commit 574a4d03 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Tests for #455. Fixes #455.

git-svn-id: file:///svn/tokudb@2472 c7de825b-a66e-492c-adef-691d508d4ae1
parent 7ebf6bf3
......@@ -27,7 +27,7 @@ TARGETS = $(TARGET_BDB) $(TARGET_TDB)
default: $(TARGETS)
check: check-default
check: check-default check-x2
check-default: $(TARGET_TDB)
$(VALGRIND) ./$(TARGET_TDB)
......@@ -35,6 +35,12 @@ check-default: $(TARGET_TDB)
check-x: $(TARGET_TDB)
$(VALGRIND) ./$(TARGET_TDB) -x
# A fast transaction test that detects #455.
check-xfast: $(TARGET_TDB)
./$(TARGET_TDB) ./db-benchmark-test-tokudb --noserial -x --valsize 1000 --cachesize 8000000 --xcount 1000 --periter 20000 1
clean:
rm -rf $(TARGETS) $(BENCHDBS) *.gcno *.gcda *.gcov
......
......@@ -17,10 +17,8 @@
#endif
enum { SERIAL_SPACING = 1<<6 };
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 };
enum { DEFAULT_ITEMS_TO_INSERT_PER_ITERATION = 1<<20 };
enum { DEFAULT_ITEMS_PER_TRANSACTION = 1<<14 };
#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
......@@ -30,6 +28,9 @@ int valsize = sizeof (long long);
int pagesize = 0;
long long cachesize = 128*1024*1024;
int dupflags = 0;
int noserial = 0; // Don't do the serial stuff
int items_per_transaction = DEFAULT_ITEMS_PER_TRANSACTION;
int items_per_iteration = DEFAULT_ITEMS_TO_INSERT_PER_ITERATION;
#define STRINGIFY2(s) #s
#define STRINGIFY(s) STRINGIFY2(s)
......@@ -61,12 +62,12 @@ void setup (void) {
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR <= 4
if (dbenv->set_lk_max) {
r = dbenv->set_lk_max(dbenv, ITEMS_PER_TRANSACTION*2);
r = dbenv->set_lk_max(dbenv, items_per_transaction*2);
assert(r==0);
}
#endif
if (dbenv->set_lk_max_locks) {
r = dbenv->set_lk_max_locks(dbenv, ITEMS_PER_TRANSACTION*2);
r = dbenv->set_lk_max_locks(dbenv, items_per_transaction*2);
assert(r == 0);
}
......@@ -136,7 +137,7 @@ void insert (long long v) {
int r = db->put(db, tid, toku_fill_dbt(&kt, kc, keysize), toku_fill_dbt(&vt, vc, valsize), DB_YESOVERWRITE);
CKERR(r);
if (do_transactions) {
if (n_insertions_since_txn_began>=ITEMS_PER_TRANSACTION) {
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);
......@@ -157,7 +158,7 @@ void serial_insert_from (long long from) {
}
}
for (i=0; i<ITEMS_TO_INSERT_PER_ITERATION; i++) {
for (i=0; i<items_per_iteration; i++) {
insert((from+i)*SERIAL_SPACING);
}
if (do_transactions) {
......@@ -175,7 +176,7 @@ void random_insert_below (long long below) {
if (do_transactions) {
int r = dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0);
}
for (i=0; i<ITEMS_TO_INSERT_PER_ITERATION; i++) {
for (i=0; i<items_per_iteration; i++) {
insert(llrandom()%below);
}
if (do_transactions) {
......@@ -192,17 +193,19 @@ void biginsert (long long n_elements, struct timeval *starttime) {
long long i;
struct timeval t1,t2;
int iteration;
for (i=0, iteration=0; i<n_elements; i+=ITEMS_TO_INSERT_PER_ITERATION, iteration++) {
gettimeofday(&t1,0);
serial_insert_from(i);
gettimeofday(&t2,0);
printf("serial %9.6fs %8.0f/s ", tdiff(&t2, &t1), ITEMS_TO_INSERT_PER_ITERATION/tdiff(&t2, &t1));
fflush(stdout);
for (i=0, iteration=0; i<n_elements; i+=items_per_iteration, iteration++) {
if (!noserial) {
gettimeofday(&t1,0);
serial_insert_from(i);
gettimeofday(&t2,0);
printf("serial %9.6fs %8.0f/s ", tdiff(&t2, &t1), items_per_iteration/tdiff(&t2, &t1));
fflush(stdout);
}
gettimeofday(&t1,0);
random_insert_below((i+ITEMS_TO_INSERT_PER_ITERATION)*SERIAL_SPACING);
random_insert_below((i+items_per_iteration)*SERIAL_SPACING);
gettimeofday(&t2,0);
printf("random %9.6fs %8.0f/s ", tdiff(&t2, &t1), ITEMS_TO_INSERT_PER_ITERATION/tdiff(&t2, &t1));
printf("cumulative %9.6fs %8.0f/s\n", tdiff(&t2, starttime), (ITEMS_TO_INSERT_PER_ITERATION*2.0/tdiff(&t2, starttime))*(iteration+1));
printf("random %9.6fs %8.0f/s ", tdiff(&t2, &t1), items_per_iteration/tdiff(&t2, &t1));
printf("cumulative %9.6fs %8.0f/s\n", tdiff(&t2, starttime), (items_per_iteration*2.0/tdiff(&t2, starttime))*(iteration+1));
}
}
......@@ -212,14 +215,17 @@ const long long default_n_items = 1LL<<22;
int print_usage (const char *argv0) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, " %s [-x] [--keysize KEYSIZE] [--valsize VALSIZE] [ n_iterations ]\n", argv0);
fprintf(stderr, " %s [-x] [--keysize KEYSIZE] [--valsize VALSIZE] [--noserial] [ n_iterations ]\n", argv0);
fprintf(stderr, " where\n");
fprintf(stderr, " -x do transactions (one transaction per iteration) (default: no transactions at all)\n");
fprintf(stderr, " --keysize KEYSIZE sets the key size (default 8)\n");
fprintf(stderr, " --valsize VALSIZE sets the value size (default 8)\n");
fprintf(stderr, " --cachesize CACHESIZE set the database cache size\n");
fprintf(stderr, " --pagesize PAGESIZE sets the database page size\n");
fprintf(stderr, " n_iterations how many iterations (default %lld iterations of %d items per iteration)\n", default_n_items/ITEMS_TO_INSERT_PER_ITERATION, ITEMS_TO_INSERT_PER_ITERATION);
fprintf(stderr, " --noserial causes the serial insertions to be skipped\n");
fprintf(stderr, " --xcount N how many insertions per transaction (default=%d)\n", DEFAULT_ITEMS_PER_TRANSACTION);
fprintf(stderr, " --periter N how many insertions per iteration (default=%d)\n", DEFAULT_ITEMS_TO_INSERT_PER_ITERATION);
fprintf(stderr, " n_iterations how many iterations (default %lld)\n", default_n_items/DEFAULT_ITEMS_TO_INSERT_PER_ITERATION);
return 1;
}
......@@ -236,7 +242,21 @@ int main (int argc, const char *argv[]) {
do_transactions = 1;
continue;
}
if (strcmp(arg, "--cachesize") == 0) {
if (strcmp(arg, "--noserial") == 0) {
noserial=1;
continue;
}
if (strcmp(arg, "--xcount") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
items_per_transaction = strtoll(argv[++i], 0, 10);
continue;
}
if (strcmp(arg, "--periter") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
items_per_iteration = strtoll(argv[++i], 0, 10);
continue;
}
if (strcmp(arg, "--cachesize") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
cachesize = strtoll(argv[++i], 0, 10);
continue;
......@@ -271,9 +291,10 @@ int main (int argc, const char *argv[]) {
print_usage(argv[0]);
return 1;
}
total_n_items = ITEMS_TO_INSERT_PER_ITERATION * (long long)n_iterations;
total_n_items = items_per_iteration * (long long)n_iterations;
}
printf("Serial and random insertions of %d per batch%s\n", ITEMS_TO_INSERT_PER_ITERATION, do_transactions ? " (with transactions)" : "");
if (!noserial) printf("serial and ");
printf("random insertions of %d per batch%s\n", items_per_iteration, do_transactions ? " (with transactions)" : "");
setup();
gettimeofday(&t1,0);
biginsert(total_n_items, &t1);
......
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