summaryrefslogtreecommitdiff
path: root/src/mongo/client
diff options
context:
space:
mode:
authorLingzhi Deng <lingzhi.deng@mongodb.com>2020-01-14 19:14:39 +0000
committerevergreen <evergreen@mongodb.com>2020-01-14 19:14:39 +0000
commite48ee34609cd5450edf1a3de8a8f75ae55db3f34 (patch)
treea73811435dac62e484987e981aecf5860330293d /src/mongo/client
parent1878d44a2ac3764d71f00e8ce04ecb9911ab6023 (diff)
downloadmongo-e48ee34609cd5450edf1a3de8a8f75ae55db3f34.tar.gz
SERVER-45557: DBClientCursor should call metadataReader once per batch
Diffstat (limited to 'src/mongo/client')
-rw-r--r--src/mongo/client/dbclient_cursor.cpp6
-rw-r--r--src/mongo/client/dbclient_cursor_test.cpp45
2 files changed, 45 insertions, 6 deletions
diff --git a/src/mongo/client/dbclient_cursor.cpp b/src/mongo/client/dbclient_cursor.cpp
index fe677d9f00c..244e893f88b 100644
--- a/src/mongo/client/dbclient_cursor.cpp
+++ b/src/mongo/client/dbclient_cursor.cpp
@@ -310,12 +310,6 @@ BSONObj DBClientCursor::commandDataReceived(const Message& reply) {
wasError = true;
}
- auto opCtx = haveClient() ? cc().getOperationContext() : nullptr;
- if (_client->getReplyMetadataReader()) {
- uassertStatusOK(_client->getReplyMetadataReader()(
- opCtx, commandReply->getCommandReply(), _client->getServerAddress()));
- }
-
return commandReply->getCommandReply().getOwned();
}
diff --git a/src/mongo/client/dbclient_cursor_test.cpp b/src/mongo/client/dbclient_cursor_test.cpp
index 9df9dd01405..d4cf194caba 100644
--- a/src/mongo/client/dbclient_cursor_test.cpp
+++ b/src/mongo/client/dbclient_cursor_test.cpp
@@ -146,6 +146,51 @@ protected:
}
};
+TEST_F(DBClientCursorTest, DBClientCursorCallsMetaDataReaderOncePerBatch) {
+ // Set up the DBClientCursor and a mock client connection.
+ DBClientConnectionForTest conn;
+ const NamespaceString nss("test", "coll");
+ DBClientCursor cursor(&conn, NamespaceStringOrUUID(nss), Query().obj, 0, 0, nullptr, 0, 0);
+ cursor.setBatchSize(2);
+
+ // Set up mock 'find' response.
+ const long long cursorId = 42;
+ Message findResponseMsg = mockFindResponse(nss, cursorId, {docObj(1), docObj(2)});
+ conn.setCallResponse(findResponseMsg);
+
+ int numMetaRead = 0;
+ conn.setReplyMetadataReader(
+ [&](OperationContext* opCtx, const BSONObj& metadataObj, StringData target) {
+ numMetaRead++;
+ return Status::OK();
+ });
+
+ // Trigger a find command.
+ ASSERT(cursor.init());
+
+ // First batch from the initial find command.
+ ASSERT_BSONOBJ_EQ(docObj(1), cursor.next());
+ ASSERT_BSONOBJ_EQ(docObj(2), cursor.next());
+ ASSERT_FALSE(cursor.moreInCurrentBatch());
+ // Test that the metadata reader callback is called once.
+ ASSERT_EQ(1, numMetaRead);
+
+ // Set a terminal getMore response with cursorId 0.
+ auto getMoreResponseMsg = mockGetMoreResponse(nss, 0, {docObj(3), docObj(4)});
+ conn.setCallResponse(getMoreResponseMsg);
+
+ // Trigger a subsequent getMore command.
+ ASSERT_TRUE(cursor.more());
+
+ // Second batch from the getMore command.
+ ASSERT_BSONOBJ_EQ(docObj(3), cursor.next());
+ ASSERT_BSONOBJ_EQ(docObj(4), cursor.next());
+ ASSERT_FALSE(cursor.moreInCurrentBatch());
+ ASSERT_TRUE(cursor.isDead());
+ // Test that the metadata reader callback is called twice.
+ ASSERT_EQ(2, numMetaRead);
+}
+
TEST_F(DBClientCursorTest, DBClientCursorHandlesOpMsgExhaustCorrectly) {
// Set up the DBClientCursor and a mock client connection.