diff options
author | Divjot Arora <divjot.arora@10gen.com> | 2019-03-14 12:28:02 -0400 |
---|---|---|
committer | Divjot Arora <divjot.arora@10gen.com> | 2019-03-18 19:49:31 -0400 |
commit | c9288a60089bf421d51c7a8573a2ceb5849edfd8 (patch) | |
tree | 69ec5148fc23a1a7b84176ed0b836c2657f0bd89 /src/mongo/db/repair_database.cpp | |
parent | 159eba44d7aad44e49c688820b1b0331230236bf (diff) | |
download | mongo-c9288a60089bf421d51c7a8573a2ceb5849edfd8.tar.gz |
SERVER-40126 Change openDb to throw exception
Diffstat (limited to 'src/mongo/db/repair_database.cpp')
-rw-r--r-- | src/mongo/db/repair_database.cpp | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp index b1c6f99d06f..18275da03cf 100644 --- a/src/mongo/db/repair_database.cpp +++ b/src/mongo/db/repair_database.cpp @@ -201,38 +201,40 @@ Status repairDatabase(OperationContext* opCtx, // Close the db and invalidate all current users and caches. auto databaseHolder = DatabaseHolder::get(opCtx); databaseHolder->close(opCtx, dbName); - ON_BLOCK_EXIT([databaseHolder, &dbName, &opCtx] { - try { - // Ensure that we don't trigger an exception when attempting to take locks. - UninterruptibleLockGuard noInterrupt(opCtx->lockState()); - // Open the db after everything finishes. - auto db = databaseHolder->openDb(opCtx, dbName); + auto status = repairCollections(opCtx, engine, dbName, onRecordStoreRepair); + if (!status.isOK()) { + severe() << "Failed to repair database " << dbName << ": " << status.reason(); + } - // Set the minimum snapshot for all Collections in this db. This ensures that readers - // using majority readConcern level can only use the collections after their repaired - // versions are in the committed view. - auto clusterTime = LogicalClock::getClusterTimeForReplicaSet(opCtx).asTimestamp(); + try { + // Ensure that we don't trigger an exception when attempting to take locks. + UninterruptibleLockGuard noInterrupt(opCtx->lockState()); - for (auto&& collection : *db) { - collection->setMinimumVisibleSnapshot(clusterTime); - } + // Open the db after everything finishes. + auto db = databaseHolder->openDb(opCtx, dbName); - // Restore oplog Collection pointer cache. - repl::acquireOplogCollectionForLogging(opCtx); - } catch (...) { - severe() << "Unexpected exception encountered while reopening database after repair."; - std::terminate(); // Logs additional info about the specific error. + // Set the minimum snapshot for all Collections in this db. This ensures that readers + // using majority readConcern level can only use the collections after their repaired + // versions are in the committed view. + auto clusterTime = LogicalClock::getClusterTimeForReplicaSet(opCtx).asTimestamp(); + + for (auto&& collection : *db) { + collection->setMinimumVisibleSnapshot(clusterTime); } - }); - auto status = repairCollections(opCtx, engine, dbName, onRecordStoreRepair); - if (!status.isOK()) { - severe() << "Failed to repair database " << dbName << ": " << status.reason(); - return status; + // Restore oplog Collection pointer cache. + repl::acquireOplogCollectionForLogging(opCtx); + } catch (const ExceptionFor<ErrorCodes::MustDowngrade>&) { + // openDb can throw an exception with a MustDowngrade status if a collection does not + // have a UUID. + throw; + } catch (...) { + severe() << "Unexpected exception encountered while reopening database after repair."; + std::terminate(); // Logs additional info about the specific error. } - return Status::OK(); + return status; } } // namespace mongo |