mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 14:54:20 +01:00
Modified tokudb to work with test_db_already_exists
git-svn-id: file:///svn/tokudb@643 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
parent
ee3d071c03
commit
f978d2859e
7 changed files with 49 additions and 20 deletions
|
@ -9,9 +9,9 @@ extern "C" {
|
|||
#endif
|
||||
#define DB_VERSION_MAJOR 4
|
||||
#define DB_VERSION_MINOR 1
|
||||
#define DB_VERSION_PATCH 25
|
||||
#define DB_VERSION_PATCH 24
|
||||
#ifndef _TOKUDB_WRAP_H
|
||||
#define DB_VERSION_STRING "Tokutek: TokuDB 4.1.25"
|
||||
#define DB_VERSION_STRING "Tokutek: TokuDB 4.1.24"
|
||||
#else
|
||||
#define DB_VERSION_STRING_ydb "Tokutek: TokuDB (wrapped bdb)"
|
||||
#endif
|
||||
|
@ -40,6 +40,7 @@ typedef enum {
|
|||
#define DB_ARCH_ABS 1
|
||||
#define DB_ARCH_LOG 4
|
||||
#define DB_CREATE 1
|
||||
#define DB_EXCL 2048
|
||||
#define DB_PRIVATE 262144
|
||||
#define DB_RDONLY 16
|
||||
#define DB_RECOVER 32
|
||||
|
|
|
@ -39,6 +39,7 @@ void print_defines (void) {
|
|||
dodefine(DB_ARCH_LOG);
|
||||
|
||||
dodefine(DB_CREATE);
|
||||
dodefine(DB_EXCL);
|
||||
dodefine(DB_PRIVATE);
|
||||
dodefine(DB_RDONLY);
|
||||
dodefine(DB_RECOVER);
|
||||
|
|
|
@ -9,9 +9,9 @@ extern "C" {
|
|||
#endif
|
||||
#define DB_VERSION_MAJOR 4
|
||||
#define DB_VERSION_MINOR 1
|
||||
#define DB_VERSION_PATCH 25
|
||||
#define DB_VERSION_PATCH 24
|
||||
#ifndef _TOKUDB_WRAP_H
|
||||
#define DB_VERSION_STRING "Tokutek: TokuDB 4.1.25"
|
||||
#define DB_VERSION_STRING "Tokutek: TokuDB 4.1.24"
|
||||
#else
|
||||
#define DB_VERSION_STRING_ydb "Tokutek: TokuDB (wrapped bdb)"
|
||||
#endif
|
||||
|
@ -40,6 +40,7 @@ typedef enum {
|
|||
#define DB_ARCH_ABS 1
|
||||
#define DB_ARCH_LOG 4
|
||||
#define DB_CREATE 1
|
||||
#define DB_EXCL 2048
|
||||
#define DB_PRIVATE 262144
|
||||
#define DB_RDONLY 16
|
||||
#define DB_RECOVER 32
|
||||
|
|
14
newbrt/brt.c
14
newbrt/brt.c
|
@ -1497,7 +1497,7 @@ int brt_set_dup_compare(BRT brt, int (*dup_compare)(DB *, const DBT*, const DBT*
|
|||
return 0;
|
||||
}
|
||||
|
||||
int brt_open(BRT t, const char *fname, const char *dbname, int is_create, CACHETABLE cachetable, TOKUTXN txn __attribute__((__unused__))) {
|
||||
int brt_open(BRT t, const char *fname, const char *dbname, int is_create, int only_create, CACHETABLE cachetable, TOKUTXN txn __attribute__((__unused__))) {
|
||||
|
||||
/* If dbname is NULL then we setup to hold a single tree. Otherwise we setup an array. */
|
||||
int r;
|
||||
|
@ -1507,6 +1507,7 @@ int brt_open(BRT t, const char *fname, const char *dbname, int is_create, CACHET
|
|||
__FILE__, __LINE__, fname, dbname, is_create, newbrt, nodesize, cachetable));
|
||||
if (0) { died0: assert(r); return r; }
|
||||
|
||||
assert(is_create || !only_create);
|
||||
if (dbname) {
|
||||
malloced_name = toku_strdup(dbname);
|
||||
if (malloced_name==0) {
|
||||
|
@ -1557,12 +1558,16 @@ int brt_open(BRT t, const char *fname, const char *dbname, int is_create, CACHET
|
|||
} else {
|
||||
int i;
|
||||
assert(r==0);
|
||||
assert(dbname);
|
||||
assert(t->h->unnamed_root==-1);
|
||||
assert(t->h->n_named_roots>=0);
|
||||
for (i=0; i<t->h->n_named_roots; i++) {
|
||||
if (strcmp(t->h->names[i], dbname)==0) {
|
||||
r = EEXIST;
|
||||
goto died1; /* deallocate everything. */
|
||||
if (only_create) {
|
||||
r = EEXIST;
|
||||
goto died1; /* deallocate everything. */
|
||||
}
|
||||
else goto found_it;
|
||||
}
|
||||
}
|
||||
if ((t->h->names = toku_realloc(t->h->names, (1+t->h->n_named_roots)*sizeof(*t->h->names))) == 0) { assert(errno==ENOMEM); r=ENOMEM; goto died1; }
|
||||
|
@ -1653,6 +1658,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
|
|||
int (*compare_fun)(DB*,const DBT*,const DBT*)) {
|
||||
BRT brt;
|
||||
int r;
|
||||
int only_create = 0;
|
||||
|
||||
r = brt_create(&brt);
|
||||
if (r != 0)
|
||||
|
@ -1660,7 +1666,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
|
|||
brt_set_nodesize(brt, nodesize);
|
||||
brt_set_bt_compare(brt, compare_fun);
|
||||
|
||||
r = brt_open(brt, fname, dbname, is_create, cachetable, txn);
|
||||
r = brt_open(brt, fname, dbname, is_create, only_create, cachetable, txn);
|
||||
if (r != 0) {
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ int brt_set_nodesize(BRT, int nodesize);
|
|||
int brt_set_bt_compare(BRT, int (*bt_compare)(DB *, const DBT*, const DBT*));
|
||||
int brt_set_dup_compare(BRT, int (*dup_compare)(DB *, const DBT*, const DBT*));
|
||||
int brt_set_cachetable(BRT, CACHETABLE);
|
||||
int brt_open(BRT, const char *fname, const char *dbname, int is_create, CACHETABLE ct, TOKUTXN txn);
|
||||
int brt_open(BRT, const char *fname, const char *dbname, int is_create, int only_create, CACHETABLE ct, TOKUTXN txn);
|
||||
int brt_remove_subdb(BRT brt, const char *dbname, u_int32_t flags);
|
||||
|
||||
int brt_insert (BRT, DBT *, DBT *, DB*, TOKUTXN);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <db.h>
|
||||
#include <errno.h>
|
||||
|
||||
// DIR is defined in the Makefile
|
||||
|
||||
|
@ -23,9 +24,6 @@ int main() {
|
|||
r = db_create(&db, null_env, 0);
|
||||
assert(r == 0);
|
||||
|
||||
r = db->set_flags(db, DB_DUP);
|
||||
assert(r == 0);
|
||||
|
||||
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666);
|
||||
assert(r == 0);
|
||||
|
||||
|
@ -41,5 +39,23 @@ int main() {
|
|||
r = db->close(db, 0);
|
||||
assert(r == 0);
|
||||
|
||||
r = db_create(&db, null_env, 0);
|
||||
assert(r == 0);
|
||||
|
||||
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_EXCL, 0666);
|
||||
assert(r == EINVAL);
|
||||
|
||||
r = db->close(db, 0);
|
||||
assert(r == 0);
|
||||
|
||||
r = db_create(&db, null_env, 0);
|
||||
assert(r == 0);
|
||||
|
||||
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE | DB_EXCL, 0666);
|
||||
assert(r == EEXIST);
|
||||
|
||||
r = db->close(db, 0);
|
||||
assert(r == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
20
src/ydb.c
20
src/ydb.c
|
@ -577,6 +577,9 @@ int __toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *dbname,
|
|||
|
||||
int openflags = 0;
|
||||
int r;
|
||||
|
||||
if ((flags & DB_EXCL) && !(flags & DB_CREATE)) return EINVAL;
|
||||
|
||||
if (db->i->full_fname)
|
||||
return -1; /* It was already open. */
|
||||
db->i->full_fname = construct_full_name(db->dbenv->i->dir, fname);
|
||||
|
@ -594,17 +597,17 @@ int __toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *dbname,
|
|||
openflags |= O_RDONLY;
|
||||
else
|
||||
openflags |= O_RDWR;
|
||||
|
||||
if (flags & DB_CREATE)
|
||||
openflags |= O_CREAT;
|
||||
|
||||
|
||||
{
|
||||
struct stat statbuf;
|
||||
if (stat(db->i->full_fname, &statbuf) == 0) {
|
||||
/* If the database exists at the file level, and we specified no db_name, then complain here. */
|
||||
if (dbname == 0 && (flags & DB_CREATE)) {
|
||||
r = EEXIST;
|
||||
goto error_cleanup;
|
||||
if (flags & DB_EXCL) {
|
||||
r = EEXIST;
|
||||
goto error_cleanup;
|
||||
}
|
||||
flags &= ~DB_CREATE;
|
||||
}
|
||||
} else {
|
||||
if (!(flags & DB_CREATE)) {
|
||||
|
@ -613,12 +616,13 @@ int __toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *dbname,
|
|||
}
|
||||
}
|
||||
}
|
||||
if (flags & DB_CREATE) openflags |= O_CREAT;
|
||||
|
||||
db->i->open_flags = flags;
|
||||
db->i->open_mode = mode;
|
||||
|
||||
r = brt_open(db->i->brt, db->i->full_fname, dbname, flags & DB_CREATE,
|
||||
db->dbenv->i->cachetable,
|
||||
r = brt_open(db->i->brt, db->i->full_fname, dbname, flags & DB_CREATE,
|
||||
flags & DB_EXCL, db->dbenv->i->cachetable,
|
||||
txn ? txn->i->tokutxn : NULL_TXN);
|
||||
if (r != 0)
|
||||
goto error_cleanup;
|
||||
|
|
Loading…
Add table
Reference in a new issue