diff options
author | Geert Bosch <geert@mongodb.com> | 2018-07-08 20:37:53 -0400 |
---|---|---|
committer | Geert Bosch <geert@mongodb.com> | 2018-09-10 18:36:19 -0400 |
commit | e2be5a4e3684daf2410e4d5e31439c9669a38e6d (patch) | |
tree | 92dc24f4d7b5637ed44c8c58bdc7f4aad0ed0d74 /src/mongo/db/repair_database.cpp | |
parent | 1070aa3880ac73bc1923b44a372c61c209a35f61 (diff) | |
download | mongo-e2be5a4e3684daf2410e4d5e31439c9669a38e6d.tar.gz |
SERVER-36014 Remove support for IndexVersion V0
Diffstat (limited to 'src/mongo/db/repair_database.cpp')
-rw-r--r-- | src/mongo/db/repair_database.cpp | 80 |
1 files changed, 43 insertions, 37 deletions
diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp index cad01ba9990..9b64c6eaf3b 100644 --- a/src/mongo/db/repair_database.cpp +++ b/src/mongo/db/repair_database.cpp @@ -59,17 +59,12 @@ namespace mongo { -using std::endl; -using std::string; - -using IndexVersion = IndexDescriptor::IndexVersion; - 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<std::string>& indexNames = ret.first; std::vector<BSONObj>& indexSpecs = ret.second; { // Fetch all indexes @@ -82,38 +77,21 @@ StatusWith<IndexNameObjs> getIndexNameObjs(OperationContext* opCtx, indexSpecs.reserve(indexNames.size()); - for (size_t i = 0; i < indexNames.size(); i++) { - const string& name = indexNames[i]; + for (const auto& name : indexNames) { BSONObj spec = cce->getIndexSpec(opCtx, name); - - IndexVersion newIndexVersion = IndexVersion::kV0; - { - BSONObjBuilder bob; - - for (auto&& indexSpecElem : spec) { - auto indexSpecElemFieldName = indexSpecElem.fieldNameStringData(); - if (IndexDescriptor::kIndexVersionFieldName == indexSpecElemFieldName) { - IndexVersion indexVersion = - static_cast<IndexVersion>(indexSpecElem.numberInt()); - if (IndexVersion::kV0 == indexVersion) { - // We automatically upgrade v=0 indexes to v=1 indexes. - newIndexVersion = IndexVersion::kV1; - } else { - newIndexVersion = indexVersion; - } - - bob.append(IndexDescriptor::kIndexVersionFieldName, - static_cast<int>(newIndexVersion)); - } else { - bob.append(indexSpecElem); - } - } - - indexSpecs.push_back(bob.obj()); + using IndexVersion = IndexDescriptor::IndexVersion; + IndexVersion indexVersion = IndexVersion::kV1; + if (auto indexVersionElem = spec[IndexDescriptor::kIndexVersionFieldName]) { + auto indexVersionNum = indexVersionElem.numberInt(); + invariant(indexVersionNum == static_cast<int>(IndexVersion::kV1) || + indexVersionNum == static_cast<int>(IndexVersion::kV2)); + indexVersion = static_cast<IndexVersion>(indexVersionNum); } + invariant(spec.isOwned()); + indexSpecs.push_back(spec); const BSONObj key = spec.getObjectField("key"); - const Status keyStatus = index_key_validate::validateKeyPattern(key, newIndexVersion); + const Status keyStatus = index_key_validate::validateKeyPattern(key, indexVersion); if (!keyStatus.isOK()) { return Status( ErrorCodes::CannotCreateIndex, @@ -285,9 +263,9 @@ Status repairDatabase(OperationContext* opCtx, StorageEngine* engine, const std: // We must hold some form of lock here invariant(opCtx->lockState()->isLocked()); - invariant(dbName.find('.') == string::npos); + invariant(dbName.find('.') == std::string::npos); - log() << "repairDatabase " << dbName << endl; + log() << "repairDatabase " << dbName; BackgroundOperation::assertNoBgOpInProgForDb(dbName); @@ -326,6 +304,34 @@ Status repairDatabase(OperationContext* opCtx, StorageEngine* engine, const std: return status; } + DatabaseCatalogEntry* dbce = engine->getDatabaseCatalogEntry(opCtx, dbName); + + std::list<std::string> colls; + dbce->getCollectionNamespaces(&colls); + + for (std::list<std::string>::const_iterator it = colls.begin(); it != colls.end(); ++it) { + // Don't check for interrupt after starting to repair a collection otherwise we can + // leave data in an inconsistent state. Interrupting between collections is ok, however. + opCtx->checkForInterrupt(); + + log() << "Repairing collection " << *it; + + Status status = engine->repairRecordStore(opCtx, *it); + if (!status.isOK()) + return status; + + 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; + + engine->flushAllFiles(opCtx, true); + } + return Status::OK(); } -} +} // namespace mongo |