Commit 51cc8acb authored by Rich Prohaska's avatar Rich Prohaska

remove tabs from examples

parent 0f1516ef
...@@ -161,7 +161,7 @@ static void do_prelock(DB* db, DB_TXN* txn) { ...@@ -161,7 +161,7 @@ static void do_prelock(DB* db, DB_TXN* txn) {
int r = db->pre_acquire_table_lock(db, txn); int r = db->pre_acquire_table_lock(db, txn);
assert(r==0); assert(r==0);
#else #else
(void) db; (void) txn; (void) db; (void) txn;
#endif #endif
} }
} }
...@@ -182,11 +182,11 @@ static void benchmark_setup (void) { ...@@ -182,11 +182,11 @@ static void benchmark_setup (void) {
int r; int r;
if (!do_append) { if (!do_append) {
char unlink_cmd[strlen(dbdir) + strlen("rm -rf ") + 1]; char unlink_cmd[strlen(dbdir) + strlen("rm -rf ") + 1];
snprintf(unlink_cmd, sizeof(unlink_cmd), "rm -rf %s", dbdir); snprintf(unlink_cmd, sizeof(unlink_cmd), "rm -rf %s", dbdir);
//printf("unlink_cmd=%s\n", unlink_cmd); //printf("unlink_cmd=%s\n", unlink_cmd);
system(unlink_cmd); system(unlink_cmd);
if (strcmp(dbdir, ".") != 0) { if (strcmp(dbdir, ".") != 0) {
r = mkdir(dbdir,S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH); r = mkdir(dbdir,S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
assert(r == 0); assert(r == 0);
...@@ -199,21 +199,21 @@ static void benchmark_setup (void) { ...@@ -199,21 +199,21 @@ static void benchmark_setup (void) {
#if !defined(TOKUDB) #if !defined(TOKUDB)
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR <= 4 #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR <= 4
if (dbenv->set_lk_max) { 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); assert(r==0);
} }
#elif DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR <= 7 #elif DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR <= 7
if (dbenv->set_lk_max_locks) { 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); assert(r==0);
} }
if (dbenv->set_lk_max_lockers) { if (dbenv->set_lk_max_lockers) {
r = dbenv->set_lk_max_lockers(dbenv, items_per_transaction*2); r = dbenv->set_lk_max_lockers(dbenv, items_per_transaction*2);
assert(r==0); assert(r==0);
} }
if (dbenv->set_lk_max_objects) { if (dbenv->set_lk_max_objects) {
r = dbenv->set_lk_max_objects(dbenv, items_per_transaction*2); r = dbenv->set_lk_max_objects(dbenv, items_per_transaction*2);
assert(r==0); assert(r==0);
} }
#else #else
#error #error
...@@ -226,8 +226,8 @@ static void benchmark_setup (void) { ...@@ -226,8 +226,8 @@ static void benchmark_setup (void) {
printf("WARNING: set_cachesize %d\n", r); printf("WARNING: set_cachesize %d\n", r);
} }
{ {
r = dbenv->open(dbenv, dbdir, env_open_flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); r = dbenv->open(dbenv, dbdir, env_open_flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
assert(r == 0); assert(r == 0);
} }
#if defined(TOKUDB) #if defined(TOKUDB)
...@@ -243,7 +243,7 @@ static void benchmark_setup (void) { ...@@ -243,7 +243,7 @@ static void benchmark_setup (void) {
assert(r == 0); assert(r == 0);
if (do_transactions) { if (do_transactions) {
r=dbenv->txn_begin(dbenv, 0, &tid, 0); CKERR(r); r=dbenv->txn_begin(dbenv, 0, &tid, 0); CKERR(r);
} }
if (pagesize && db->set_pagesize) { if (pagesize && db->set_pagesize) {
r = db->set_pagesize(db, pagesize); r = db->set_pagesize(db, pagesize);
...@@ -278,7 +278,7 @@ static void benchmark_setup (void) { ...@@ -278,7 +278,7 @@ static void benchmark_setup (void) {
r=dbenv->txn_begin(dbenv, 0, &tid, 0); CKERR(r); r=dbenv->txn_begin(dbenv, 0, &tid, 0); CKERR(r);
} }
if (do_transactions) { if (do_transactions) {
if (singlex) if (singlex)
do_prelock(db, tid); do_prelock(db, tid);
else { else {
r=tid->commit(tid, 0); r=tid->commit(tid, 0);
...@@ -300,15 +300,15 @@ static void benchmark_shutdown (void) { ...@@ -300,15 +300,15 @@ static void benchmark_shutdown (void) {
if (do_transactions && singlex && !insert1first && (singlex_create || prelock)) { if (do_transactions && singlex && !insert1first && (singlex_create || prelock)) {
#if defined(TOKUDB) #if defined(TOKUDB)
//There should be a single 'truncate' in the rollback instead of many 'insert' entries. //There should be a single 'truncate' in the rollback instead of many 'insert' entries.
struct txn_stat *s; struct txn_stat *s;
r = tid->txn_stat(tid, &s); r = tid->txn_stat(tid, &s);
assert(r==0); assert(r==0);
//TODO: #1125 Always do the test after performance testing is done. //TODO: #1125 Always do the test after performance testing is done.
if (singlex_child) fprintf(stderr, "SKIPPED 'small rollback' test for child txn\n"); if (singlex_child) fprintf(stderr, "SKIPPED 'small rollback' test for child txn\n");
else else
assert(s->rollback_raw_count < 100); // gross test, not worth investigating details assert(s->rollback_raw_count < 100); // gross test, not worth investigating details
free(s); free(s);
//system("ls -l bench.tokudb"); //system("ls -l bench.tokudb");
#endif #endif
} }
if (do_transactions && singlex) { if (do_transactions && singlex) {
...@@ -337,7 +337,7 @@ static void benchmark_shutdown (void) { ...@@ -337,7 +337,7 @@ static void benchmark_shutdown (void) {
static void long_long_to_array (unsigned char *a, int array_size, unsigned long long l) { static void long_long_to_array (unsigned char *a, int array_size, unsigned long long l) {
int i; int i;
for (i=0; i<8 && i<array_size; i++) for (i=0; i<8 && i<array_size; i++)
a[i] = (l>>(56-8*i))&0xff; a[i] = (l>>(56-8*i))&0xff;
} }
static DBT *fill_dbt(DBT *dbt, const void *data, int size) { static DBT *fill_dbt(DBT *dbt, const void *data, int size) {
...@@ -351,10 +351,10 @@ static DBT *fill_dbt(DBT *dbt, const void *data, int size) { ...@@ -351,10 +351,10 @@ static DBT *fill_dbt(DBT *dbt, const void *data, int size) {
static void fill_array (unsigned char *data, int size) { static void fill_array (unsigned char *data, int size) {
memset(data, 0, size); memset(data, 0, size);
if (compressibility>0) { if (compressibility>0) {
int i; int i;
for (i=0; i<size/compressibility; i++) { for (i=0; i<size/compressibility; i++) {
data[i] = (unsigned char) random(); data[i] = (unsigned char) random();
} }
} }
} }
...@@ -368,36 +368,35 @@ static void insert (long long v) { ...@@ -368,36 +368,35 @@ static void insert (long long v) {
int r = db->put(db, tid, fill_dbt(&kt, kc, keysize), fill_dbt(&vt, vc, valsize), put_flags); int r = db->put(db, tid, fill_dbt(&kt, kc, keysize), fill_dbt(&vt, vc, valsize), put_flags);
CKERR(r); CKERR(r);
if (do_transactions) { if (do_transactions) {
if (n_insertions_since_txn_began>=items_per_transaction && !singlex) { if (n_insertions_since_txn_began>=items_per_transaction && !singlex) {
n_insertions_since_txn_began=0; n_insertions_since_txn_began=0;
r = tid->commit(tid, 0); assert(r==0); r = tid->commit(tid, 0); assert(r==0);
tid = NULL; tid = NULL;
r=dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0); r=dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0);
do_prelock(db, tid); do_prelock(db, tid);
n_insertions_since_txn_began=0; n_insertions_since_txn_began=0;
} }
n_insertions_since_txn_began++; n_insertions_since_txn_began++;
} }
} }
static void serial_insert_from (long long from) { static void serial_insert_from (long long from) {
long long i; long long i;
if (do_transactions && !singlex) { if (do_transactions && !singlex) {
int r = dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0); int r = dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0);
do_prelock(db, tid); do_prelock(db, tid);
{ {
DBT k,v; DBT k,v;
r=db->put(db, tid, fill_dbt(&k, "a", 1), fill_dbt(&v, "b", 1), put_flags); r=db->put(db, tid, fill_dbt(&k, "a", 1), fill_dbt(&v, "b", 1), put_flags);
CKERR(r); CKERR(r);
} }
} }
for (i=0; i<items_per_iteration; i++) { for (i=0; i<items_per_iteration; i++) {
insert((from+i)*SERIAL_SPACING); insert((from+i)*SERIAL_SPACING);
} }
if (do_transactions && !singlex) { if (do_transactions && !singlex) {
int r= tid->commit(tid, 0); assert(r==0); int r= tid->commit(tid, 0); assert(r==0);
tid=NULL; tid=NULL;
} }
} }
...@@ -408,15 +407,15 @@ static long long llrandom (void) { ...@@ -408,15 +407,15 @@ static long long llrandom (void) {
static void random_insert_below (long long below) { static void random_insert_below (long long below) {
long long i; long long i;
if (do_transactions && !singlex) { if (do_transactions && !singlex) {
int r = dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0); int r = dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0);
do_prelock(db, tid); do_prelock(db, tid);
} }
for (i=0; i<items_per_iteration; i++) { for (i=0; i<items_per_iteration; i++) {
insert(llrandom()%below); insert(llrandom()%below);
} }
if (do_transactions && !singlex) { if (do_transactions && !singlex) {
int r= tid->commit(tid, 0); assert(r==0); int r= tid->commit(tid, 0); assert(r==0);
tid=NULL; tid=NULL;
} }
} }
...@@ -429,15 +428,15 @@ static void biginsert (long long n_elements, struct timeval *starttime) { ...@@ -429,15 +428,15 @@ static void biginsert (long long n_elements, struct timeval *starttime) {
printf("%d ", iteration); printf("%d ", iteration);
fflush(stdout); fflush(stdout);
} }
if (!noserial) { if (!noserial) {
gettimeofday(&t1,0); gettimeofday(&t1,0);
serial_insert_from(i); serial_insert_from(i);
gettimeofday(&t2,0); gettimeofday(&t2,0);
if (verbose) { if (verbose) {
printf("serial %9.6fs %8.0f/s ", toku_tdiff(&t2, &t1), items_per_iteration/toku_tdiff(&t2, &t1)); printf("serial %9.6fs %8.0f/s ", toku_tdiff(&t2, &t1), items_per_iteration/toku_tdiff(&t2, &t1));
fflush(stdout); fflush(stdout);
} }
} }
if (!norandom) { if (!norandom) {
gettimeofday(&t1,0); gettimeofday(&t1,0);
random_insert_below((i+items_per_iteration)*SERIAL_SPACING); random_insert_below((i+items_per_iteration)*SERIAL_SPACING);
...@@ -447,7 +446,7 @@ static void biginsert (long long n_elements, struct timeval *starttime) { ...@@ -447,7 +446,7 @@ static void biginsert (long long n_elements, struct timeval *starttime) {
fflush(stdout); fflush(stdout);
} }
} }
if (verbose) { if (verbose) {
printf("cumulative %9.6fs %8.0f/s\n", toku_tdiff(&t2, starttime), (((float)items_per_iteration*(!noserial+!norandom))/toku_tdiff(&t2, starttime))*(iteration+1)); printf("cumulative %9.6fs %8.0f/s\n", toku_tdiff(&t2, starttime), (((float)items_per_iteration*(!noserial+!norandom))/toku_tdiff(&t2, starttime))*(iteration+1));
fflush(stdout); fflush(stdout);
} }
...@@ -497,34 +496,34 @@ int main (int argc, const char *argv[]) { ...@@ -497,34 +496,34 @@ int main (int argc, const char *argv[]) {
const char *arg = argv[i]; const char *arg = argv[i];
if (arg[0] != '-') if (arg[0] != '-')
break; break;
if (strcmp(arg, "-q") == 0) { if (strcmp(arg, "-q") == 0) {
verbose--; if (verbose<0) verbose=0; verbose--; if (verbose<0) verbose=0;
} else if (strcmp(arg, "-x") == 0) { } else if (strcmp(arg, "-x") == 0) {
do_transactions = 1; do_transactions = 1;
} else if (strcmp(arg, "--noserial") == 0) { } else if (strcmp(arg, "--noserial") == 0) {
noserial=1; noserial=1;
} else if (strcmp(arg, "--norandom") == 0) { } else if (strcmp(arg, "--norandom") == 0) {
norandom=1; norandom=1;
} else if (strcmp(arg, "--compressibility") == 0) { } else if (strcmp(arg, "--compressibility") == 0) {
compressibility = atof(argv[++i]); compressibility = atof(argv[++i]);
} else if (strcmp(arg, "--nolog") == 0) { } else if (strcmp(arg, "--nolog") == 0) {
if_transactions_do_logging = 0; if_transactions_do_logging = 0;
} else if (strcmp(arg, "--singlex-create") == 0) { } else if (strcmp(arg, "--singlex-create") == 0) {
do_transactions = 1; do_transactions = 1;
singlex = 1; singlex = 1;
singlex_create = 1; singlex_create = 1;
} else if (strcmp(arg, "--finish-child-first") == 0) { } else if (strcmp(arg, "--finish-child-first") == 0) {
finish_child_first = 1; finish_child_first = 1;
} else if (strcmp(arg, "--singlex-child") == 0) { } else if (strcmp(arg, "--singlex-child") == 0) {
do_transactions = 1; do_transactions = 1;
singlex = 1; singlex = 1;
singlex_child = 1; singlex_child = 1;
} else if (strcmp(arg, "--singlex") == 0) { } else if (strcmp(arg, "--singlex") == 0) {
do_transactions = 1; do_transactions = 1;
singlex = 1; singlex = 1;
} else if (strcmp(arg, "--insert1first") == 0) { } else if (strcmp(arg, "--insert1first") == 0) {
insert1first = 1; insert1first = 1;
} else if (strcmp(arg, "--xcount") == 0) { } else if (strcmp(arg, "--xcount") == 0) {
if (i+1 >= argc) return print_usage(argv[0]); if (i+1 >= argc) return print_usage(argv[0]);
items_per_transaction = strtoll(argv[++i], &endptr, 10); assert(*endptr == 0); items_per_transaction = strtoll(argv[++i], &endptr, 10); assert(*endptr == 0);
} else if (strcmp(arg, "--abort") == 0) { } else if (strcmp(arg, "--abort") == 0) {
...@@ -544,9 +543,9 @@ int main (int argc, const char *argv[]) { ...@@ -544,9 +543,9 @@ int main (int argc, const char *argv[]) {
} else if (strcmp(arg, "--pagesize") == 0) { } else if (strcmp(arg, "--pagesize") == 0) {
if (i+1 >= argc) return print_usage(argv[0]); if (i+1 >= argc) return print_usage(argv[0]);
pagesize = atoi(argv[++i]); pagesize = atoi(argv[++i]);
} else if (strcmp(arg, "--env") == 0) { } else if (strcmp(arg, "--env") == 0) {
if (i+1 >= argc) return print_usage(argv[0]); if (i+1 >= argc) return print_usage(argv[0]);
dbdir = argv[++i]; dbdir = argv[++i];
} else if (strcmp(arg, "--prelock") == 0) { } else if (strcmp(arg, "--prelock") == 0) {
prelock=1; prelock=1;
} else if (strcmp(arg, "--prelockflag") == 0) { } else if (strcmp(arg, "--prelockflag") == 0) {
...@@ -568,11 +567,11 @@ int main (int argc, const char *argv[]) { ...@@ -568,11 +567,11 @@ int main (int argc, const char *argv[]) {
else else
put_flags = 0; put_flags = 0;
} else { } else {
return print_usage(argv[0]); return print_usage(argv[0]);
} }
} }
if (do_transactions) { if (do_transactions) {
env_open_flags |= DB_INIT_TXN | if_transactions_do_logging | DB_INIT_LOCK; env_open_flags |= DB_INIT_TXN | if_transactions_do_logging | DB_INIT_LOCK;
} }
if (do_transactions && prelockflag) { if (do_transactions && prelockflag) {
put_flags |= DB_PRELOCKED_WRITE; put_flags |= DB_PRELOCKED_WRITE;
...@@ -589,10 +588,10 @@ int main (int argc, const char *argv[]) { ...@@ -589,10 +588,10 @@ int main (int argc, const char *argv[]) {
total_n_items = items_per_iteration * (long long)n_iterations; total_n_items = items_per_iteration * (long long)n_iterations;
} }
if (verbose) { if (verbose) {
if (!noserial) printf("serial "); if (!noserial) printf("serial ");
if (!noserial && !norandom) printf("and "); if (!noserial && !norandom) printf("and ");
if (!norandom) printf("random "); if (!norandom) printf("random ");
printf("insertions of %d per batch%s\n", items_per_iteration, do_transactions ? " (with transactions)" : ""); printf("insertions of %d per batch%s\n", items_per_iteration, do_transactions ? " (with transactions)" : "");
} }
benchmark_setup(); benchmark_setup();
gettimeofday(&t1,0); gettimeofday(&t1,0);
...@@ -601,9 +600,9 @@ int main (int argc, const char *argv[]) { ...@@ -601,9 +600,9 @@ int main (int argc, const char *argv[]) {
benchmark_shutdown(); benchmark_shutdown();
gettimeofday(&t3,0); gettimeofday(&t3,0);
if (verbose) { if (verbose) {
printf("Shutdown %9.6fs\n", toku_tdiff(&t3, &t2)); printf("Shutdown %9.6fs\n", toku_tdiff(&t3, &t2));
printf("Total time %9.6fs for %lld insertions = %8.0f/s\n", toku_tdiff(&t3, &t1), printf("Total time %9.6fs for %lld insertions = %8.0f/s\n", toku_tdiff(&t3, &t1),
(!noserial+!norandom)*total_n_items, (!noserial+!norandom)*total_n_items/toku_tdiff(&t3, &t1)); (!noserial+!norandom)*total_n_items, (!noserial+!norandom)*total_n_items/toku_tdiff(&t3, &t1));
} }
return 0; return 0;
......
...@@ -154,34 +154,34 @@ static void parse_args (int argc, const char *argv[]) { ...@@ -154,34 +154,34 @@ static void parse_args (int argc, const char *argv[]) {
argc--; argv++; argc--; argv++;
int specified_run_mode=0; int specified_run_mode=0;
while (argc>0) { while (argc>0) {
if (strcmp(*argv,"--verify-lwc")==0) { if (strcmp(*argv,"--verify-lwc")==0) {
if (specified_run_mode && run_mode!=RUN_VERIFY) { two_modes: fprintf(stderr, "You specified two run modes\n"); exit(1); } if (specified_run_mode && run_mode!=RUN_VERIFY) { two_modes: fprintf(stderr, "You specified two run modes\n"); exit(1); }
run_mode = RUN_VERIFY; run_mode = RUN_VERIFY;
} else if (strcmp(*argv, "--lwc")==0) { } else if (strcmp(*argv, "--lwc")==0) {
if (specified_run_mode && run_mode!=RUN_LWC) goto two_modes; if (specified_run_mode && run_mode!=RUN_LWC) goto two_modes;
run_mode = RUN_LWC; run_mode = RUN_LWC;
} else if (strcmp(*argv, "--hwc")==0) { } else if (strcmp(*argv, "--hwc")==0) {
if (specified_run_mode && run_mode!=RUN_VERIFY) goto two_modes; if (specified_run_mode && run_mode!=RUN_VERIFY) goto two_modes;
run_mode = RUN_HWC; run_mode = RUN_HWC;
} else if (strcmp(*argv, "--prelock")==0) prelock=1; } else if (strcmp(*argv, "--prelock")==0) prelock=1;
#ifdef TOKUDB #ifdef TOKUDB
else if (strcmp(*argv, "--prelockflag")==0) { prelockflag=1; lock_flag = DB_PRELOCKED; } else if (strcmp(*argv, "--prelockflag")==0) { prelockflag=1; lock_flag = DB_PRELOCKED; }
else if (strcmp(*argv, "--prelockwriteflag")==0) { prelockflag=1; lock_flag = DB_PRELOCKED_WRITE; } else if (strcmp(*argv, "--prelockwriteflag")==0) { prelockflag=1; lock_flag = DB_PRELOCKED_WRITE; }
#endif #endif
else if (strcmp(*argv, "--nox")==0) { do_txns=0; } else if (strcmp(*argv, "--nox")==0) { do_txns=0; }
else if (strcmp(*argv, "--count")==0) { else if (strcmp(*argv, "--count")==0) {
char *end; char *end;
argc--; argv++; argc--; argv++;
errno=0; limitcount=strtol(*argv, &end, 10); assert(errno==0); errno=0; limitcount=strtol(*argv, &end, 10); assert(errno==0);
printf("Limiting count to %ld\n", limitcount); printf("Limiting count to %ld\n", limitcount);
} else if (strcmp(*argv, "--cachesize")==0 && argc>0) { } else if (strcmp(*argv, "--cachesize")==0 && argc>0) {
char *end; char *end;
argc--; argv++; argc--; argv++;
cachesize=(u_int32_t)strtol(*argv, &end, 10); cachesize=(u_int32_t)strtol(*argv, &end, 10);
} else if (strcmp(*argv, "--env") == 0) { } else if (strcmp(*argv, "--env") == 0) {
argc--; argv++; argc--; argv++;
if (argc==0) exit(print_usage(pname)); if (argc==0) exit(print_usage(pname));
dbdir = *argv; dbdir = *argv;
} else if (strcmp(*argv, "--range") == 0 && argc > 2) { } else if (strcmp(*argv, "--range") == 0 && argc > 2) {
run_mode = RUN_RANGE; run_mode = RUN_RANGE;
argc--; argv++; argc--; argv++;
...@@ -192,15 +192,15 @@ static void parse_args (int argc, const char *argv[]) { ...@@ -192,15 +192,15 @@ static void parse_args (int argc, const char *argv[]) {
argc--; argv++; argc--; argv++;
n_experiments = strtol(*argv, NULL, 10); n_experiments = strtol(*argv, NULL, 10);
} else if (strcmp(*argv, "--srandom") == 0 && argc > 1) { } else if (strcmp(*argv, "--srandom") == 0 && argc > 1) {
argc--; argv++; argc--; argv++;
srandom(atoi(*argv)); srandom(atoi(*argv));
} else if (strcmp(*argv, "--bulk_fetch") == 0 && argc > 1) { } else if (strcmp(*argv, "--bulk_fetch") == 0 && argc > 1) {
argc--; argv++; argc--; argv++;
bulk_fetch = atoi(*argv); bulk_fetch = atoi(*argv);
} else { } else {
exit(print_usage(pname)); exit(print_usage(pname));
} }
argc--; argv++; argc--; argv++;
} }
//Prelocking is meaningless without transactions //Prelocking is meaningless without transactions
if (do_txns==0) { if (do_txns==0) {
...@@ -217,13 +217,13 @@ static void scanscan_setup (void) { ...@@ -217,13 +217,13 @@ static void scanscan_setup (void) {
r = env->open(env, dbdir, do_txns? env_open_flags_yesx : env_open_flags_nox, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); assert(r==0); r = env->open(env, dbdir, do_txns? env_open_flags_yesx : env_open_flags_nox, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); assert(r==0);
r = db_create(&db, env, 0); assert(r==0); r = db_create(&db, env, 0); assert(r==0);
if (do_txns) { if (do_txns) {
r = env->txn_begin(env, 0, &tid, 0); assert(r==0); r = env->txn_begin(env, 0, &tid, 0); assert(r==0);
} }
r = db->open(db, tid, dbfilename, NULL, DB_BTREE, 0, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); assert(r==0); r = db->open(db, tid, dbfilename, NULL, DB_BTREE, 0, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); assert(r==0);
#ifdef TOKUDB #ifdef TOKUDB
if (prelock) { if (prelock) {
r = db->pre_acquire_table_lock(db, tid); r = db->pre_acquire_table_lock(db, tid);
assert(r==0); assert(r==0);
} }
#endif #endif
} }
...@@ -232,7 +232,7 @@ static void scanscan_shutdown (void) { ...@@ -232,7 +232,7 @@ static void scanscan_shutdown (void) {
int r; int r;
r = db->close(db, 0); assert(r==0); r = db->close(db, 0); assert(r==0);
if (do_txns) { if (do_txns) {
r = tid->commit(tid, 0); assert(r==0); r = tid->commit(tid, 0); assert(r==0);
} }
r = env->close(env, 0); assert(r==0); r = env->close(env, 0); assert(r==0);
} }
...@@ -248,31 +248,31 @@ static void scanscan_hwc (void) { ...@@ -248,31 +248,31 @@ static void scanscan_hwc (void) {
int r; int r;
int counter=0; int counter=0;
for (counter=0; counter<n_experiments; counter++) { for (counter=0; counter<n_experiments; counter++) {
long long totalbytes=0; long long totalbytes=0;
int rowcounter=0; int rowcounter=0;
double prevtime = gettime(); double prevtime = gettime();
DBT k,v; DBT k,v;
DBC *dbc; DBC *dbc;
r = db->cursor(db, tid, &dbc, 0); assert(r==0); r = db->cursor(db, tid, &dbc, 0); assert(r==0);
memset(&k, 0, sizeof(k)); memset(&k, 0, sizeof(k));
memset(&v, 0, sizeof(v)); memset(&v, 0, sizeof(v));
u_int32_t c_get_flags = DB_NEXT; u_int32_t c_get_flags = DB_NEXT;
if (prelockflag && (counter || prelock)) { if (prelockflag && (counter || prelock)) {
c_get_flags |= lock_flag; c_get_flags |= lock_flag;
} }
while (0 == (r = dbc->c_get(dbc, &k, &v, c_get_flags))) { while (0 == (r = dbc->c_get(dbc, &k, &v, c_get_flags))) {
//printf("r=%d\n", r); //printf("r=%d\n", r);
totalbytes += k.size + v.size; totalbytes += k.size + v.size;
rowcounter++; rowcounter++;
if (limitcount>0 && rowcounter>=limitcount) break; if (limitcount>0 && rowcounter>=limitcount) break;
} }
assert(r==DB_NOTFOUND); assert(r==DB_NOTFOUND);
r = dbc->c_close(dbc); assert(r==0); r = dbc->c_close(dbc); assert(r==0);
double thistime = gettime(); double thistime = gettime();
double tdiff = thistime-prevtime; double tdiff = thistime-prevtime;
printf("Scan %lld bytes (%d rows) in %9.6fs at %9fMB/s\n", totalbytes, rowcounter, tdiff, 1e-6*totalbytes/tdiff); printf("Scan %lld bytes (%d rows) in %9.6fs at %9fMB/s\n", totalbytes, rowcounter, tdiff, 1e-6*totalbytes/tdiff);
} }
} }
...@@ -294,23 +294,23 @@ static void scanscan_lwc (void) { ...@@ -294,23 +294,23 @@ static void scanscan_lwc (void) {
int r; int r;
int counter=0; int counter=0;
for (counter=0; counter<n_experiments; counter++) { for (counter=0; counter<n_experiments; counter++) {
struct extra_count e = {0,0}; struct extra_count e = {0,0};
double prevtime = gettime(); double prevtime = gettime();
DBC *dbc; DBC *dbc;
r = db->cursor(db, tid, &dbc, 0); assert(r==0); r = db->cursor(db, tid, &dbc, 0); assert(r==0);
u_int32_t f_flags = 0; u_int32_t f_flags = 0;
if (prelockflag && (counter || prelock)) { if (prelockflag && (counter || prelock)) {
f_flags |= lock_flag; f_flags |= lock_flag;
} }
long rowcounter=0; long rowcounter=0;
while (0 == (r = dbc->c_getf_next(dbc, f_flags, counttotalbytes, &e))) { while (0 == (r = dbc->c_getf_next(dbc, f_flags, counttotalbytes, &e))) {
rowcounter++; rowcounter++;
if (limitcount>0 && rowcounter>=limitcount) break; if (limitcount>0 && rowcounter>=limitcount) break;
} }
r = dbc->c_close(dbc); assert(r==0); r = dbc->c_close(dbc); assert(r==0);
double thistime = gettime(); double thistime = gettime();
double tdiff = thistime-prevtime; double tdiff = thistime-prevtime;
printf("LWC Scan %lld bytes (%d rows) in %9.6fs at %9fMB/s\n", e.totalbytes, e.rowcounter, tdiff, 1e-6*e.totalbytes/tdiff); printf("LWC Scan %lld bytes (%d rows) in %9.6fs at %9fMB/s\n", e.totalbytes, e.rowcounter, tdiff, 1e-6*e.totalbytes/tdiff);
} }
} }
#endif #endif
...@@ -327,15 +327,15 @@ static void scanscan_range (void) { ...@@ -327,15 +327,15 @@ static void scanscan_range (void) {
for (counter = 0; counter < n_experiments; counter++) { for (counter = 0; counter < n_experiments; counter++) {
if (1) { //if ((counter&1) == 0) { if (1) { //if ((counter&1) == 0) {
makekey: makekey:
// generate a random key in the key range // generate a random key in the key range
k = (start_range + (random() % (end_range - start_range))) * (1<<6); k = (start_range + (random() % (end_range - start_range))) * (1<<6);
int i; int i;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
kv[i] = k >> (56-8*i); kv[i] = k >> (56-8*i);
} }
memset(&key, 0, sizeof key); key.data = &kv, key.size = sizeof kv; memset(&key, 0, sizeof key); key.data = &kv, key.size = sizeof kv;
memset(&val, 0, sizeof val); memset(&val, 0, sizeof val);
double tstart = gettime(); double tstart = gettime();
...@@ -352,14 +352,14 @@ static void scanscan_range (void) { ...@@ -352,14 +352,14 @@ static void scanscan_range (void) {
#ifdef TOKUDB #ifdef TOKUDB
// do the range scan // do the range scan
long rowcounter = 0; long rowcounter = 0;
struct extra_count e = {0,0}; struct extra_count e = {0,0};
while (limitcount > 0 && rowcounter < limitcount) { while (limitcount > 0 && rowcounter < limitcount) {
r = dbc->c_getf_next(dbc, prelockflag ? lock_flag : 0, counttotalbytes, &e); r = dbc->c_getf_next(dbc, prelockflag ? lock_flag : 0, counttotalbytes, &e);
if (r != 0) if (r != 0)
break; break;
rowcounter++; rowcounter++;
} }
#endif #endif
r = dbc->c_close(dbc); r = dbc->c_close(dbc);
...@@ -408,33 +408,33 @@ static void scanscan_verify (void) { ...@@ -408,33 +408,33 @@ static void scanscan_verify (void) {
int r; int r;
int counter=0; int counter=0;
for (counter=0; counter<n_experiments; counter++) { for (counter=0; counter<n_experiments; counter++) {
struct extra_verify v; struct extra_verify v;
v.totalbytes=0; v.totalbytes=0;
v.rowcounter=0; v.rowcounter=0;
double prevtime = gettime(); double prevtime = gettime();
DBC *dbc1, *dbc2; DBC *dbc1, *dbc2;
r = db->cursor(db, tid, &dbc1, 0); assert(r==0); r = db->cursor(db, tid, &dbc1, 0); assert(r==0);
r = db->cursor(db, tid, &dbc2, 0); assert(r==0); r = db->cursor(db, tid, &dbc2, 0); assert(r==0);
memset(&v.k, 0, sizeof(v.k)); memset(&v.k, 0, sizeof(v.k));
memset(&v.v, 0, sizeof(v.v)); memset(&v.v, 0, sizeof(v.v));
u_int32_t f_flags = 0; u_int32_t f_flags = 0;
u_int32_t c_get_flags = DB_NEXT; u_int32_t c_get_flags = DB_NEXT;
if (prelockflag && (counter || prelock)) { if (prelockflag && (counter || prelock)) {
f_flags |= lock_flag; f_flags |= lock_flag;
c_get_flags |= lock_flag; c_get_flags |= lock_flag;
} }
while (1) { while (1) {
int r1,r2; int r1,r2;
r2 = dbc1->c_get(dbc1, &v.k, &v.v, c_get_flags); r2 = dbc1->c_get(dbc1, &v.k, &v.v, c_get_flags);
r1 = dbc2->c_getf_next(dbc2, f_flags, checkbytes, &v); r1 = dbc2->c_getf_next(dbc2, f_flags, checkbytes, &v);
assert(r1==r2); assert(r1==r2);
if (r1) break; if (r1) break;
} }
r = dbc1->c_close(dbc1); assert(r==0); r = dbc1->c_close(dbc1); assert(r==0);
r = dbc2->c_close(dbc2); assert(r==0); r = dbc2->c_close(dbc2); assert(r==0);
double thistime = gettime(); double thistime = gettime();
double tdiff = thistime-prevtime; double tdiff = thistime-prevtime;
printf("verify %lld bytes (%d rows) in %9.6fs at %9fMB/s\n", v.totalbytes, v.rowcounter, tdiff, 1e-6*v.totalbytes/tdiff); printf("verify %lld bytes (%d rows) in %9.6fs at %9fMB/s\n", v.totalbytes, v.rowcounter, tdiff, 1e-6*v.totalbytes/tdiff);
} }
} }
......
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