diff options
author | Michael Cahill <michael.cahill@mongodb.com> | 2015-05-19 16:39:18 +1000 |
---|---|---|
committer | Michael Cahill <michael.cahill@mongodb.com> | 2015-05-25 16:43:19 +1000 |
commit | 8411609f3bc3c1dee36c8690e8d09d269d03894d (patch) | |
tree | f268964f9417342406cefe3c7cf0604cc0cf0251 | |
parent | c81beade99f4b32665c3c6a322025abdb98042af (diff) | |
download | mongo-8411609f3bc3c1dee36c8690e8d09d269d03894d.tar.gz |
Merge pull request #1974 from wiredtiger/handle-unexpected-files
block manager and already-existing files.
(cherry picked from commit 9f93181d630bc5b3258209bccacac2e4f4db5e80)
-rw-r--r-- | src/block/block_open.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/block/block_open.c b/src/block/block_open.c index 64bd86294f2..5a882f0fb7c 100644 --- a/src/block/block_open.c +++ b/src/block/block_open.c @@ -51,11 +51,41 @@ __wt_block_manager_create( WT_SESSION_IMPL *session, const char *filename, uint32_t allocsize) { WT_DECL_RET; + WT_DECL_ITEM(tmp); WT_FH *fh; + int exists, suffix; char *path; - /* Create the underlying file and open a handle. */ - WT_RET(__wt_open(session, filename, 1, 1, WT_FILE_TYPE_DATA, &fh)); + /* + * Create the underlying file and open a handle. + * + * Since WiredTiger schema operations are (currently) non-transactional, + * it's possible to see a partially-created file left from a previous + * create. Further, there's nothing to prevent users from creating files + * in our space. Move any existing files out of the way and complain. + */ + for (;;) { + if ((ret = __wt_open( + session, filename, 1, 1, WT_FILE_TYPE_DATA, &fh)) == 0) + break; + WT_ERR_TEST(ret != EEXIST, ret); + + if (tmp == NULL) + WT_ERR(__wt_scr_alloc(session, 0, &tmp)); + for (suffix = 1;; ++suffix) { + WT_ERR(__wt_buf_fmt( + session, tmp, "%s.%d", filename, suffix)); + WT_ERR(__wt_exist(session, tmp->data, &exists)); + if (!exists) { + WT_ERR( + __wt_rename(session, filename, tmp->data)); + WT_ERR(__wt_msg(session, + "unexpected file %s found, renamed to %s", + filename, (char *)tmp->data)); + break; + } + } + } /* Write out the file's meta-data. */ ret = __wt_desc_init(session, fh, allocsize); @@ -83,6 +113,8 @@ __wt_block_manager_create( if (ret != 0) WT_TRET(__wt_remove(session, filename)); +err: __wt_scr_free(session, &tmp); + return (ret); } |