From e161282063c7ab698982dba88e5514dc9faf0cc9 Mon Sep 17 00:00:00 2001 From: Lingzhi Deng Date: Fri, 7 Aug 2020 11:34:49 -0400 Subject: SERVER-50063: Consolidate OplogFetcher return code to CallbackCanceled when shutting down (cherry picked from commit a12299145c35b0cebea60f303613f85472b2915f) --- src/mongo/db/repl/oplog_fetcher.cpp | 6 ++++++ src/mongo/db/repl/oplog_fetcher_test.cpp | 23 +++++++---------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/mongo/db/repl/oplog_fetcher.cpp b/src/mongo/db/repl/oplog_fetcher.cpp index 09e00a383d7..9c3c09186f0 100644 --- a/src/mongo/db/repl/oplog_fetcher.cpp +++ b/src/mongo/db/repl/oplog_fetcher.cpp @@ -409,6 +409,12 @@ Milliseconds OplogFetcher::_getRetriedFindMaxTime() const { void OplogFetcher::_finishCallback(Status status) { invariant(isActive()); + // If the oplog fetcher is shutting down, consolidate return code to CallbackCanceled. + if (_isShuttingDown() && status != ErrorCodes::CallbackCanceled) { + status = Status(ErrorCodes::CallbackCanceled, + str::stream() << "Got error: \"" << status.toString() + << "\" while oplog fetcher is shutting down"); + } _onShutdownCallbackFn(status); decltype(_onShutdownCallbackFn) onShutdownCallbackFn; diff --git a/src/mongo/db/repl/oplog_fetcher_test.cpp b/src/mongo/db/repl/oplog_fetcher_test.cpp index 3fea1e0319f..c539323d477 100644 --- a/src/mongo/db/repl/oplog_fetcher_test.cpp +++ b/src/mongo/db/repl/oplog_fetcher_test.cpp @@ -570,32 +570,21 @@ TEST_F(OplogFetcherTest, OplogFetcherReturnsCallbackCanceledIfShutdownBeforeRunQ } TEST_F(OplogFetcherTest, OplogFetcherReturnsCallbackCanceledIfShutdownAfterRunQueryScheduled) { - // Tests shutting down after _runQuery is scheduled (but not while blocked on the network). + // Tests shutting down after _runQuery is scheduled. ShutdownState shutdownState; - auto waitForCallbackScheduledFailPoint = - globalFailPointRegistry().find("hangAfterOplogFetcherCallbackScheduled"); - auto timesEnteredFailPoint = waitForCallbackScheduledFailPoint->setMode(FailPoint::alwaysOn, 0); - // This will also ensure that _runQuery was scheduled before returning. auto oplogFetcher = getOplogFetcherAfterConnectionCreated(std::ref(shutdownState)); - waitForCallbackScheduledFailPoint->waitForTimesEntered(timesEnteredFailPoint + 1); - - // Only call shutdown once we have confirmed that the callback is paused at the fail point. oplogFetcher->shutdown(); - // Unpause the oplog fetcher. - waitForCallbackScheduledFailPoint->setMode(FailPoint::off); - oplogFetcher->join(); ASSERT_EQUALS(ErrorCodes::CallbackCanceled, shutdownState.getStatus()); } -TEST_F(OplogFetcherTest, - OplogFetcherReturnsHostUnreachableIfShutdownAfterRunQueryScheduledWhileBlockedOnCall) { +TEST_F(OplogFetcherTest, OplogFetcherShutsDownConnectionIfShutdownWhileBlockedOnCall) { // Tests that shutting down while the connection is blocked on call successfully shuts down the // connection as well. @@ -614,8 +603,10 @@ TEST_F(OplogFetcherTest, oplogFetcher->join(); - // This is the error that the connection throws if shutdown while blocked on the network. - ASSERT_EQUALS(ErrorCodes::HostUnreachable, shutdownState.getStatus()); + // This is the error message that the connection throws if shutdown while blocked on the + // network. + ASSERT_EQUALS(ErrorCodes::CallbackCanceled, shutdownState.getStatus()); + ASSERT_STRING_CONTAINS(shutdownState.getStatus().reason(), "Socket was shut down"); } TEST_F(OplogFetcherTest, @@ -1513,7 +1504,7 @@ TEST_F(OplogFetcherTest, OplogFetcherShouldExcludeFirstDocumentInFirstBatchWhenE ASSERT_EQUALS(unittest::assertGet(OpTime::parseFromOplogEntry(thirdEntry)), lastEnqueuedDocumentsInfo.lastDocument); - ASSERT_EQUALS(ErrorCodes::HostUnreachable, shutdownState->getStatus()); + ASSERT_EQUALS(ErrorCodes::CallbackCanceled, shutdownState->getStatus()); } TEST_F(OplogFetcherTest, -- cgit v1.2.1