Commit a3462592 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

#4429 get test_set_lk_max_locks running on BDB 5.3 refs[t:4429]

git-svn-id: file:///svn/toku/tokudb@39193 c7de825b-a66e-492c-adef-691d508d4ae1
parent 5703873e
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
// ENVDIR is defined in the Makefile // ENVDIR is defined in the Makefile
#ifdef TOKUDB #if TOKUDB
#define EXTRA_LOCK_NEEDED 2 #define EXTRA_LOCK_NEEDED 2
#else #else
#define EXTRA_LOCK_NEEDED 0 #define EXTRA_LOCK_NEEDED 0
...@@ -31,34 +31,39 @@ static void make_db (int n_locks) { ...@@ -31,34 +31,39 @@ static void make_db (int n_locks) {
r = system("rm -rf " ENVDIR); r = system("rm -rf " ENVDIR);
CKERR(r); CKERR(r);
r=toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO); assert(r==0); r = toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO); assert(r == 0);
r=db_env_create(&env, 0); assert(r==0); r = db_env_create(&env, 0); assert(r == 0);
#ifdef TOKUDB #if TOKUDB
r = env->set_redzone(env, 0); assert(r == 0); r = env->set_redzone(env, 0); assert(r == 0);
#endif #endif
env->set_errfile(env, 0); env->set_errfile(env, 0);
if (n_locks>0) { if (n_locks>0) {
r=env->set_lk_max_locks(env, n_locks+EXTRA_LOCK_NEEDED); CKERR(r); #if !TOKUDB && DB_VERSION_MAJOR >= 5
// BDB configures lock partitons with the number of processors. We set the number of lock partitions to 1
// to override the default and get consistent locking behaviour on many machines.
r = env->set_lk_partitions(env, 1); CKERR(r);
#endif
r = env->set_lk_max_locks(env, n_locks+EXTRA_LOCK_NEEDED); CKERR(r);
/* test the get_lk_max_locks method */ /* test the get_lk_max_locks method */
#ifdef TOKUDB #if TOKUDB
// BDB cannot handle a NULL passed to get_lk_max_locks // BDB cannot handle a NULL passed to get_lk_max_locks
r=env->get_lk_max_locks(env, 0); r = env->get_lk_max_locks(env, 0);
assert(r == EINVAL); assert(r == EINVAL);
#endif #endif
r=env->get_lk_max_locks(env, &actual_n_locks); r = env->get_lk_max_locks(env, &actual_n_locks);
assert(r == 0 && actual_n_locks == (u_int32_t)n_locks+EXTRA_LOCK_NEEDED); assert(r == 0 && actual_n_locks == (u_int32_t)n_locks+EXTRA_LOCK_NEEDED);
} }
else { else {
r=env->get_lk_max_locks(env, &actual_n_locks); r = env->get_lk_max_locks(env, &actual_n_locks);
CKERR(r); CKERR(r);
} }
r=env->open(env, ENVDIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_CREATE|DB_PRIVATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r); r = env->open(env, ENVDIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_CREATE|DB_PRIVATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r=db_create(&db, env, 0); CKERR(r); r = db_create(&db, env, 0); CKERR(r);
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, "foo.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r); r = db->open(db, tid, "foo.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r=tid->commit(tid, 0); assert(r==0); r = tid->commit(tid, 0); assert(r == 0);
#ifndef TOKUDB #if !TOKUDB
u_int32_t pagesize; u_int32_t pagesize;
r = db->get_pagesize(db, &pagesize); CKERR(r); r = db->get_pagesize(db, &pagesize); CKERR(r);
u_int32_t datasize = pagesize/6; u_int32_t datasize = pagesize/6;
...@@ -68,7 +73,7 @@ static void make_db (int n_locks) { ...@@ -68,7 +73,7 @@ static void make_db (int n_locks) {
int effective_n_locks = (n_locks<0) ? (int)actual_n_locks-EXTRA_LOCK_NEEDED : n_locks; int effective_n_locks = (n_locks<0) ? (int)actual_n_locks-EXTRA_LOCK_NEEDED : n_locks;
// create even numbered keys 0 2 4 ... (effective_n_locks*32-2) // create even numbered keys 0 2 4 ... (effective_n_locks*32-2)
r=env->txn_begin(env, 0, &tid, 0); CKERR(r); r = env->txn_begin(env, 0, &tid, 0); CKERR(r);
for (i=0; i<effective_n_locks*16; i++) { for (i=0; i<effective_n_locks*16; i++) {
char hello[30], there[datasize+30]; char hello[30], there[datasize+30];
DBT key,data; DBT key,data;
...@@ -79,20 +84,20 @@ static void make_db (int n_locks) { ...@@ -79,20 +84,20 @@ static void make_db (int n_locks) {
key.data = hello; key.size=strlen(hello)+1; key.data = hello; key.size=strlen(hello)+1;
data.data = there; data.size=strlen(there)+1; data.data = there; data.size=strlen(there)+1;
if (i%50==49) { if (i%50==49) {
r=tid->commit(tid, 0); CKERR(r); r = tid->commit(tid, 0); CKERR(r);
r=env->txn_begin(env, 0, &tid, 0); CKERR(r); r = env->txn_begin(env, 0, &tid, 0); CKERR(r);
} }
r=db->put(db, tid, &key, &data, 0); CKERR(r); r = db->put(db, tid, &key, &data, 0); CKERR(r);
} }
r=tid->commit(tid, 0); CKERR(r); r = tid->commit(tid, 0); CKERR(r);
// Now using two different transactions have one transaction create keys // Now using two different transactions have one transaction create keys
// 1 17 33 ... (1 mod 16) // 1 17 33 ... (1 mod 16)
// and another do // and another do
// 9 25 41 ... (9 mod 16) // 9 25 41 ... (9 mod 16)
r=env->txn_begin(env, 0, &tid, 0); CKERR(r); r = env->txn_begin(env, 0, &tid, 0); CKERR(r);
r=env->txn_begin(env, 0, &tid2, 0); CKERR(r); r = env->txn_begin(env, 0, &tid2, 0); CKERR(r);
for (i=0; i<effective_n_locks*2; i++) { for (i=0; i<effective_n_locks*2; i++) {
int j; int j;
...@@ -107,19 +112,20 @@ static void make_db (int n_locks) { ...@@ -107,19 +112,20 @@ static void make_db (int n_locks) {
//printf("Writing %s in %d\n", hello, j); //printf("Writing %s in %d\n", hello, j);
key.data = hello; key.size=strlen(hello)+1; key.data = hello; key.size=strlen(hello)+1;
data.data = there; data.size=strlen(there)+1; data.data = there; data.size=strlen(there)+1;
r=db->put(db, j==0 ? tid : tid2, &key, &data, 0); r = db->put(db, j==0 ? tid : tid2, &key, &data, 0);
#ifdef TOKUDB #if TOKUDB
// Lock escalation cannot help here: We require too many locks because we are alternating between tid and tid2 // Lock escalation cannot help here: We require too many locks because we are alternating between tid and tid2
if (i*2+j<effective_n_locks) { if (i*2+j<effective_n_locks) {
CKERR(r); CKERR(r);
} else CKERR2(r, TOKUDB_OUT_OF_LOCKS); } else CKERR2(r, TOKUDB_OUT_OF_LOCKS);
#else #else
if (verbose) printf("%d %d %d\n", i, j, r);
#if DB_VERSION_MAJOR >= 5 #if DB_VERSION_MAJOR >= 5
if (i*2+j+1<effective_n_locks) { if (i*2+j+1<effective_n_locks) {
#else #else
if (i*2+j+2<effective_n_locks) { if (i*2+j+2<effective_n_locks) {
#endif #endif
if (r!=0) printf("r=%d on i=%d j=%d eff=%d\n", r, i, j, effective_n_locks); if (r!=0) printf("r = %d on i=%d j=%d eff=%d\n", r, i, j, effective_n_locks);
CKERR(r); CKERR(r);
} else { } else {
CKERR2(r, ENOMEM); CKERR2(r, ENOMEM);
...@@ -127,14 +133,15 @@ static void make_db (int n_locks) { ...@@ -127,14 +133,15 @@ static void make_db (int n_locks) {
#endif #endif
} }
} }
r=tid->commit(tid2, 0); assert(r==0); r = tid->commit(tid2, 0); assert(r == 0);
r=tid->commit(tid, 0); assert(r==0); r = tid->commit(tid, 0); assert(r == 0);
r=db->close(db, 0); assert(r==0); r = db->close(db, 0); assert(r == 0);
r=env->close(env, 0); assert(r==0); r = env->close(env, 0); assert(r == 0);
} }
int int
test_main (int argc __attribute__((__unused__)), char *const argv[] __attribute__((__unused__))) { test_main (int argc, char * const argv[]) {
parse_args(argc, argv);
make_db(100); make_db(100);
make_db(1000); make_db(1000);
if (0) { if (0) {
......
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