diff options
Diffstat (limited to 'src/mongo/db/curop_failpoint_helpers.cpp')
-rw-r--r-- | src/mongo/db/curop_failpoint_helpers.cpp | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/src/mongo/db/curop_failpoint_helpers.cpp b/src/mongo/db/curop_failpoint_helpers.cpp index 6afbfb05be5..5f2a4190de7 100644 --- a/src/mongo/db/curop_failpoint_helpers.cpp +++ b/src/mongo/db/curop_failpoint_helpers.cpp @@ -47,42 +47,44 @@ std::string CurOpFailpointHelpers::updateCurOpMsg(OperationContext* opCtx, void CurOpFailpointHelpers::waitWhileFailPointEnabled(FailPoint* failPoint, OperationContext* opCtx, const std::string& curOpMsg, - const std::function<void(void)>& whileWaiting, + const std::function<void()>& whileWaiting, bool checkForInterrupt, boost::optional<NamespaceString> nss) { - invariant(failPoint); - MONGO_FAIL_POINT_BLOCK((*failPoint), options) { - const BSONObj& data = options.getData(); - StringData fpNss = data.getStringField("nss"); - if (nss && !fpNss.empty() && fpNss != nss.get().toString()) { - return; - } + failPoint->executeIf( + [&](const BSONObj& data) { + auto origCurOpMsg = updateCurOpMsg(opCtx, curOpMsg); - auto origCurOpMsg = updateCurOpMsg(opCtx, curOpMsg); + const bool shouldCheckForInterrupt = + checkForInterrupt || data["shouldCheckForInterrupt"].booleanSafe(); + const bool shouldContinueOnInterrupt = data["shouldContinueOnInterrupt"].booleanSafe(); + while (MONGO_unlikely(failPoint->shouldFail())) { + sleepFor(Milliseconds(10)); + if (whileWaiting) { + whileWaiting(); + } - const bool shouldCheckForInterrupt = - checkForInterrupt || data["shouldCheckForInterrupt"].booleanSafe(); - const bool shouldContinueOnInterrupt = data["shouldContinueOnInterrupt"].booleanSafe(); - while (MONGO_FAIL_POINT((*failPoint))) { - sleepFor(Milliseconds(10)); - if (whileWaiting) { - whileWaiting(); + // Check for interrupt so that an operation can be killed while waiting for the + // failpoint to be disabled, if the failpoint is configured to be interruptible. + // + // For shouldContinueOnInterrupt, an interrupt merely allows the code to continue + // past the failpoint; it is up to the code under test to actually check for + // interrupt. + if (shouldContinueOnInterrupt) { + if (!opCtx->checkForInterruptNoAssert().isOK()) + break; + } else if (shouldCheckForInterrupt) { + opCtx->checkForInterrupt(); + } } - - // Check for interrupt so that an operation can be killed while waiting for the - // failpoint to be disabled, if the failpoint is configured to be interruptible. - // - // For shouldContinueOnInterrupt, an interrupt merely allows the code to continue past - // the failpoint; it is up to the code under test to actually check for interrupt. - if (shouldContinueOnInterrupt) { - if (!opCtx->checkForInterruptNoAssert().isOK()) - break; - } else if (shouldCheckForInterrupt) { - opCtx->checkForInterrupt(); + updateCurOpMsg(opCtx, origCurOpMsg); + }, + [&](const BSONObj& data) { + StringData fpNss = data.getStringField("nss"); + if (nss && !fpNss.empty() && fpNss != nss.get().toString()) { + return false; } - } - updateCurOpMsg(opCtx, origCurOpMsg); - } + return true; + }); } } // namespace mongo |