summaryrefslogtreecommitdiff
path: root/src/mongo/db/repair_database.cpp
diff options
context:
space:
mode:
authorDaniel Gottlieb <daniel.gottlieb@mongodb.com>2017-08-15 14:19:26 -0400
committerDaniel Gottlieb <daniel.gottlieb@mongodb.com>2017-08-15 14:19:26 -0400
commit3138119968a4d5bb7602bc766762d571ae5cd248 (patch)
tree876d19f0d5f97dc2e17304b7b7b5930ac86fb65d /src/mongo/db/repair_database.cpp
parent6b366f48699ce1a040b2129ef745290261153cc9 (diff)
downloadmongo-3138119968a4d5bb7602bc766762d571ae5cd248.tar.gz
SERVER-30081: Run storage recovery at startup.
Diffstat (limited to 'src/mongo/db/repair_database.cpp')
-rw-r--r--src/mongo/db/repair_database.cpp42
1 files changed, 32 insertions, 10 deletions
diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp
index af2e4b1be3b..552f4577f04 100644
--- a/src/mongo/db/repair_database.cpp
+++ b/src/mongo/db/repair_database.cpp
@@ -30,11 +30,14 @@
#include "mongo/platform/basic.h"
+#include <algorithm>
+
#include "mongo/db/repair_database.h"
#include "mongo/base/status.h"
#include "mongo/base/string_data.h"
#include "mongo/bson/bson_validate.h"
+#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/db/background.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/collection_catalog_entry.h"
@@ -60,17 +63,22 @@ using std::string;
using IndexVersion = IndexDescriptor::IndexVersion;
-namespace {
-Status rebuildIndexesOnCollection(OperationContext* opCtx,
- DatabaseCatalogEntry* dbce,
- const std::string& collectionName) {
- CollectionCatalogEntry* cce = dbce->getCollectionCatalogEntry(collectionName);
-
- std::vector<string> indexNames;
- std::vector<BSONObj> indexSpecs;
+StatusWith<IndexNameObjs> getIndexNameObjs(OperationContext* opCtx,
+ DatabaseCatalogEntry* dbce,
+ CollectionCatalogEntry* cce,
+ stdx::function<bool(const std::string&)> filter) {
+ IndexNameObjs ret;
+ std::vector<string>& indexNames = ret.first;
+ std::vector<BSONObj>& indexSpecs = ret.second;
{
// Fetch all indexes
cce->getAllIndexes(opCtx, &indexNames);
+ auto newEnd =
+ std::remove_if(indexNames.begin(),
+ indexNames.end(),
+ [&filter](const std::string& indexName) { return !filter(indexName); });
+ indexNames.erase(newEnd, indexNames.end());
+
indexSpecs.reserve(indexNames.size());
for (size_t i = 0; i < indexNames.size(); i++) {
@@ -118,6 +126,16 @@ Status rebuildIndexesOnCollection(OperationContext* opCtx,
}
}
+ return ret;
+}
+
+Status rebuildIndexesOnCollection(OperationContext* opCtx,
+ DatabaseCatalogEntry* dbce,
+ CollectionCatalogEntry* cce,
+ const IndexNameObjs& indexNameObjs) {
+ const std::vector<std::string>& indexNames = indexNameObjs.first;
+ const std::vector<BSONObj>& indexSpecs = indexNameObjs.second;
+
// Skip the rest if there are no indexes to rebuild.
if (indexSpecs.empty())
return Status::OK();
@@ -211,7 +229,6 @@ Status rebuildIndexesOnCollection(OperationContext* opCtx,
return Status::OK();
}
-} // namespace
Status repairDatabase(OperationContext* opCtx,
StorageEngine* engine,
@@ -283,7 +300,12 @@ Status repairDatabase(OperationContext* opCtx,
if (!status.isOK())
return status;
- status = rebuildIndexesOnCollection(opCtx, dbce, *it);
+ CollectionCatalogEntry* cce = dbce->getCollectionCatalogEntry(*it);
+ auto swIndexNameObjs = getIndexNameObjs(opCtx, dbce, cce);
+ if (!swIndexNameObjs.isOK())
+ return swIndexNameObjs.getStatus();
+
+ status = rebuildIndexesOnCollection(opCtx, dbce, cce, swIndexNameObjs.getValue());
if (!status.isOK())
return status;