Commit a30a89e7 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Make DB_ENV->set_lk_max_locks work. And test it. Fixes #366.

git-svn-id: file:///svn/tokudb@2205 c7de825b-a66e-492c-adef-691d508d4ae1
parent 3356090e
...@@ -25,6 +25,7 @@ static void make_db (void) { ...@@ -25,6 +25,7 @@ static void make_db (void) {
system("rm -rf " DIR); system("rm -rf " DIR);
r=mkdir(DIR, 0777); assert(r==0); r=mkdir(DIR, 0777); assert(r==0);
r=db_env_create(&env, 0); assert(r==0); r=db_env_create(&env, 0); assert(r==0);
r=env->set_lk_max_locks(env, 30000); CKERR(r);
r=env->open(env, DIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_CREATE|DB_PRIVATE, 0777); CKERR(r); r=env->open(env, DIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_CREATE|DB_PRIVATE, 0777); 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);
...@@ -41,7 +42,7 @@ static void make_db (void) { ...@@ -41,7 +42,7 @@ static void make_db (void) {
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
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, tid, &key, &data, 0); assert(r==0); r=db->put(db, tid, &key, &data, 0); CKERR(r);
} }
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);
......
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
/* Test to see if the set_lk_max_locks works. */
/* This is very specific to TokuDB. It won't work with Berkeley DB. */
#include <assert.h>
#include <db.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
// DIR is defined in the Makefile
#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
static void make_db (int n_locks) {
DB_ENV *env;
DB *db;
DB_TXN *tid;
int r;
int i;
system("rm -rf " DIR);
r=mkdir(DIR, 0777); assert(r==0);
r=db_env_create(&env, 0); assert(r==0);
if (n_locks>0)
r=env->set_lk_max_locks(env, n_locks); CKERR(r);
r=env->open(env, DIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_CREATE|DB_PRIVATE, 0777); CKERR(r);
r=db_create(&db, env, 0); CKERR(r);
r=env->txn_begin(env, 0, &tid, 0); assert(r==0);
r=db->open(db, tid, "foo.db", 0, DB_BTREE, DB_CREATE, 0777); CKERR(r);
r=tid->commit(tid, 0); assert(r==0);
r=env->txn_begin(env, 0, &tid, 0); assert(r==0);
int effective_n_locks = (n_locks<0) ? 1000 : n_locks;
for (i=0; i<20000; i++) {
char hello[30], there[30];
DBT key,data;
snprintf(hello, sizeof(hello), "hello%ld.%d", random(), i);
snprintf(there, sizeof(hello), "there%d", i);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data = hello; key.size=strlen(hello)+1;
data.data = there; data.size=strlen(there)+1;
r=db->put(db, tid, &key, &data, 0);
if (effective_n_locks<=i) {
assert(r==ENOMEM);
break;
} else {
assert(r==0);
}
}
r=tid->commit(tid, 0); assert(r==0);
r=db->close(db, 0); assert(r==0);
r=env->close(env, 0); assert(r==0);
}
int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
make_db(-1);
make_db(1000);
make_db(30000);
return 0;
}
...@@ -566,6 +566,29 @@ static int locked_env_set_lk_max(DB_ENV * env, u_int32_t lk_max) { ...@@ -566,6 +566,29 @@ static int locked_env_set_lk_max(DB_ENV * env, u_int32_t lk_max) {
} }
#endif #endif
static int toku_env_set_lk_max_locks(DB_ENV *dbenv, u_int32_t max) {
HANDLE_PANICKED_ENV(dbenv);
if (env_opened(dbenv)) return EINVAL;
if (!max) return EINVAL;
dbenv->i->max_locks = max;
return 0;
}
static int toku_env_get_lk_max_locks(DB_ENV *dbenv, u_int32_t *lk_maxp) {
HANDLE_PANICKED_ENV(dbenv);
if (!lk_maxp) return EINVAL;
*lk_maxp = dbenv->i->max_locks;
return 0;
}
static int locked_env_set_lk_max_locks(DB_ENV *dbenv, u_int32_t max) {
ydb_lock(); int r = toku_env_set_lk_max_locks(dbenv, max); ydb_unlock(); return r;
}
static int __attribute__((unused)) locked_env_get_lk_max_locks(DB_ENV *dbenv, u_int32_t *lk_maxp) {
ydb_lock(); int r = toku_env_get_lk_max_locks(dbenv, lk_maxp); ydb_unlock(); return r;
}
//void __toku_env_set_noticecall (DB_ENV *env, void (*noticecall)(DB_ENV *, db_notices)) { //void __toku_env_set_noticecall (DB_ENV *env, void (*noticecall)(DB_ENV *, db_notices)) {
// env->i->noticecall = noticecall; // env->i->noticecall = noticecall;
//} //}
...@@ -612,7 +635,6 @@ void toku_default_errcall(const DB_ENV *env, const char *errpfx, const char *msg ...@@ -612,7 +635,6 @@ void toku_default_errcall(const DB_ENV *env, const char *errpfx, const char *msg
#if _THREAD_SAFE #if _THREAD_SAFE
static void locked_env_err(const DB_ENV * env, int error, const char *fmt, ...) static void locked_env_err(const DB_ENV * env, int error, const char *fmt, ...)
__attribute__((__format__(__printf__, 3, 4))); __attribute__((__format__(__printf__, 3, 4)));
...@@ -711,6 +733,7 @@ static int toku_env_create(DB_ENV ** envp, u_int32_t flags) { ...@@ -711,6 +733,7 @@ static int toku_env_create(DB_ENV ** envp, u_int32_t flags) {
result->set_lg_bsize = locked_env_set_lg_bsize; result->set_lg_bsize = locked_env_set_lg_bsize;
result->set_lg_dir = locked_env_set_lg_dir; result->set_lg_dir = locked_env_set_lg_dir;
result->set_lg_max = locked_env_set_lg_max; result->set_lg_max = locked_env_set_lg_max;
result->set_lk_max_locks = locked_env_set_lk_max_locks;
result->set_cachesize = locked_env_set_cachesize; result->set_cachesize = locked_env_set_cachesize;
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3 #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3
result->get_cachesize = locked_env_get_cachesize; result->get_cachesize = locked_env_get_cachesize;
...@@ -1781,22 +1804,6 @@ static int find_db_file(DB_ENV* dbenv, const char *fname, char** full_name_out) ...@@ -1781,22 +1804,6 @@ static int find_db_file(DB_ENV* dbenv, const char *fname, char** full_name_out)
return 0; return 0;
} }
static int toku_env_set_lk_max_locks(DB_ENV *dbenv, u_int32_t max) {
HANDLE_PANICKED_ENV(dbenv);
if (env_opened(dbenv)) return EINVAL;
if (!max) return EINVAL;
dbenv->i->max_locks = max;
return 0;
}
static int toku_env_get_lk_max_locks(DB_ENV *dbenv, u_int32_t *lk_maxp) {
HANDLE_PANICKED_ENV(dbenv);
if (!lk_maxp) return EINVAL;
*lk_maxp = dbenv->i->max_locks;
return 0;
}
static int toku_db_lt_panic(DB* db, int r) { static int toku_db_lt_panic(DB* db, int r) {
assert(db && db->i && db->dbenv && db->dbenv->i); assert(db && db->i && db->dbenv && db->dbenv->i);
DB_ENV* env = db->dbenv; DB_ENV* env = db->dbenv;
...@@ -2140,14 +2147,6 @@ static int toku_db_fd(DB *db, int *fdp) { ...@@ -2140,14 +2147,6 @@ static int toku_db_fd(DB *db, int *fdp) {
#if _THREAD_SAFE #if _THREAD_SAFE
static int __attribute__((unused)) locked_env_set_lk_max_locks(DB_ENV *dbenv, u_int32_t max) {
ydb_lock(); int r = toku_env_set_lk_max_locks(dbenv, max); ydb_unlock(); return r;
}
static int __attribute__((unused)) locked_env_get_lk_max_locks(DB_ENV *dbenv, u_int32_t *lk_maxp) {
ydb_lock(); int r = toku_env_get_lk_max_locks(dbenv, lk_maxp); ydb_unlock(); return r;
}
static int locked_db_associate (DB *primary, DB_TXN *txn, DB *secondary, static int locked_db_associate (DB *primary, DB_TXN *txn, DB *secondary,
int (*callback)(DB *secondary, const DBT *key, const DBT *data, DBT *result), u_int32_t flags) { int (*callback)(DB *secondary, const DBT *key, const DBT *data, DBT *result), u_int32_t flags) {
ydb_lock(); int r = toku_db_associate(primary, txn, secondary, callback, flags); ydb_unlock(); return r; ydb_lock(); int r = toku_db_associate(primary, txn, secondary, callback, flags); ydb_unlock(); return r;
......
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