Commit 488e36a5 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #1396

Opening a DB dirties it.

git-svn-id: file:///svn/toku/tokudb@9144 c7de825b-a66e-492c-adef-691d508d4ae1
parent 56f1207f
...@@ -1411,7 +1411,7 @@ unlock_for_graceful (void) { ...@@ -1411,7 +1411,7 @@ unlock_for_graceful (void) {
} }
static int static int
graceful_open_get_append_fd(const char *db_fname, BOOL *is_dirtyp, BOOL *create) { graceful_open_get_append_fd(const char *db_fname, BOOL *was_dirtyp, BOOL *create) {
BOOL clean_exists; BOOL clean_exists;
BOOL dirty_exists; BOOL dirty_exists;
char cleanbuf[strlen(db_fname) + sizeof(".clean")]; char cleanbuf[strlen(db_fname) + sizeof(".clean")];
...@@ -1426,26 +1426,17 @@ graceful_open_get_append_fd(const char *db_fname, BOOL *is_dirtyp, BOOL *create) ...@@ -1426,26 +1426,17 @@ graceful_open_get_append_fd(const char *db_fname, BOOL *is_dirtyp, BOOL *create)
mode_t mode = S_IRWXU|S_IRWXG|S_IRWXO; mode_t mode = S_IRWXU|S_IRWXG|S_IRWXO;
int r = 0; int r = 0;
*create = FALSE; *was_dirtyp = dirty_exists;
if (dirty_exists && clean_exists) { *create = FALSE;
r = unlink(cleanbuf); if (!dirty_exists && !clean_exists) {
clean_exists = FALSE; *create = TRUE;
dirty_exists = TRUE;
} }
if (r==0) { if (clean_exists) {
if (!dirty_exists && !clean_exists) { if (dirty_exists) r = unlink(cleanbuf);
*create = TRUE; else r = rename(cleanbuf, dirtybuf);
dirty_exists = TRUE;
}
if (dirty_exists) {
*is_dirtyp = TRUE;
r = open(dirtybuf, O_WRONLY | O_CREAT | O_BINARY | O_APPEND, mode);
}
else {
assert(clean_exists);
*is_dirtyp = FALSE;
r = open(cleanbuf, O_WRONLY | O_CREAT | O_BINARY | O_APPEND, mode);
}
} }
r = open(dirtybuf, O_WRONLY | O_CREAT | O_BINARY | O_APPEND, mode);
return r; return r;
} }
...@@ -1529,17 +1520,20 @@ int ...@@ -1529,17 +1520,20 @@ int
toku_graceful_open(const char *db_fname, BOOL *is_dirtyp) { toku_graceful_open(const char *db_fname, BOOL *is_dirtyp) {
int r; int r;
int r2 = 0; int r2 = 0;
BOOL is_dirty; BOOL was_dirty;
BOOL created; BOOL created;
int fd; int fd;
lock_for_graceful(); lock_for_graceful();
fd = graceful_open_get_append_fd(db_fname, &is_dirty, &created); fd = graceful_open_get_append_fd(db_fname, &was_dirty, &created);
if (fd == -1) r = errno; if (fd == -1) r = errno;
else { else {
graceful_log(fd, created ? "Created" : "Opened", is_dirty, is_dirty); graceful_log(fd,
*is_dirtyp = is_dirty; created ? "Created" : "Opened",
if (created || !is_dirty) r = 0; was_dirty,
TRUE);
*is_dirtyp = TRUE;
if (created || !was_dirty) r = 0;
else r = TOKUDB_DIRTY_DICTIONARY; else r = TOKUDB_DIRTY_DICTIONARY;
r2 = close(fd); r2 = close(fd);
} }
......
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