diff --git a/src/mongo/db/pipeline/expression_context.cpp b/src/mongo/db/pipeline/expression_context.cpp index 417e02815d..a2d66d942f 100644 --- a/src/mongo/db/pipeline/expression_context.cpp +++ b/src/mongo/db/pipeline/expression_context.cpp @@ -159,13 +159,11 @@ ExpressionContext::ExpressionContext( variables.seedVariablesWithLetParameters(this, *letParameters); } -void ExpressionContext::checkForInterrupt() { +void ExpressionContext::checkForInterruptSlow() { // This check could be expensive, at least in relative terms, so don't check every time. - if (--_interruptCounter == 0) { - invariant(opCtx); - _interruptCounter = kInterruptCheckPeriod; - opCtx->checkForInterrupt(); - } + invariant(opCtx); + _interruptCounter = kInterruptCheckPeriod; + opCtx->checkForInterrupt(); } ExpressionContext::CollatorStash::CollatorStash(ExpressionContext* const expCtx, diff --git a/src/mongo/db/pipeline/expression_context.h b/src/mongo/db/pipeline/expression_context.h index 33696061ec..f3a43208a6 100644 --- a/src/mongo/db/pipeline/expression_context.h +++ b/src/mongo/db/pipeline/expression_context.h @@ -151,7 +151,11 @@ public: * Used by a pipeline to check for interrupts so that killOp() works. Throws a UserAssertion if * this aggregation pipeline has been interrupted. */ - void checkForInterrupt(); + void checkForInterrupt() { + if (--_interruptCounter == 0) { + checkForInterruptSlow(); + } + } /** * Returns true if this is a collectionless aggregation on the specified database. @@ -375,6 +379,8 @@ protected: friend class CollatorStash; + void checkForInterruptSlow(); + // Collator used for comparisons. std::unique_ptr _collator;