summaryrefslogtreecommitdiff
path: root/src/mongo/db/repair_database.cpp
diff options
context:
space:
mode:
authorScott Hernandez <scotthernandez@gmail.com>2014-12-30 14:46:29 -0500
committerScott Hernandez <scotthernandez@gmail.com>2015-01-02 14:21:08 -0500
commit8b37507dd51cdf058377a24ca0171e7fae6f2c6b (patch)
tree1bea2528edb8df7cf70fda21f6894e59af820f60 /src/mongo/db/repair_database.cpp
parent430bafbd8643bd1d30513ad231850c6927e8553d (diff)
downloadmongo-8b37507dd51cdf058377a24ca0171e7fae6f2c6b.tar.gz
SERVER-16502: open database after repair is done
Diffstat (limited to 'src/mongo/db/repair_database.cpp')
-rw-r--r--src/mongo/db/repair_database.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp
index af27db45098..8f49e4df300 100644
--- a/src/mongo/db/repair_database.cpp
+++ b/src/mongo/db/repair_database.cpp
@@ -55,7 +55,6 @@ namespace {
DatabaseCatalogEntry* dbce,
const std::string& collectionName) {
- Database db(txn, dbce->name(), dbce);
CollectionCatalogEntry* cce = dbce->getCollectionCatalogEntry(txn, collectionName);
std::vector<string> indexNames;
@@ -81,6 +80,7 @@ namespace {
// Skip the rest if there are no indexes to rebuild.
if (indexSpecs.empty()) return Status::OK();
+ boost::scoped_ptr<Database> db;
Collection* collection;
boost::scoped_ptr<MultiIndexBlock> indexer;
{
@@ -102,7 +102,8 @@ namespace {
// Indexes must be dropped before we open the Collection otherwise we could attempt to
// open a bad index and fail.
// TODO see if MultiIndexBlock can be made to work without a Collection.
- collection = db.getCollection(txn, collectionName);
+ db.reset(new Database(txn, dbce->name(), dbce));
+ collection = db->getCollection(txn, collectionName);
invariant(collection);
indexer.reset(new MultiIndexBlock(txn, collection));
@@ -166,6 +167,8 @@ namespace {
bool preserveClonedFilesOnFailure,
bool backupOriginalFiles) {
+
+
// We must hold some form of lock here
invariant(txn->lockState()->isLocked());
invariant( dbName.find( '.' ) == string::npos );
@@ -192,12 +195,22 @@ namespace {
return Status( ErrorCodes::BadValue, "backupOriginalFiles not supported" );
}
- // Close and reopen the db to invalidate all current users and caches.
- // WARNING: it is important that the opened Database object isn't used for anything as its
- // cache must remain empty until we return.
+ // Close the db to invalidate all current users and caches.
dbHolder().close(txn, dbName);
- dbHolder().openDb(txn, dbName);
-
+ // Open the db after everything finishes
+ class OpenDbInDestructor {
+ public:
+ OpenDbInDestructor(OperationContext* txn, const std::string& db) :
+ _dbName(db)
+ , _txn(txn)
+ {}
+ ~OpenDbInDestructor() {
+ dbHolder().openDb(_txn, _dbName);
+ }
+ private:
+ const std::string& _dbName;
+ OperationContext* _txn;
+ } dbOpener(txn, dbName);
DatabaseCatalogEntry* dbce = engine->getDatabaseCatalogEntry(txn, dbName);
std::list<std::string> colls;