Commit 0b981a37 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #1639 Can now remove (unnamed) old version dbs. Test included

git-svn-id: file:///svn/toku/tokudb@10925 c7de825b-a66e-492c-adef-691d508d4ae1
parent de8165e2
......@@ -113,7 +113,7 @@ typedef enum {
/* TOKUDB specific error codes */
#define TOKUDB_OUT_OF_LOCKS -100000
#define TOKUDB_SUCCEEDED_EARLY -100001
#define TOKUDB_DIRTY_DICTIONARY -100004
#define TOKUDB_DICTIONARY_TOO_OLD -100004
#define TOKUDB_FOUND_BUT_REJECTED -100002
#define TOKUDB_USER_CALLBACK_ERROR -100003
/* in wrap mode, top-level function txn_begin is renamed, but the field isn't renamed, so we have to hack it here.*/
......
......@@ -115,7 +115,7 @@ typedef enum {
/* TOKUDB specific error codes */
#define TOKUDB_OUT_OF_LOCKS -100000
#define TOKUDB_SUCCEEDED_EARLY -100001
#define TOKUDB_DIRTY_DICTIONARY -100004
#define TOKUDB_DICTIONARY_TOO_OLD -100004
#define TOKUDB_FOUND_BUT_REJECTED -100002
#define TOKUDB_USER_CALLBACK_ERROR -100003
/* in wrap mode, top-level function txn_begin is renamed, but the field isn't renamed, so we have to hack it here.*/
......
......@@ -116,7 +116,7 @@ typedef enum {
/* TOKUDB specific error codes */
#define TOKUDB_OUT_OF_LOCKS -100000
#define TOKUDB_SUCCEEDED_EARLY -100001
#define TOKUDB_DIRTY_DICTIONARY -100004
#define TOKUDB_DICTIONARY_TOO_OLD -100004
#define TOKUDB_FOUND_BUT_REJECTED -100002
#define TOKUDB_USER_CALLBACK_ERROR -100003
/* in wrap mode, top-level function txn_begin is renamed, but the field isn't renamed, so we have to hack it here.*/
......
......@@ -116,7 +116,7 @@ typedef enum {
/* TOKUDB specific error codes */
#define TOKUDB_OUT_OF_LOCKS -100000
#define TOKUDB_SUCCEEDED_EARLY -100001
#define TOKUDB_DIRTY_DICTIONARY -100004
#define TOKUDB_DICTIONARY_TOO_OLD -100004
#define TOKUDB_FOUND_BUT_REJECTED -100002
#define TOKUDB_USER_CALLBACK_ERROR -100003
/* in wrap mode, top-level function txn_begin is renamed, but the field isn't renamed, so we have to hack it here.*/
......
......@@ -118,7 +118,7 @@ typedef enum {
/* TOKUDB specific error codes */
#define TOKUDB_OUT_OF_LOCKS -100000
#define TOKUDB_SUCCEEDED_EARLY -100001
#define TOKUDB_DIRTY_DICTIONARY -100004
#define TOKUDB_DICTIONARY_TOO_OLD -100004
#define TOKUDB_FOUND_BUT_REJECTED -100002
#define TOKUDB_USER_CALLBACK_ERROR -100003
/* in wrap mode, top-level function txn_begin is renamed, but the field isn't renamed, so we have to hack it here.*/
......
......@@ -34,7 +34,7 @@ enum {
TOKUDB_SUCCEEDED_EARLY = -100001,
TOKUDB_FOUND_BUT_REJECTED = -100002,
TOKUDB_USER_CALLBACK_ERROR = -100003,
TOKUDB_DIRTY_DICTIONARY = -100004
TOKUDB_DICTIONARY_TOO_OLD = -100004
};
void print_defines (void) {
......@@ -140,7 +140,7 @@ void print_defines (void) {
printf("/* TOKUDB specific error codes */\n");
dodefine(TOKUDB_OUT_OF_LOCKS);
dodefine(TOKUDB_SUCCEEDED_EARLY);
dodefine(TOKUDB_DIRTY_DICTIONARY);
dodefine(TOKUDB_DICTIONARY_TOO_OLD);
dodefine(TOKUDB_FOUND_BUT_REJECTED);
dodefine(TOKUDB_USER_CALLBACK_ERROR);
}
......
......@@ -118,7 +118,7 @@ typedef enum {
/* TOKUDB specific error codes */
#define TOKUDB_OUT_OF_LOCKS -100000
#define TOKUDB_SUCCEEDED_EARLY -100001
#define TOKUDB_DIRTY_DICTIONARY -100004
#define TOKUDB_DICTIONARY_TOO_OLD -100004
#define TOKUDB_FOUND_BUT_REJECTED -100002
#define TOKUDB_USER_CALLBACK_ERROR -100003
/* in wrap mode, top-level function txn_begin is renamed, but the field isn't renamed, so we have to hack it here.*/
......
......@@ -1220,7 +1220,7 @@ deserialize_brtheader (int fd, struct rbuf *rb, struct brt_header **brth) {
//-1 means we can overwrite everything in the file AND the header is useless
static int
deserialize_brtheader_from_fd_into_rbuf(int fd, toku_off_t offset, struct rbuf *rb, u_int64_t *checkpoint_count) {
int r;
int r = 0;
const int prefix_size = 8 + // magic ("tokudata")
4; // size
char prefix[prefix_size];
......@@ -1244,17 +1244,17 @@ deserialize_brtheader_from_fd_into_rbuf(int fd, toku_off_t offset, struct rbuf *
else {
n = pread(fd, rb->buf, rb->size, offset);
if (n!=(int64_t)size) r = EINVAL; //Header might be useless (wrong size) or could be an error.
else {
if (r==0) {
//check version (before checksum, since older versions didn't have checksums)
int version = rbuf_network_int(rb);
if (version != BRT_LAYOUT_VERSION_10) r = TOKUDB_DICTIONARY_TOO_OLD; //Cannot use
}
if (r==0) {
u_int32_t calculated_x1764 = x1764_memory(rb->buf, size-4);
u_int32_t stored_x1764 = toku_dtoh32(*(int*)(rb->buf+size-4));
if (calculated_x1764!=stored_x1764) r = -1; //Header useless
else r = 0;
}
if (r==0) {
//check version/checkstuff
int version = rbuf_network_int(rb);
if (version != BRT_LAYOUT_VERSION_10) r = EINVAL; //Cannot use
}
if (r==0) {
//Verify byte order
bytevec tmp_byte_order_check;
......@@ -1299,6 +1299,7 @@ int toku_deserialize_brtheader_from (int fd, struct brt_header **brth) {
int r = 0;
if (rb==NULL) {
r = r0;
if (r1==TOKUDB_DICTIONARY_TOO_OLD) r = r1;
assert(r!=0);
}
......
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
#include "test.h"
#include "toku_portability.h"
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
#define stringify(x) #x
// ENVDIR is defined in the Makefile
DB_ENV *env;
DB *db;
static void
create_db(char *name) {
char fullname[strlen(name) + sizeof(ENVDIR) + sizeof("/")];
sprintf(fullname, "%s/%s", ENVDIR, name);
int r;
r=db_create(&db, NULL, 0);
CKERR(r);
r=db->open(db, NULL, fullname, NULL, DB_BTREE, DB_CREATE, 0666);
CKERR(r);
r=db->close(db, 0);
CKERR(r);
}
static void
delete_db(char *name) {
char fullname[strlen(name) + sizeof(ENVDIR) + sizeof("/")];
sprintf(fullname, "%s/%s", ENVDIR, name);
int r;
toku_struct_stat buf;
r = toku_stat(fullname, &buf);
CKERR(r);
r=db_create(&db, NULL, 0);
CKERR(r);
r=db->remove(db, fullname, NULL, 0);
CKERR(r);
r = toku_stat(fullname, &buf);
CKERR2(r, -1);
r = errno;
CKERR2(r, ENOENT);
}
int
test_main (int UU(argc), const char UU(*argv[])) {
int r;
r=system("rm -rf " ENVDIR);
CKERR(r);
r=toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
system("cp test_dbremove_old.dir/* "ENVDIR);
CKERR(r);
{
//Create and delete a brand new version db.
char *unnamed_db = "version_now_unnamed.tokudb";
create_db(unnamed_db);
delete_db(unnamed_db);
}
{
//Delete old version dbs
DIR* direct = opendir(ENVDIR);
struct dirent *entry;
while ((entry = readdir(direct))) {
if (entry->d_type&DT_REG) {
delete_db(entry->d_name);
}
}
closedir(direct);
}
return 0;
}
......@@ -3022,7 +3022,7 @@ static int toku_db_remove(DB * db, const char *fname, const char *dbname, u_int3
//TODO: Verify DB* db not yet opened
//TODO: Verify db file not in use. (all dbs in the file must be unused)
r = toku_db_open(db, NULL, fname, dbname, DB_UNKNOWN, 0, S_IRWXU|S_IRWXG|S_IRWXO);
if (r==TOKUDB_DIRTY_DICTIONARY && !dbname) {
if (r==TOKUDB_DICTIONARY_TOO_OLD && !dbname) {
need_close = FALSE;
goto delete_db_file;
}
......
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