git-svn-id: file:///svn/toku/tokudb@11914 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
Bradley C. Kuszmaul 2013-04-16 23:57:52 -04:00 committed by Yoni Fogel
parent 64874ce9bc
commit 02d6a37e3b
6 changed files with 62 additions and 5 deletions

View file

@ -24,7 +24,7 @@ The name of the environment's directory if non-\fBNULL\fR. Can be
either a relative pathame (relative to the current working directory),
or an absolute pathname.
if \fidb_home\fR is \fBNULL\fR and the \fBDB_USE_ENVIRON\fR or \fBDB_USE_ENVIRON_ROOT\fB flag is set, then the value of the
If \fidb_home\fR is \fBNULL\fR and the \fBDB_USE_ENVIRON\fR or \fBDB_USE_ENVIRON_ROOT\fB flag is set, then the value of the
\fBDB_HOME\fR environment variable is used.
.IP \fIflags
@ -42,6 +42,7 @@ The \fIflags\fR parameter must be set to 0 or the bitwise or of one or more of t
.IP \fBDB_PRIVATE
.IP \fBDB_THREAD
If \fBDB_THREAD\fR is specified, then \fBDB_CREATE\fR must also be specified, even if the environment already exists. This restriction is in place in Berkeley DB 4.6 and 4.7, and so TokuDB also enforces it for compatibility.
.SH RETURN VALUE
.LP

View file

@ -35,7 +35,7 @@ void do_1381_maybe_lock (int do_table_lock, u_int64_t *raw_count) {
{
DB_ENV *env;
DB *db;
const int envflags = DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOCK|DB_INIT_LOG |DB_THREAD |DB_PRIVATE;
const int envflags = DB_CREATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOCK|DB_INIT_LOG |DB_THREAD |DB_PRIVATE;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);

52
src/tests/test1753.c Normal file
View file

@ -0,0 +1,52 @@
#include <db.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <assert.h>
#include "test.h"
DB_TXN *null_txn=0;
void do_test1753 (int do_create_on_reopen) {
system("rm -rf " ENVDIR);
toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
int r;
// Create an empty file
{
DB_ENV *env;
DB *db;
const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_PRIVATE ;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = db_create(&db, env, 0); CKERR(r);
r = db->open(db, null_txn, "main", 0, DB_BTREE, DB_CREATE, 0666); CKERR(r);
r = db->close(db, 0); CKERR(r);
r = env->close(env, 0); CKERR(r);
}
// Now open the empty file and insert
{
DB_ENV *env;
int envflags = DB_INIT_MPOOL| DB_THREAD |DB_PRIVATE;
if (do_create_on_reopen) envflags |= DB_CREATE;
r = db_env_create(&env, 0); CKERR(r);
env->set_errfile(env, 0);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO);
if (do_create_on_reopen) CKERR(r);
else CKERR2(r, ENOENT);
r = env->close(env, 0); CKERR(r);
}
}
int test_main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
do_test1753(1);
do_test1753(0);
return 0;
}

View file

@ -35,7 +35,7 @@ test_main(int argc, char *argv[]) {
#else
if (do_private==1) continue; // See #530. BDB 4.6.21 segfaults if DB_PRIVATE is passed when no environment previously exists.
#endif
int private_flags = do_private ? DB_PRIVATE : 0;
int private_flags = do_private ? (DB_CREATE|DB_PRIVATE) : 0;
system("rm -rf " ENVDIR);
r = db_env_create(&dbenv, 0);

View file

@ -24,7 +24,7 @@ test_main (int UU(argc), char UU(*argv[])) {
// None of this stuff works with BDB. TDB does more error checking.
#ifdef USE_TDB
r=env->set_data_dir(env, NULL); assert(r==EINVAL);
r=env->open(env, ENVDIR, DB_PRIVATE, S_IRWXU+S_IRWXG+S_IRWXO); assert(r==0);
r=env->open(env, ENVDIR, DB_CREATE|DB_PRIVATE, S_IRWXU+S_IRWXG+S_IRWXO); assert(r==0);
env->set_errpfx(env, NULL); assert(1); //Did not crash.
r=env->set_tmp_dir(env, NULL); assert(r==EINVAL);
#endif

View file

@ -344,6 +344,10 @@ static int toku_env_open(DB_ENV * env, const char *home, u_int32_t flags, int mo
return toku_ydb_do_error(env, EINVAL, "DB_USE_ENVIRON and DB_USE_ENVIRON_ROOT are incompatible flags\n");
}
if ((flags & DB_PRIVATE) && !(flags & DB_CREATE)) {
return toku_ydb_do_error(env, ENOENT, "DB_PRIVATE requires DB_CREATE (seems gratuitous to us, but that's BDB's behavior\n");
}
if (home) {
if ((flags & DB_USE_ENVIRON) || (flags & DB_USE_ENVIRON_ROOT)) {
return toku_ydb_do_error(env, EINVAL, "DB_USE_ENVIRON and DB_USE_ENVIRON_ROOT are incompatible with specifying a home\n");
@ -3673,7 +3677,7 @@ static int toku_db_create(DB ** db, DB_ENV * env, u_int32_t flags) {
r = toku_env_create(&env, 0);
if (r != 0)
return r;
r = toku_env_open(env, ".", DB_PRIVATE + DB_INIT_MPOOL, 0);
r = toku_env_open(env, ".", DB_CREATE | DB_PRIVATE | DB_INIT_MPOOL, 0);
if (r != 0) {
env_unref(env);
return r;