diff options
author | Eliot Horowitz <eliot@10gen.com> | 2014-02-19 07:45:54 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2014-02-19 07:45:54 -0500 |
commit | 63ba64be33b2c0dab6fb9bbfbbd265f0afa7e788 (patch) | |
tree | aa7975a9260ad599a5f341b1c936d4524d49c1a2 /src/mongo/db/repair_database.cpp | |
parent | 681c74b3f2de1e3665f953dfb07bcb25f48ecd2c (diff) | |
download | mongo-63ba64be33b2c0dab6fb9bbfbbd265f0afa7e788.tar.gz |
SERVER-8412: fix repair database failure cleanup
Diffstat (limited to 'src/mongo/db/repair_database.cpp')
-rw-r--r-- | src/mongo/db/repair_database.cpp | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp index 06fdfe8cf03..df22ec051fb 100644 --- a/src/mongo/db/repair_database.cpp +++ b/src/mongo/db/repair_database.cpp @@ -228,24 +228,47 @@ namespace mongo { class RepairFileDeleter { public: - RepairFileDeleter( const Path& path ) - : _path( path ), - _succces( false ) { + RepairFileDeleter( const string& dbName, + const string& pathString, + const Path& path ) + : _dbName( dbName ), + _pathString( pathString ), + _path( path ), + _success( false ) { } ~RepairFileDeleter() { - if ( !_succces ) { + if ( _success ) + return; + + log() << "cleaning up failed repair " + << "db: " << _dbName << " path: " << _pathString; + + try { + getDur().syncDataAndTruncateJournal(); + MongoFile::flushAll(true); // need both in case journaling is disabled + { + Client::Context tempContext( _dbName, _pathString ); + Database::closeDatabase( _dbName, _pathString ); + } MONGO_ASSERT_ON_EXCEPTION( boost::filesystem::remove_all( _path ) ); } + catch ( DBException& e ) { + error() << "RepairFileDeleter failed to cleanup: " << e; + error() << "aborting"; + fassertFailed( 17402 ); + } } void success() { - _succces = true; + _success = true; } private: + string _dbName; + string _pathString; Path _path; - bool _succces; + bool _success; }; Status repairDatabase( string dbName, @@ -283,7 +306,9 @@ namespace mongo { string reservedPathString = reservedPath.string(); if ( !preserveClonedFilesOnFailure ) - repairFileDeleter.reset( new RepairFileDeleter( reservedPath ) ); + repairFileDeleter.reset( new RepairFileDeleter( dbName, + reservedPathString, + reservedPath ) ); { Database* originalDatabase = dbHolder().get( dbName, storageGlobalParams.dbpath ); @@ -396,6 +421,9 @@ namespace mongo { } + getDur().syncDataAndTruncateJournal(); + MongoFile::flushAll(true); // need both in case journaling is disabled + Client::Context tempContext( dbName, reservedPathString ); Database::closeDatabase( dbName, reservedPathString ); } |