Commit 6054331d authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

Fixes #2851. (cxx tests now work concurrently). close[t:2851]

git-svn-id: file:///svn/toku/tokudb@22727 c7de825b-a66e-492c-adef-691d508d4ae1
parent f0b4f4b7
......@@ -53,6 +53,11 @@ int DbEnv::set_cachesize(u_int32_t gbytes, u_int32_t bytes, int ncache) {
return maybe_throw_error(ret);
}
int DbEnv::set_redzone(u_int32_t percent) {
int ret = the_env->set_redzone(the_env, percent);
return maybe_throw_error(ret);
}
int DbEnv::set_flags(u_int32_t flags, int onoff) {
int ret = the_env->set_flags(the_env, flags, onoff);
return maybe_throw_error(ret);
......
......@@ -88,18 +88,19 @@ check_test_error_stream: test_error_stream
$(VGRIND) ./test_error_stream 2> $@.out $(SUMMARIZE_CMD)
check_test1e: test1e
$(VGRIND) ./test1e > test1eactual.out
$(VGRIND) ./test1e > test1eactual.out && \
(echo "Prefix: Hello Name!";echo -n ": Success") > test1expect.out
diff test1eactual.out test1expect.out \
$(SUMMARIZE_CMD)
check_create_dump_diff: db_create db_dump db_dump_e
rm -f cdd.tdb cdd.tdb.dirty cdd.tdb.clean
$(VGRIND) ./db_create cdd.tdb a b c d && \
$(VGRIND) ./db_dump cdd.tdb > cdd.out && \
rm -rf $@.dir
mkdir $@.dir
$(VGRIND) ./db_create --env_dir $@.dir cdd.tdb a b c d && \
$(VGRIND) ./db_dump --env_dir $@.dir cdd.tdb > cdd.out && \
(echo " 61";echo " 62";echo " 63";echo " 64")>cddexpect.out && \
diff cdd.out cddexpect.out && \
$(VGRIND) ./db_dump_e cdd.tdb > cdd.out && \
$(VGRIND) ./db_dump_e --env_dir $@.dir cdd.tdb > cdd.out && \
diff cdd.out cddexpect.out \
$(SUMMARIZE_CMD)
......@@ -133,12 +134,15 @@ check_exceptions: exceptions
$(VGRIND) ./exceptions $(MAYBEINVERTER) $(SUMMARIZE_CMD)
check_db_create: db_create
rm -rf $@.tdb
$(VGRIND) ./db_create -s main $@.tdb $(SUMMARIZE_CMD)
rm -rf $@.dir
mkdir $@.dir
$(VGRIND) ./db_create --env_dir $@.dir -s main $@.tdb $(SUMMARIZE_CMD)
check_db_create_DSM: db_create
rm -rf $@.tdb
$(VGRIND) ./db_create -D -S -s main $@.tdb $(SUMMARIZE_CMD)
rm -rf $@.dir
mkdir $@.dir
$(VGRIND) ./db_create --env_dir $@.dir -D -S -s main $@.tdb $(SUMMARIZE_CMD)
# These don't need to set the env dir
check_db_create_1: db_create
$(VGRIND) ./db_create &> $@.out ; test $$? -ne 0 $(SUMMARIZE_CMD)
check_db_create_2: db_create
......@@ -148,9 +152,9 @@ check_db_create_3: db_create
check_db_create_4: db_create
$(VGRIND) ./db_create -s &> $@.out ; test $$? -ne 0 $(SUMMARIZE_CMD)
check_permissions:
rm -f permissions_tdb_*.tokudb && \
./db_create permissions.tdb 1 1 && \
chmod -w permissions_tdb_*.tokudb && \
(./db_create permissions.tdb 2 2 &> check_permissions.out 2>&1 ; test $$? -ne 0) \
check_permissions: db_create
rm -rf $@.dir && mkdir $@.dir && \
./db_create --env_dir $@.dir permissions.tdb 1 1 && \
chmod -w $@.dir/*.tokudb && \
(./db_create --env_dir $@.dir permissions.tdb 2 2 &> check_permissions.out 2>&1 ; test $$? -ne 0) \
$(SUMMARIZE_CMD)
......@@ -5,7 +5,7 @@
#define DB_YESOVERWRITE 0
#endif
char *data_dir;
char *data_dir, *env_dir=NULL;
static int dbcreate(char *dbfile, char *dbname, int dbflags, int argc, char *argv[]) {
int r;
......@@ -13,7 +13,8 @@ static int dbcreate(char *dbfile, char *dbname, int dbflags, int argc, char *arg
if (data_dir) {
r = env->set_data_dir(data_dir); assert(r == 0);
}
r = env->open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
r = env->set_redzone(0); assert(r==0);
r = env->open(env_dir ? env_dir : ".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db *db = new Db(env, DB_CXX_NO_EXCEPTIONS);
r = db->set_flags(dbflags); assert(r == 0);
......@@ -72,12 +73,22 @@ int main(int argc, char *argv[]) {
dbflags += DB_DUPSORT;
continue;
}
if (0 == strcmp(arg, "--env_dir")) {
if (i+1 >= argc)
return usage();
env_dir = argv[++i];
continue;
}
if (0 == strcmp(arg, "--set_data_dir")) {
if (i+1 >= argc)
return usage();
data_dir = argv[++i];
continue;
}
if (arg[0]=='-') {
printf("I don't understand this argument: %s\n", arg);
return 1;
}
break;
}
......
......@@ -12,12 +12,13 @@ static void hexdump(Dbt *d) {
printf("\n");
}
static int dbdump(char *dbfile, char *dbname) {
static int dbdump(const char *env_dir, const char *dbfile, const char *dbname) {
int r;
#if defined(USE_ENV) && USE_ENV
DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
r = env.set_redzone(0); assert(r==0);
r = env.open(env_dir, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, DB_CXX_NO_EXCEPTIONS);
#else
Db db(0, DB_CXX_NO_EXCEPTIONS);
......@@ -72,12 +73,13 @@ static int usage() {
return 1;
}
int main(int argc, char *argv[]) {
char *dbname = 0;
int main(int argc, const char *argv[]) {
const char *dbname = 0;
const char *env_dir = ".";
int i;
for (i=1; i<argc; i++) {
char *arg = argv[i];
const char *arg = argv[i];
if (0 == strcmp(arg, "-h") || 0 == strcmp(arg, "--help"))
return usage();
if (0 == strcmp(arg, "-s")) {
......@@ -86,11 +88,17 @@ int main(int argc, char *argv[]) {
dbname = argv[++i];
continue;
}
if (0 == strcmp(arg, "--env_dir")) {
if (i+1 >= argc)
return usage();
env_dir = argv[++i];
continue;
}
break;
}
if (i >= argc)
return usage();
return dbdump(argv[i], dbname);
return dbdump(env_dir, argv[i], dbname);
}
......@@ -13,12 +13,13 @@ static void hexdump(Dbt *d) {
printf("\n");
}
static int dbdump(char *dbfile, char *dbname) {
static int dbdump(const char *env_dir, const char *dbfile, const char *dbname) {
int r;
#if defined(USE_ENV) && USE_ENV
DbEnv env(0);
r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
r = env.set_redzone(0); assert(r==0);
r = env.open(env_dir, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, 0);
#else
Db db(0, 0);
......@@ -71,9 +72,10 @@ static int usage() {
int main(int argc, char *argv[]) {
int i;
char *dbname = 0;
const char *env_dir = ".";
const char *dbname = 0;
for (i=1; i<argc; i++) {
char *arg = argv[i];
const char *arg = argv[i];
if (0 == strcmp(arg, "-h") || 0 == strcmp(arg, "--help"))
return usage();
if (0 == strcmp(arg, "-s")) {
......@@ -83,11 +85,17 @@ int main(int argc, char *argv[]) {
dbname = argv[i];
continue;
}
if (0 == strcmp(arg, "--env_dir")) {
if (i+1 >= argc)
return usage();
env_dir = argv[++i];
continue;
}
break;
}
if (i >= argc)
return usage();
return dbdump(argv[i], dbname);
return dbdump(env_dir, argv[i], dbname);
}
......@@ -50,12 +50,12 @@ static int hexload(Dbt *d) {
return 1;
}
static int dbload(char *dbfile, char *dbname) {
static int dbload(const char *envdir, const char *dbfile, const char *dbname) {
int r;
#if defined(USE_ENV) && USE_ENV
DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
r = env.open(envdir, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, DB_CXX_NO_EXCEPTIONS);
#else
Db db(0, DB_CXX_NO_EXCEPTIONS);
......@@ -93,12 +93,13 @@ static int usage() {
return 1;
}
int main(int argc, char *argv[]) {
int main(int argc, const char *argv[]) {
int i;
char *dbname = 0;
const char *dbname = 0;
const char *env_dir = ".";
for (i=1; i<argc; i++) {
char *arg = argv[i];
const char *arg = argv[i];
if (0 == strcmp(arg, "-h") || 0 == strcmp(arg, "--help"))
return usage();
if (0 == strcmp(arg, "-s")) {
......@@ -108,11 +109,17 @@ int main(int argc, char *argv[]) {
dbname = argv[i];
continue;
}
if (0 == strcmp(arg, "--env_dir")) {
if (i+1 >= argc)
return usage();
env_dir = argv[++i];
continue;
}
break;
}
if (i >= argc)
return usage();
return dbload(argv[i], dbname);
return dbload(env_dir, argv[i], dbname);
}
......@@ -42,16 +42,19 @@ int verbose = 0;
static void test_env_exceptions (void) {
{
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR "no.such.dir", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0777), ENOENT);
}
{
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR "no.such.dir", -1, 0777), EINVAL);
}
{
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0777), 0);
DbTxn *txn;
TC(env.txn_begin(0, &txn, 0), EINVAL); // not configured for transactions
......@@ -60,12 +63,14 @@ static void test_env_exceptions (void) {
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE | DB_INIT_LOG, 0777), EINVAL); // cannot do logging without txns
}
{
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE | DB_INIT_LOG | DB_INIT_TXN, 0777), 0);
DbTxn *txn;
TC(env.txn_begin(0, &txn, 0), 0);
......@@ -77,6 +82,7 @@ static void test_env_exceptions (void) {
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
env.set_errfile(stderr);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE | DB_INIT_LOG | DB_INIT_LOCK | DB_INIT_TXN, 0777), 0);
DbTxn *txn;
TC(env.txn_begin(0, &txn, 0), 0);
......@@ -87,6 +93,7 @@ static void test_env_exceptions (void) {
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE | DB_INIT_LOG | DB_INIT_TXN, 0777), 0);
DbTxn *txn;
TC(env.txn_begin(0, &txn, 0), 0);
......@@ -101,6 +108,7 @@ static void test_db_exceptions (void) {
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE , 0777), 0);
env.set_errfile(stderr);
TC( ({ Db db(&env, -1); assert(0); }), EINVAL); // Create with flags=-1 should do an EINVAL
......
#include <db_cxx.h>
#include <errno.h>
#include <assert.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <iostream>
using namespace std;
......@@ -29,7 +30,8 @@ int cmp(DB *db, const DBT *dbt1, const DBT *dbt2) {
void test_db(void) {
DbEnv env(DB_CXX_NO_EXCEPTIONS);
int r = env.open(NULL, DB_CREATE|DB_PRIVATE, 0666);
{ int r = env.set_redzone(0); assert(r==0); }
int r = env.open("test1.dir", DB_CREATE|DB_PRIVATE, 0666);
assert(r==0);
Db db(&env, 0);
......@@ -41,6 +43,8 @@ void test_db(void) {
int main()
{
system("rm -rf test1.dir");
mkdir("test1.dir", 0777);
test_dbt();
test_db();
return 0;
......
......@@ -2,6 +2,7 @@
#include <errno.h>
#include <assert.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <iostream>
using namespace std;
......@@ -10,9 +11,14 @@ int cmp(DB *db, const DBT *dbt1, const DBT *dbt2) {
return 0;
}
#define DIR "test1e.dir"
void test_db(void) {
system("rm -rf " DIR);
mkdir(DIR, 0777);
DbEnv env(0);
env.open(NULL, DB_CREATE|DB_PRIVATE, 0666);
{ int r = env.set_redzone(0); assert(r==0); }
env.open(DIR, DB_CREATE|DB_PRIVATE, 0666);
Db db(&env, 0);
int r;
......
......@@ -5,6 +5,7 @@
#include <assert.h>
#include <db_cxx.h>
#include <memory.h>
#include <sys/stat.h>
int verbose;
......@@ -325,6 +326,8 @@ void test_next_dup(Db *db, int n) {
r = cursor->close(); assert(r == 0);
}
#define DIR "test_cursor_count.dir"
int main(int argc, char *argv[]) {
for (int i=1; i<argc; i++) {
char *arg = argv[i];
......@@ -334,9 +337,13 @@ int main(int argc, char *argv[]) {
int r;
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
#if defined(USE_ENV) && USE_ENV
DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
r = env.set_redzone(0); assert(r==0);
r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, DB_CXX_NO_EXCEPTIONS);
#else
Db db(0, DB_CXX_NO_EXCEPTIONS);
......
......@@ -11,6 +11,7 @@ void test_new_delete() {
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
{ int r = env.set_redzone(0); assert(r==0); }
{ int r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0); }
Db *db = new Db(&env, 0); assert(db != 0);
delete db;
......@@ -20,6 +21,7 @@ void test_new_open_delete() {
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
{ int r = env.set_redzone(0); assert(r==0); }
{ int r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0); }
Db *db = new Db(&env, 0); assert(db != 0);
{ int r = db->open(NULL, FNAME, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0); }
......
......@@ -42,7 +42,8 @@ void reset_env (void) {
toku_os_mkdir(DIR, 0777);
if (env) delete env;
env = new DbEnv(DB_CXX_NO_EXCEPTIONS);
int r = env->open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777);
{ int r = env->set_redzone(0); assert(r==0); }
int r = env->open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777);
assert(r == 0);
}
......
......@@ -68,6 +68,7 @@ void test_reverse_compare(int n, int dup_flags) {
/* create the dup database file */
DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.set_redzone(0); assert(r==0);
r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
db = new Db(&env, DB_CXX_NO_EXCEPTIONS);
assert(db);
......
......@@ -160,6 +160,7 @@ class DbEnv {
int close(u_int32_t);
int open(const char *, u_int32_t, int);
int set_cachesize(u_int32_t, u_int32_t, int);
int set_redzone(u_int32_t);
int set_flags(u_int32_t, int);
int txn_begin(DbTxn *, DbTxn **, u_int32_t);
int set_data_dir(const char *dir);
......
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