summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r--src/mongo/db/repl/oplog_fetcher.cpp5
-rw-r--r--src/mongo/db/repl/oplog_fetcher_test.cpp34
2 files changed, 36 insertions, 3 deletions
diff --git a/src/mongo/db/repl/oplog_fetcher.cpp b/src/mongo/db/repl/oplog_fetcher.cpp
index bc23fa0d029..087bb34bbaa 100644
--- a/src/mongo/db/repl/oplog_fetcher.cpp
+++ b/src/mongo/db/repl/oplog_fetcher.cpp
@@ -959,9 +959,8 @@ StatusWith<NewOplogFetcher::Documents> NewOplogFetcher::_getNextBatch() {
// The 'find' command has already been executed, so reset the socket timeout to reflect
// the awaitData timeout with a network buffer.
_setSocketTimeout(durationCount<Milliseconds>(_awaitDataTimeout));
- } else if (!_cursor->more()) {
- // The only reason more() should return false is if the cursor is dead.
- invariant(_cursor->isDead());
+ } else {
+ _cursor->more();
}
while (_cursor->moreInCurrentBatch()) {
diff --git a/src/mongo/db/repl/oplog_fetcher_test.cpp b/src/mongo/db/repl/oplog_fetcher_test.cpp
index 172f4d6c182..ed5c69a4b0f 100644
--- a/src/mongo/db/repl/oplog_fetcher_test.cpp
+++ b/src/mongo/db/repl/oplog_fetcher_test.cpp
@@ -1236,6 +1236,10 @@ void NewOplogFetcherTest::setUp() {
auto target = HostAndPort{"localhost:12346"};
_mockServer = std::make_unique<MockRemoteDBServer>(target.toString());
+
+ // Always enable oplogFetcherUsesExhaust at the beginning of each unittest in case some
+ // unittests disable it in the test.
+ oplogFetcherUsesExhaust = true;
}
std::unique_ptr<NewOplogFetcher> NewOplogFetcherTest::makeOplogFetcher() {
@@ -2687,4 +2691,34 @@ TEST_F(NewOplogFetcherTest, DisconnectsOnErrorsDuringExhaustStream) {
ASSERT_OK(shutdownState.getStatus());
}
+
+TEST_F(NewOplogFetcherTest, GetMoreEmptyBatch) {
+ ShutdownState shutdownState;
+
+ // Create an oplog fetcher without any retries.
+ auto oplogFetcher = getOplogFetcherAfterConnectionCreated(std::ref(shutdownState));
+
+ CursorId cursorId = 22LL;
+ auto firstEntry = makeNoopOplogEntry(lastFetched);
+ auto metadataObj = makeOplogBatchMetadata(boost::none, staleOqMetadata);
+
+ auto conn = oplogFetcher->getDBClientConnection_forTest();
+
+ // Creating the cursor will succeed.
+ auto m =
+ processSingleRequestResponse(conn, makeFirstBatch(cursorId, {firstEntry}, metadataObj));
+
+ // Empty batch from first getMore.
+ processSingleRequestResponse(
+ conn, makeSubsequentBatch(cursorId, {}, metadataObj, true /* moreToCome */));
+
+ // Terminating empty batch from exhaust stream with cursorId 0.
+ processSingleExhaustResponse(oplogFetcher->getDBClientConnection_forTest(),
+ makeSubsequentBatch(0LL, {}, metadataObj, false /* moreToCome */),
+ false);
+
+ oplogFetcher->join();
+
+ ASSERT_OK(shutdownState.getStatus());
+}
} // namespace