diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2020-08-05 13:45:52 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-05 17:59:52 +0000 |
commit | c3421443d50acfb81ee299bf5eff6e14879591f3 (patch) | |
tree | 7d28ca9c606c4d81b8a16103076170ffb474e1da /src/mongo/db/catalog/multi_index_block.cpp | |
parent | fd109f08f97117237dae3a9428c3d2d66f14e221 (diff) | |
download | mongo-c3421443d50acfb81ee299bf5eff6e14879591f3.tar.gz |
SERVER-49448 Interrupt index builds for shutdown during the expected phase in resumable index build tests
Diffstat (limited to 'src/mongo/db/catalog/multi_index_block.cpp')
-rw-r--r-- | src/mongo/db/catalog/multi_index_block.cpp | 70 |
1 files changed, 45 insertions, 25 deletions
diff --git a/src/mongo/db/catalog/multi_index_block.cpp b/src/mongo/db/catalog/multi_index_block.cpp index c9ba79ec06e..4bf146c8b7e 100644 --- a/src/mongo/db/catalog/multi_index_block.cpp +++ b/src/mongo/db/catalog/multi_index_block.cpp @@ -72,6 +72,38 @@ MONGO_FAIL_POINT_DEFINE(hangIndexBuildDuringCollectionScanPhaseBeforeInsertion); MONGO_FAIL_POINT_DEFINE(hangIndexBuildDuringCollectionScanPhaseAfterInsertion); MONGO_FAIL_POINT_DEFINE(leaveIndexBuildUnfinishedForShutdown); +namespace { + +void failPointHangDuringBuild(OperationContext* opCtx, + FailPoint* fp, + StringData where, + const BSONObj& doc, + unsigned long long iteration) { + fp->executeIf( + [=, &doc](const BSONObj& data) { + LOGV2(20386, + "Hanging index build during collection scan phase insertion", + "where"_attr = where, + "doc"_attr = doc); + + fp->pauseWhileSet(opCtx); + }, + [&doc, iteration](const BSONObj& data) { + if (data.hasField("iteration")) { + return iteration == static_cast<unsigned long long>(data["iteration"].numberLong()); + } + + auto fieldsToMatch = data.getObjectField("fieldsToMatch"); + return std::all_of( + fieldsToMatch.begin(), fieldsToMatch.end(), [&doc](const auto& elem) { + return SimpleBSONElementComparator::kInstance.evaluate(elem == + doc[elem.fieldName()]); + }); + }); +} + +} // namespace + MultiIndexBlock::~MultiIndexBlock() { invariant(_buildIsCleanedUp); } @@ -172,7 +204,9 @@ StatusWith<std::vector<BSONObj>> MultiIndexBlock::init( invariant(_indexes.empty()); - if (resumeInfo) { + // TODO (SERVER-49409): Resume from the collection scan phase. + // TODO (SERVER-49408): Resume from the bulk load phase. + if (resumeInfo && resumeInfo->getPhase() == IndexBuildPhaseEnum::kDrainWrites) { _phase = resumeInfo->getPhase(); } @@ -338,26 +372,6 @@ StatusWith<std::vector<BSONObj>> MultiIndexBlock::init( } } -void failPointHangDuringBuild(FailPoint* fp, StringData where, const BSONObj& doc) { - fp->executeIf( - [&](const BSONObj& data) { - LOGV2(20386, - "Hanging index build during collection scan phase insertion", - "where"_attr = where, - "doc"_attr = doc); - - fp->pauseWhileSet(); - }, - [&doc](const BSONObj& data) { - auto fieldsToMatch = data.getObjectField("fieldsToMatch"); - return std::all_of( - fieldsToMatch.begin(), fieldsToMatch.end(), [&doc](const auto& elem) { - return SimpleBSONElementComparator::kInstance.evaluate(elem == - doc[elem.fieldName()]); - }); - }); -} - Status MultiIndexBlock::insertAllDocumentsInCollection(OperationContext* opCtx, Collection* collection) { invariant(!_buildIsCleanedUp); @@ -445,8 +459,11 @@ Status MultiIndexBlock::insertAllDocumentsInCollection(OperationContext* opCtx, progress->setTotalWhileRunning(collection->numRecords(opCtx)); - failPointHangDuringBuild( - &hangIndexBuildDuringCollectionScanPhaseBeforeInsertion, "before", objToIndex); + failPointHangDuringBuild(opCtx, + &hangIndexBuildDuringCollectionScanPhaseBeforeInsertion, + "before", + objToIndex, + n); // The external sorter is not part of the storage engine and therefore does not need a // WriteUnitOfWork to write keys. @@ -455,8 +472,11 @@ Status MultiIndexBlock::insertAllDocumentsInCollection(OperationContext* opCtx, return ret; } - failPointHangDuringBuild( - &hangIndexBuildDuringCollectionScanPhaseAfterInsertion, "after", objToIndex); + failPointHangDuringBuild(opCtx, + &hangIndexBuildDuringCollectionScanPhaseAfterInsertion, + "after", + objToIndex, + n); // Go to the next document. progress->hit(); |