diff options
author | James Wahlin <james@mongodb.com> | 2019-02-08 08:43:44 -0500 |
---|---|---|
committer | James Wahlin <james@mongodb.com> | 2019-02-08 08:43:44 -0500 |
commit | 87ea6539360b6003aa75a1f40c0e294a8ae4a359 (patch) | |
tree | 252d0e9e53c3805168142326fa29f7fc1d137632 /src/mongo | |
parent | 4da738debb1aea49524ff8e364254afb5bfda612 (diff) | |
download | mongo-87ea6539360b6003aa75a1f40c0e294a8ae4a359.tar.gz |
Revert "SERVER-39149 Homogenize getMore behavior"
This reverts commit 4d703e26c2801971d538f948a4dc3191994f0074.
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/commands/getmore_cmd.cpp | 35 | ||||
-rw-r--r-- | src/mongo/db/query/find.cpp | 51 | ||||
-rw-r--r-- | src/mongo/db/query/find_common.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/query/find_common.h | 8 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_find.cpp | 8 |
5 files changed, 29 insertions, 75 deletions
diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp index 43f78ec6484..8db406d77e2 100644 --- a/src/mongo/db/commands/getmore_cmd.cpp +++ b/src/mongo/db/commands/getmore_cmd.cpp @@ -72,6 +72,8 @@ namespace { MONGO_FAIL_POINT_DEFINE(rsStopGetMoreCmd); +MONGO_FAIL_POINT_DEFINE(waitWithPinnedCursorDuringGetMoreBatch); + /** * Validates that the lsid of 'opCtx' matches that of 'cursor'. This must be called after * authenticating, so that it is safe to report the lsid of 'cursor'. @@ -338,6 +340,26 @@ public: readLock.emplace(opCtx, _request.nss); }; + // If the 'waitAfterPinningCursorBeforeGetMoreBatch' fail point is enabled, set the + // 'msg' field of this operation's CurOp to signal that we've hit this point and then + // repeatedly release and re-acquire the collection readLock at regular intervals until + // the failpoint is released. This is done in order to avoid deadlocks caused by the + // pinned-cursor failpoints in this file (see SERVER-21997). + MONGO_FAIL_POINT_BLOCK(waitAfterPinningCursorBeforeGetMoreBatch, options) { + const BSONObj& data = options.getData(); + if (data["shouldNotdropLock"].booleanSafe()) { + dropAndReaquireReadLock = []() {}; + } + + CurOpFailpointHelpers::waitWhileFailPointEnabled( + &waitAfterPinningCursorBeforeGetMoreBatch, + opCtx, + "waitAfterPinningCursorBeforeGetMoreBatch", + dropAndReaquireReadLock, + false, + _request.nss); + } + // A user can only call getMore on their own cursor. If there were multiple users // authenticated when the cursor was created, then at least one of them must be // authenticated in order to run getMore on the cursor. @@ -378,19 +400,6 @@ public: // On early return, get rid of the cursor. auto cursorFreer = makeGuard([&] { cursorPin.deleteUnderlying(); }); - // If the 'waitAfterPinningCursorBeforeGetMoreBatch' fail point is enabled, set the - // 'msg' field of this operation's CurOp to signal that we've hit this point and then - // repeatedly release and re-acquire the collection readLock at regular intervals until - // the failpoint is released. This is done in order to avoid deadlocks caused by the - // pinned-cursor failpoints in this file (see SERVER-21997). - if (MONGO_FAIL_POINT(waitAfterPinningCursorBeforeGetMoreBatch)) { - CurOpFailpointHelpers::waitWhileFailPointEnabled( - &waitAfterPinningCursorBeforeGetMoreBatch, - opCtx, - "waitAfterPinningCursorBeforeGetMoreBatch", - dropAndReaquireReadLock); - } - // We must respect the read concern from the cursor. applyCursorReadConcern(opCtx, cursorPin->getReadConcernArgs()); diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp index 97905e0cdda..da3ff98fb0c 100644 --- a/src/mongo/db/query/find.cpp +++ b/src/mongo/db/query/find.cpp @@ -353,31 +353,6 @@ Message getMore(OperationContext* opCtx, *isCursorAuthorized = true; - // Only used by the failpoints. - const auto dropAndReaquireReadLock = [&] { - // Make sure an interrupted operation does not prevent us from reacquiring the lock. - UninterruptibleLockGuard noInterrupt(opCtx->lockState()); - - readLock.reset(); - readLock.emplace(opCtx, NamespaceString(ns)); - }; - - // On early return, get rid of the cursor. - auto cursorFreer = makeGuard([&] { cursorPin.deleteUnderlying(); }); - - // If the 'waitAfterPinningCursorBeforeGetMoreBatch' fail point is enabled, set the - // 'msg' field of this operation's CurOp to signal that we've hit this point and then - // repeatedly release and re-acquire the collection readLock at regular intervals until - // the failpoint is released. This is done in order to avoid deadlocks caused by the - // pinned-cursor failpoints in this file (see SERVER-21997). - if (MONGO_FAIL_POINT(waitAfterPinningCursorBeforeGetMoreBatch)) { - CurOpFailpointHelpers::waitWhileFailPointEnabled(&waitAfterPinningCursorBeforeGetMoreBatch, - opCtx, - "waitAfterPinningCursorBeforeGetMoreBatch", - dropAndReaquireReadLock); - } - - const auto replicationMode = repl::ReplicationCoordinator::get(opCtx)->getReplicationMode(); if (replicationMode == repl::ReplicationCoordinator::modeReplSet && @@ -446,11 +421,9 @@ Message getMore(OperationContext* opCtx, // accumulate over the course of a cursor's lifetime. PlanSummaryStats preExecutionStats; Explain::getSummaryStats(*exec, &preExecutionStats); - if (MONGO_FAIL_POINT(waitWithPinnedCursorDuringGetMoreBatch)) { - CurOpFailpointHelpers::waitWhileFailPointEnabled(&waitWithPinnedCursorDuringGetMoreBatch, - opCtx, - "waitWithPinnedCursorDuringGetMoreBatch", - nullptr); + if (MONGO_FAIL_POINT(legacyGetMoreWaitWithCursor)) { + CurOpFailpointHelpers::waitWhileFailPointEnabled( + &legacyGetMoreWaitWithCursor, opCtx, "legacyGetMoreWaitWithCursor", nullptr); } generateBatch(ntoreturn, cursorPin.getCursor(), &bb, &numResults, &state); @@ -505,6 +478,8 @@ Message getMore(OperationContext* opCtx, // ClientCursorPin is declared after our lock is declared, this will happen under the lock if // any locking was necessary. if (!shouldSaveCursorGetMore(state, exec, cursorPin->isTailable())) { + cursorPin.deleteUnderlying(); + // cc is now invalid, as is the executor cursorid = 0; curOp.debug().cursorExhausted = true; @@ -512,7 +487,6 @@ Message getMore(OperationContext* opCtx, LOG(5) << "getMore NOT saving client cursor, ended with state " << PlanExecutor::statestr(state); } else { - cursorFreer.dismiss(); // Continue caching the ClientCursor. cursorPin->incNReturnedSoFar(numResults); cursorPin->incNBatches(); @@ -531,18 +505,6 @@ Message getMore(OperationContext* opCtx, } } - // We're about to unpin or delete the cursor as the ClientCursorPin goes out of scope. - // If the 'waitBeforeUnpinningOrDeletingCursorAfterGetMoreBatch' failpoint is active, we - // set the 'msg' field of this operation's CurOp to signal that we've hit this point and - // then spin until the failpoint is released. - if (MONGO_FAIL_POINT(waitBeforeUnpinningOrDeletingCursorAfterGetMoreBatch)) { - CurOpFailpointHelpers::waitWhileFailPointEnabled( - &waitBeforeUnpinningOrDeletingCursorAfterGetMoreBatch, - opCtx, - "waitBeforeUnpinningOrDeletingCursorAfterGetMoreBatch", - dropAndReaquireReadLock); - } - QueryResult::View qr = bb.buf(); qr.msgdata().setLen(bb.len()); qr.msgdata().setOperation(opReply); @@ -642,9 +604,6 @@ std::string runQuery(OperationContext* opCtx, } opCtx->checkForInterrupt(); // May trigger maxTimeAlwaysTimeOut fail point. - CurOpFailpointHelpers::waitWhileFailPointEnabled( - &waitInFindBeforeMakingBatch, opCtx, "waitInFindBeforeMakingBatch"); - // Run the query. // bb is used to hold query results // this buffer should contain either requested documents per query or diff --git a/src/mongo/db/query/find_common.cpp b/src/mongo/db/query/find_common.cpp index e74d9594a9c..e86695959ab 100644 --- a/src/mongo/db/query/find_common.cpp +++ b/src/mongo/db/query/find_common.cpp @@ -45,8 +45,6 @@ MONGO_FAIL_POINT_DEFINE(disableAwaitDataForGetMoreCmd); MONGO_FAIL_POINT_DEFINE(waitAfterPinningCursorBeforeGetMoreBatch); -MONGO_FAIL_POINT_DEFINE(waitWithPinnedCursorDuringGetMoreBatch); - MONGO_FAIL_POINT_DEFINE(waitBeforeUnpinningOrDeletingCursorAfterGetMoreBatch); const OperationContext::Decoration<AwaitDataState> awaitDataState = diff --git a/src/mongo/db/query/find_common.h b/src/mongo/db/query/find_common.h index ca4111dd754..4dfa751a110 100644 --- a/src/mongo/db/query/find_common.h +++ b/src/mongo/db/query/find_common.h @@ -63,15 +63,11 @@ MONGO_FAIL_POINT_DECLARE(waitInFindBeforeMakingBatch); // tests. MONGO_FAIL_POINT_DECLARE(disableAwaitDataForGetMoreCmd); -// Enabling this fail point will cause getMores to busy wait after pinning the cursor +// Enabling this fail point will cause the getMore command to busy wait after pinning the cursor // but before we have started building the batch, until the fail point is disabled. MONGO_FAIL_POINT_DECLARE(waitAfterPinningCursorBeforeGetMoreBatch); -// Enabling this fail point will cause getMores to busy wait after setting up the plan executor and -// before beginning the batch. -MONGO_FAIL_POINT_DECLARE(waitWithPinnedCursorDuringGetMoreBatch); - -// Enabling this failpoint will cause getMores to wait just before it unpins its cursor after it +// Enabling this failpoint will cause the getMore to wait just before it unpins its cursor after it // has completed building the current batch. MONGO_FAIL_POINT_DECLARE(waitBeforeUnpinningOrDeletingCursorAfterGetMoreBatch); diff --git a/src/mongo/s/query/cluster_find.cpp b/src/mongo/s/query/cluster_find.cpp index 29392c0b07e..e9f55a271e6 100644 --- a/src/mongo/s/query/cluster_find.cpp +++ b/src/mongo/s/query/cluster_find.cpp @@ -598,14 +598,6 @@ StatusWith<CursorResponse> ClusterFind::runGetMore(OperationContext* opCtx, BSONObj postBatchResumeToken; bool stashedResult = false; - // If the 'waitWithPinnedCursorDuringGetMoreBatch' fail point is enabled, set the 'msg' - // field of this operation's CurOp to signal that we've hit this point. - if (MONGO_FAIL_POINT(waitWithPinnedCursorDuringGetMoreBatch)) { - CurOpFailpointHelpers::waitWhileFailPointEnabled(&waitWithPinnedCursorDuringGetMoreBatch, - opCtx, - "waitWithPinnedCursorDuringGetMoreBatch"); - } - while (!FindCommon::enoughForGetMore(batchSize, batch.size())) { auto context = batch.empty() ? RouterExecStage::ExecContext::kGetMoreNoResultsYet |