Commit 6e6e27c7 authored by Barry Perlman's avatar Barry Perlman Committed by Yoni Fogel

Addresses #1694 Checkpoint stress test

git-svn-id: file:///svn/toku/tokudb@11506 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0dfea88d
...@@ -13,16 +13,6 @@ ...@@ -13,16 +13,6 @@
TODO: This test is not yet complete
- write scribble_n function to scribble over expected data (and maybe do some random inserts?)
- create separate thread to do scribbling
- have drop_dead function sleep a random time (0.1 to 5 seconds?) before sigsegv
- find some way to force disk I/O (Make cachetable very small)
Accept n as iteration number Accept n as iteration number
Operate on more than one dictionary simultaneously Operate on more than one dictionary simultaneously
...@@ -178,12 +168,36 @@ verify_and_insert (DB* db, int iter) { ...@@ -178,12 +168,36 @@ verify_and_insert (DB* db, int iter) {
} }
// Purpose of this function is to perform a variety of random acts.
// This will simulate normal database operations. The idea is for the
// the crash to occur sometimes during an insert, sometimes during a query, etc.
void * void *
random_acts(void * d) { random_acts(void * d) {
void * intothevoid = NULL; void * intothevoid = NULL;
DICTIONARY dictionaries = (DICTIONARY) d; DICTIONARY dictionaries = (DICTIONARY) d;
printf("perform random acts, %s\n", dictionaries[0].filename); if (verbose)
printf("perform random acts, %s\n", dictionaries[0].filename);
fflush(stdout); fflush(stdout);
int i = 0;
int64_t k = 0;
while (1) { // run until crash
// main thread is scribbling over dictionary 0
// this thread will futz with other dictionaries
for (i = 1; i < NUM_DICTIONARIES; i++) {
int j;
DB * db = dictionaries[i].db;
insert_random(db, NULL, NULL);
delete_both_random(db, NULL, NULL, 0); // delete only if found (performs query)
delete_both_random(db, NULL, NULL, DB_DELETE_ANY); // delete whether or not found (no query)
for (j = 0; j < 10; j++) {
delete_fixed(db, NULL, NULL, k, 0); // delete only if found to provoke more queries
k++;
}
}
}
return intothevoid; return intothevoid;
} }
...@@ -218,19 +232,17 @@ run_test (int iter, int die) { ...@@ -218,19 +232,17 @@ run_test (int iter, int die) {
snapshot(NULL, 1); snapshot(NULL, 1);
if (die) { if (die) {
//TODO: in separate thread do random inserts/deletes/queries // separate thread will perform random acts on other dictionaries (not 0)
// in this thread:
// first scribble over correct data
// sleep a random amount of time and drop dead
int r = toku_pthread_create(&thread, 0, random_acts, (void *) dictionaries); int r = toku_pthread_create(&thread, 0, random_acts, (void *) dictionaries);
CKERR(r); CKERR(r);
// this thead will scribble over dictionary 0 before crash to verify that
// post-checkpoint inserts are not in the database
DB* db = dictionaries[0].db; DB* db = dictionaries[0].db;
scribble(db, iter); scribble(db, iter);
u_int32_t delay = myrandom(); u_int32_t delay = myrandom();
delay &= 0xFFF; // select lower 12 bits, shifted up 8 delay &= 0xFFF; // select lower 12 bits, shifted up 8 for random number ...
delay = delay << 8; // sleep up to one second delay = delay << 8; // ... uniformly distributed between 0 and 1M ...
usleep(delay); usleep(delay); // ... to sleep up to one second (1M usec)
drop_dead(); drop_dead();
} }
else { else {
...@@ -254,8 +266,6 @@ test_main (int argc, char *argv[]) { ...@@ -254,8 +266,6 @@ test_main (int argc, char *argv[]) {
// get arguments, set parameters // get arguments, set parameters
printf("enter test_main \n");
int iter = -1; int iter = -1;
int c; int c;
...@@ -270,7 +280,6 @@ test_main (int argc, char *argv[]) { ...@@ -270,7 +280,6 @@ test_main (int argc, char *argv[]) {
break; break;
case 'i': case 'i':
iter = atoi(optarg); iter = atoi(optarg);
printf(" setting iter = %d\n", iter);
break; break;
case 'v': case 'v':
verbose++; verbose++;
...@@ -292,13 +301,15 @@ test_main (int argc, char *argv[]) { ...@@ -292,13 +301,15 @@ test_main (int argc, char *argv[]) {
// for developing this test // for developing this test
if (iter <0) { if (iter <0) {
printf("No argument, just run five times without crash\n"); if (verbose)
printf("No argument, just run five times without crash\n");
for (iter = 0; iter<5; iter++) { for (iter = 0; iter<5; iter++) {
run_test(iter, 0); run_test(iter, 0);
} }
} }
else { else {
printf("checkpoint_stress running one iteration, iter = %d\n", iter); if (verbose)
printf("checkpoint_stress running one iteration, iter = %d\n", iter);
run_test(iter, crash); run_test(iter, crash);
} }
......
...@@ -21,6 +21,12 @@ typedef struct { ...@@ -21,6 +21,12 @@ typedef struct {
} DICTIONARY_S, *DICTIONARY; } DICTIONARY_S, *DICTIONARY;
static inline int64_t UU()
generate_val(int64_t key) {
int64_t val = key + 314;
return val;
}
// return 0 if same // return 0 if same
static int static int
verify_identical_dbts(const DBT *dbt1, const DBT *dbt2) { verify_identical_dbts(const DBT *dbt1, const DBT *dbt2) {
...@@ -260,13 +266,50 @@ insert_random(DB *db1, DB *db2, DB_TXN *txn) { ...@@ -260,13 +266,50 @@ insert_random(DB *db1, DB *db2, DB_TXN *txn) {
} }
} }
static inline int64_t UU() static void UU()
generate_val(int64_t key) { delete_both_random(DB *db1, DB *db2, DB_TXN *txn, u_int32_t flags) {
int64_t val = key + 314; int64_t k = random64();
return val; int64_t v = random64();
int r;
DBT key;
DBT val;
dbt_init(&key, &k, sizeof(k));
dbt_init(&val, &v, sizeof(v));
if (db1) {
r = db1->delboth(db1, txn, &key, &val, flags);
CKERR2s(r, 0, DB_NOTFOUND);
}
if (db2) {
r = db2->delboth(db2, txn, &key, &val, flags);
CKERR2s(r, 0, DB_NOTFOUND);
}
}
static void UU()
delete_fixed(DB *db1, DB *db2, DB_TXN *txn, int64_t k, u_int32_t flags) {
int r;
DBT key;
DBT val;
int64_t v = generate_val(k);
dbt_init(&key, &k, sizeof(k));
dbt_init(&val, &v, sizeof(v));
if (db1) {
r = db1->delboth(db1, txn, &key, &val, flags);
CKERR2s(r, 0, DB_NOTFOUND);
}
if (db2) {
r = db2->delboth(db2, txn, &key, &val, flags);
CKERR2s(r, 0, DB_NOTFOUND);
}
} }
static void static void
insert_n(DB *db1, DB *db2, DB_TXN *txn, int firstkey, int n, int offset) { insert_n(DB *db1, DB *db2, DB_TXN *txn, int firstkey, int n, int offset) {
int64_t k; int64_t k;
......
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