summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLingzhi Deng <lingzhi.deng@mongodb.com>2020-08-07 11:34:49 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-24 18:31:14 +0000
commite161282063c7ab698982dba88e5514dc9faf0cc9 (patch)
treecb3bd0fe3c2b4dd26312e8516efb06fb6d35358f
parentd4b960b5f3f4a7a2b18b48d7fb14251704a8bda8 (diff)
downloadmongo-e161282063c7ab698982dba88e5514dc9faf0cc9.tar.gz
SERVER-50063: Consolidate OplogFetcher return code to CallbackCanceled when shutting down
(cherry picked from commit a12299145c35b0cebea60f303613f85472b2915f)
-rw-r--r--src/mongo/db/repl/oplog_fetcher.cpp6
-rw-r--r--src/mongo/db/repl/oplog_fetcher_test.cpp23
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,