diff options
author | Eliot Horowitz <eliot@10gen.com> | 2014-04-30 00:16:07 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2014-04-30 00:16:07 -0400 |
commit | ed1c2d2db431766492892e68702564f5722f15b0 (patch) | |
tree | 5b46a6e6c10bacf586c68502edc0e24ad57b3679 /src/mongo/db/repair_database.cpp | |
parent | 712e4f8063a0e329fd6d69d80d992e2214f97d6e (diff) | |
download | mongo-ed1c2d2db431766492892e68702564f5722f15b0.tar.gz |
SERVER-13739: don't delete new files until as late as possible during repair
Diffstat (limited to 'src/mongo/db/repair_database.cpp')
-rw-r--r-- | src/mongo/db/repair_database.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp index 7dbea7e9b95..d7bcdc40d7e 100644 --- a/src/mongo/db/repair_database.cpp +++ b/src/mongo/db/repair_database.cpp @@ -428,21 +428,32 @@ namespace mongo { Database::closeDatabase( dbName, reservedPathString ); } + // at this point if we abort, we don't want to delete new files + // as they might be the only copies + + if ( repairFileDeleter.get() ) + repairFileDeleter->success(); + Client::Context ctx( dbName ); Database::closeDatabase(dbName, storageGlobalParams.dbpath); - if ( backupOriginalFiles ) { _renameForBackup( dbName, reservedPath ); } else { + // first make new directory before deleting data + Path newDir = Path(storageGlobalParams.dbpath) / dbName; + MONGO_ASSERT_ON_EXCEPTION(boost::filesystem::create_directory(newDir)); + + // this deletes old files _deleteDataFiles( dbName ); - MONGO_ASSERT_ON_EXCEPTION( - boost::filesystem::create_directory(Path(storageGlobalParams.dbpath) / dbName)); - } - if ( repairFileDeleter.get() ) - repairFileDeleter->success(); + if ( !boost::filesystem::exists(newDir) ) { + // we deleted because of directoryperdb + // re-create + MONGO_ASSERT_ON_EXCEPTION(boost::filesystem::create_directory(newDir)); + } + } _replaceWithRecovered( dbName, reservedPathString.c_str() ); |