Commit 0a6c63ac authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

#4336 fix a locking test for bdb refs[t:4336]

git-svn-id: file:///svn/toku/tokudb@39043 c7de825b-a66e-492c-adef-691d508d4ae1
parent c02e91a5
......@@ -958,13 +958,13 @@ $(CHECK_HOTINDEXER_UNDO_TESTS): %.run: %.test hotindexer-undo-do-test.tdb$(BINSU
./run-hotindexer-undo-do-tests.bash $< $(SUMMARIZE_CMD)
# blocking lock tree tests
BLOCKING_SRCS = $(wildcard blocking-*.c)
BLOCKING_SRCS = $(wildcard blocking-*.c db-put-*.c)
BLOCKING_TDB_TESTS = $(patsubst %.c,%.tdbrun,$(BLOCKING_SRCS))
BLOCKING_BDB_TESTS = $(patsubst %.c,%.bdbrun,$(BLOCKING_SRCS))
check_blocking_tdb: $(BLOCKING_TDB_TESTS)
check_blocking.tdbrun: $(BLOCKING_TDB_TESTS)
check_blocking_bdb: $(BLOCKING_BDB_TESTS)
check_blocking.bdbrun: $(BLOCKING_BDB_TESTS)
STRESS_TEST_SRCS = $(wildcard test_stress*.c)
STRESS_TESTS = $(patsubst %.c,%,$(STRESS_TEST_SRCS))
......
......@@ -189,7 +189,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#else
r = db_env->set_lk_detect(db_env, DB_LOCK_YOUNGEST); assert(r == 0);
#endif
......
......@@ -187,7 +187,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#else
r = db_env->set_lk_detect(db_env, DB_LOCK_YOUNGEST); assert(r == 0);
#endif
......
......@@ -143,7 +143,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#endif
// create the db
......
......@@ -160,7 +160,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#endif
// create the db
......
......@@ -160,7 +160,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#endif
// create the db
......
......@@ -229,7 +229,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#else
r = db_env->set_lk_detect(db_env, DB_LOCK_YOUNGEST); assert(r == 0);
#endif
......
......@@ -98,7 +98,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#endif
// create the db
......
......@@ -129,7 +129,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#endif
// create the db
......
......@@ -97,7 +97,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#endif
// create the db
......
......@@ -170,7 +170,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#endif
// create the db
......
......@@ -165,7 +165,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#endif
// create the db
......
......@@ -168,7 +168,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#endif
// create the db
......
......@@ -142,7 +142,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#endif
// create the db
......
......@@ -91,7 +91,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#endif
// create the db
......
// T(a) put 0
// T(b) put N-1
// T(a) put N-1, should wait on lock W(N-1)
// T(b) put 0, should return deadlock
// this test demonstrates that the lock manager can detect a simple deadlock with 2 transactions on 2 threads
// the threads do:
// T(a) put 0, grabs write lock on 0
// T(b) put N-1, grabs write lock on N-1
// T(a) put N-1, try's to grab write lock on N-1, should return lock not granted
// T(b) put 0, try's to grab write lock on 0, should return deadlock
// T(b) abort
// T(a) gets lock W(N-1)
// T(A) commit
......@@ -69,17 +71,12 @@ static void *run_txn_b(void *arg) {
insert_row(db, txn_b, htonl(n-1), n-1, 0);
test_seq_next_state(test_seq);
#if defined(USE_TDB)
test_seq_sleep(test_seq, 3);
insert_row(db, txn_b, htonl(0), 0, DB_LOCK_NOTGRANTED);
int r = txn_b->commit(txn_b, 0); assert(r == 0);
#elif defined(USE_BDB)
test_seq_sleep(test_seq, 2);
insert_row(db, txn_b, htonl(0), 0, DB_LOCK_DEADLOCK);
int r = txn_b->abort(txn_b); assert(r == 0);
#else
#error
#endif
test_seq_next_state(test_seq);
test_seq_sleep(test_seq, 5);
int r = txn_b->abort(txn_b); assert(r == 0);
return arg;
}
......@@ -100,15 +97,19 @@ static void simple_deadlock(DB_ENV *db_env, DB *db, int do_txn, int n) {
r = txn_init->commit(txn_init, 0); assert(r == 0);
}
uint32_t txn_flags = 0;
#if USE_BDB
txn_flags = DB_TXN_NOWAIT; // force no wait for BDB to avoid a bug described below
#endif
DB_TXN *txn_a = NULL;
if (do_txn) {
r = db_env->txn_begin(db_env, NULL, &txn_a, 0); assert(r == 0);
r = db_env->txn_begin(db_env, NULL, &txn_a, txn_flags); assert(r == 0);
}
DB_TXN *txn_b = NULL;
if (do_txn) {
r = db_env->txn_begin(db_env, NULL, &txn_b, 0); assert(r == 0);
r = db_env->txn_begin(db_env, NULL, &txn_b, txn_flags); assert(r == 0);
}
struct test_seq test_seq; test_seq_init(&test_seq);
......@@ -122,21 +123,18 @@ static void simple_deadlock(DB_ENV *db_env, DB *db, int do_txn, int n) {
test_seq_next_state(&test_seq);
test_seq_sleep(&test_seq, 2);
#if defined(USE_TDB)
// BDB does not time out this lock request, so the test hangs. it looks like a bug in bdb's __lock_get_internal.
insert_row(db, txn_a, htonl(n-1), n-1, DB_LOCK_NOTGRANTED);
#elif defined(USE_BDB)
insert_row(db, txn_a, htonl(n-1), n-1, 0);
#else
#error
#endif
test_seq_next_state(&test_seq);
void *ret = NULL;
r = toku_pthread_join(tid, &ret); assert(r == 0);
test_seq_sleep(&test_seq, 4);
if (do_txn) {
r = txn_a->commit(txn_a, 0); assert(r == 0);
r = txn_a->abort(txn_a); assert(r == 0);
}
test_seq_next_state(&test_seq);
void *ret = NULL;
r = toku_pthread_join(tid, &ret); assert(r == 0);
test_seq_destroy(&test_seq);
}
......@@ -190,9 +188,15 @@ int test_main(int argc, char * const argv[]) {
}
if (!do_txn)
db_env_open_flags &= ~(DB_INIT_TXN | DB_INIT_LOG);
#if USE_BDB
r = db_env->set_flags(db_env, DB_TIME_NOTGRANTED, 1); assert(r == 0); // force DB_LOCK_DEADLOCK to DB_LOCK_NOTGRANTED
#endif
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if defined(USE_BDB)
#if defined(USE_TDB)
r = db_env->set_lock_timeout(db_env, 0); assert(r == 0); // no wait
#elif defined(USE_BDB)
r = db_env->set_lk_detect(db_env, DB_LOCK_YOUNGEST); assert(r == 0);
r = db_env->set_timeout(db_env, 10000, DB_SET_LOCK_TIMEOUT); assert(r == 0);
#endif
// create the db
......
// this test demonstrates that a simple deadlock with 2 transactions on a single thread works with tokudb, hangs with bdb
#include "test.h"
static void insert_row(DB *db, DB_TXN *txn, int k, int v, int expect_r) {
......@@ -22,20 +24,28 @@ static void simple_deadlock(DB_ENV *db_env, DB *db, int do_txn, int n) {
r = txn_init->commit(txn_init, 0); assert(r == 0);
}
uint32_t txn_flags = 0;
#if USE_BDB
txn_flags = DB_TXN_NOWAIT; // force no wait for BDB to avoid a bug described below
#endif
DB_TXN *txn_a = NULL;
if (do_txn) {
r = db_env->txn_begin(db_env, NULL, &txn_a, 0); assert(r == 0);
r = db_env->txn_begin(db_env, NULL, &txn_a, txn_flags); assert(r == 0);
}
DB_TXN *txn_b = NULL;
if (do_txn) {
r = db_env->txn_begin(db_env, NULL, &txn_b, 0); assert(r == 0);
r = db_env->txn_begin(db_env, NULL, &txn_b, txn_flags); assert(r == 0);
}
insert_row(db, txn_a, htonl(0), 0, 0);
insert_row(db, txn_b, htonl(n-1), n-1, 0);
// if the txn_flags is 0, then BDB does not time out this lock request, so the test hangs. it looks like a bug in bdb's __lock_get_internal.
insert_row(db, txn_a, htonl(n-1), n-1, DB_LOCK_NOTGRANTED);
insert_row(db, txn_b, htonl(0), 0, DB_LOCK_NOTGRANTED);
if (do_txn) {
......@@ -48,7 +58,7 @@ int test_main(int argc, char * const argv[]) {
uint64_t cachesize = 0;
uint32_t pagesize = 0;
int do_txn = 1;
int nrows = 2;
int nrows = 1000; // for BDB, insert enough rows to create a tree with more than one page in it. this avoids a page locking conflict.
#if defined(USE_TDB)
char *db_env_dir = "dir." __FILE__ ".tokudb";
#elif defined(USE_BDB)
......@@ -93,11 +103,14 @@ int test_main(int argc, char * const argv[]) {
}
if (!do_txn)
db_env_open_flags &= ~(DB_INIT_TXN | DB_INIT_LOG);
#if USE_BDB
r = db_env->set_flags(db_env, DB_TIME_NOTGRANTED, 1); assert(r == 0); // force DB_LOCK_DEADLOCK to DB_LOCK_NOTGRANTED
#endif
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if defined(USE_BDB)
r = db_env->set_lk_detect(db_env, DB_LOCK_YOUNGEST); assert(r == 0);
r = db_env->set_timeout(db_env, 1000, DB_SET_LOCK_TIMEOUT); assert(r == 0);
#endif
// create the db
DB *db = NULL;
r = db_create(&db, db_env, 0); assert(r == 0);
......
......@@ -130,7 +130,7 @@ int test_main(int argc, char * const argv[]) {
db_env_open_flags &= ~(DB_INIT_TXN | DB_INIT_LOG);
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#else
r = db_env->set_lk_detect(db_env, DB_LOCK_YOUNGEST); assert(r == 0);
#endif
......
// for all i: T(i) reads 0, gets a read lock on 0
// for all i: T(i) writes 0, enters a deadlock
// run deadlock detector until forward progress is possible
// tokudb detects deadlock on the fly
// bdb detects deadlock on the fly or uses a deadlock detector
// --poll runs the deadlock detector until all the txns are resolved
#include "test.h"
#include "toku_pthread.h"
......@@ -168,7 +170,7 @@ int test_main(int argc, char * const argv[]) {
db_env_open_flags &= ~(DB_INIT_TXN | DB_INIT_LOG);
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if defined(TOKUDB)
r = db_env->set_lock_timeout(db_env, 30 * 1000000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
#endif
#if defined(USE_BDB)
if (!poll_deadlock) {
......
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