Commit 6ce9a5cd authored by Rich Prohaska's avatar Rich Prohaska

make tokudb->set_flags compatible with bdb->set_flags. closes #157

git-svn-id: file:///svn/tokudb@1116 c7de825b-a66e-492c-adef-691d508d4ae1
parent e39af351
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <db.h>
#include "test.h"
void test_db_set_flags(int flags, int expectr, int flags2, int expectr2) {
if (verbose) printf("test_db_set_flags:%d %d %d %d\n", flags, expectr, flags2, expectr2);
DB_ENV * const null_env = 0;
DB *db;
DB_TXN * const null_txn = 0;
const char * const fname = DIR "/" "test.db.set.flags.brt";
int r;
unlink(fname);
r = db_create(&db, null_env, 0); assert(r == 0);
r = db->set_flags(db, flags); assert(r == expectr);
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666); assert(r == 0);
r = db->set_flags(db, flags2); assert(r == expectr2);
r = db->close(db, 0); assert(r == 0);
}
int main(int argc, const char *argv[]) {
parse_args(argc, argv);
system("rm -rf " DIR);
mkdir(DIR, 0777);
test_db_set_flags(0, 0, 0, 0);
test_db_set_flags(0, 0, DB_DUP, EINVAL);
test_db_set_flags(DB_DUP, 0, DB_DUP, EINVAL);
test_db_set_flags(DB_DUP, 0, 0, 0);
return 0;
}
...@@ -117,6 +117,9 @@ static inline int db_env_opened(DB_ENV *env) { ...@@ -117,6 +117,9 @@ static inline int db_env_opened(DB_ENV *env) {
return env->i->cachetable != 0; return env->i->cachetable != 0;
} }
static inline int db_opened(DB *db) {
return db->i->full_fname != 0;
}
static int db_env_parse_config_line(DB_ENV* dbenv, char *command, char *value) { static int db_env_parse_config_line(DB_ENV* dbenv, char *command, char *value) {
int r; int r;
...@@ -1123,7 +1126,7 @@ static int toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *db ...@@ -1123,7 +1126,7 @@ static int toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *db
if ((flags & DB_EXCL) && !(flags & DB_CREATE)) return EINVAL; if ((flags & DB_EXCL) && !(flags & DB_CREATE)) return EINVAL;
if (dbtype==DB_UNKNOWN && (flags & DB_EXCL)) return EINVAL; if (dbtype==DB_UNKNOWN && (flags & DB_EXCL)) return EINVAL;
if (db->i->full_fname) if (db_opened(db))
return -1; /* It was already open. */ return -1; /* It was already open. */
db->i->full_fname = construct_full_name(db->dbenv->i->dir, fname); db->i->full_fname = construct_full_name(db->dbenv->i->dir, fname);
if (db->i->full_fname == 0) { if (db->i->full_fname == 0) {
...@@ -1299,6 +1302,9 @@ static int toku_db_set_dup_compare(DB *db, int (*dup_compare)(DB *, const DBT *, ...@@ -1299,6 +1302,9 @@ static int toku_db_set_dup_compare(DB *db, int (*dup_compare)(DB *, const DBT *,
} }
static int toku_db_set_flags(DB * db, u_int32_t flags) { static int toku_db_set_flags(DB * db, u_int32_t flags) {
if (db_opened(db) && flags != 0) return EINVAL;
u_int32_t tflags; u_int32_t tflags;
int r = toku_brt_get_flags(db->i->brt, &tflags); int r = toku_brt_get_flags(db->i->brt, &tflags);
if (r!=0) return r; if (r!=0) 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