diff options
author | David Storch <david.storch@mongodb.com> | 2021-10-01 13:24:06 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-01 14:08:31 +0000 |
commit | fe4cf6134b16f102591053d6f4fe11e5cc0eb3ec (patch) | |
tree | 559991d99827a8b3252e2fdfb14b90a548de0793 /src | |
parent | 0950600446ee8030132bacc9c00eb4ebca411500 (diff) | |
download | mongo-fe4cf6134b16f102591053d6f4fe11e5cc0eb3ec.tar.gz |
SERVER-58210 Eliminate unnecessary RPC protocol negotiation code
Diffstat (limited to 'src')
67 files changed, 342 insertions, 696 deletions
diff --git a/src/mongo/bson/SConscript b/src/mongo/bson/SConscript index 17c965ea677..d4156225e85 100644 --- a/src/mongo/bson/SConscript +++ b/src/mongo/bson/SConscript @@ -63,7 +63,7 @@ asioEnv.CppIntegrationTest( LIBDEPS=[ '$BUILD_DIR/mongo/executor/network_interface', '$BUILD_DIR/mongo/executor/network_interface_fixture', - '$BUILD_DIR/mongo/rpc/protocol', + '$BUILD_DIR/mongo/rpc/message', '$BUILD_DIR/mongo/transport/transport_layer_egress_init', ], ) diff --git a/src/mongo/client/async_client.cpp b/src/mongo/client/async_client.cpp index 3fcd468d8d5..1af9070645b 100644 --- a/src/mongo/client/async_client.cpp +++ b/src/mongo/client/async_client.cpp @@ -113,8 +113,9 @@ void AsyncDBClient::_parseIsMasterResponse(BSONObj request, auto responseBody = response->getCommandReply(); uassertStatusOK(getStatusFromCommandResult(responseBody)); - auto protocolSet = uassertStatusOK(rpc::parseProtocolSetFromIsMasterReply(responseBody)); - auto validateStatus = rpc::validateWireVersion(wireSpec->outgoing, protocolSet.version); + auto replyWireVersion = + uassertStatusOK(wire_version::parseWireVersionFromHelloReply(responseBody)); + auto validateStatus = wire_version::validateWireVersion(wireSpec->outgoing, replyWireVersion); if (!validateStatus.isOK()) { LOGV2_WARNING(23741, "Remote host has incompatible wire version: {error}", @@ -128,7 +129,7 @@ void AsyncDBClient::_parseIsMasterResponse(BSONObj request, auto& egressTagManager = executor::EgressTagCloserManager::get(_svcCtx); // Tag outgoing connection so it can be kept open on FCV upgrade if it is not to a // server with a lower binary version. - if (protocolSet.version.maxWireVersion >= wireSpec->outgoing.maxWireVersion) { + if (replyWireVersion.maxWireVersion >= wireSpec->outgoing.maxWireVersion) { pauseBeforeMarkKeepOpen.pauseWhileSet(); egressTagManager.mutateTags( _peer, [](transport::Session::TagMask tags) { return transport::Session::kKeepOpen; }); @@ -140,12 +141,6 @@ void AsyncDBClient::_parseIsMasterResponse(BSONObj request, }); } - auto clientProtocols = rpc::computeProtocolSet(wireSpec->outgoing); - invariant(clientProtocols != rpc::supports::kNone); - boost::optional<rpc::Protocol> protocol = - uassertStatusOK(rpc::negotiate(protocolSet.protocolSet, clientProtocols)); - invariant(protocol && *protocol == rpc::Protocol::kOpMsg); - _compressorManager.clientFinish(responseBody); } diff --git a/src/mongo/client/async_client.h b/src/mongo/client/async_client.h index ce88edb7228..82867a057ff 100644 --- a/src/mongo/client/async_client.h +++ b/src/mongo/client/async_client.h @@ -36,7 +36,6 @@ #include "mongo/executor/network_connection_hook.h" #include "mongo/executor/remote_command_request.h" #include "mongo/executor/remote_command_response.h" -#include "mongo/rpc/protocol.h" #include "mongo/rpc/unique_message.h" #include "mongo/transport/baton.h" #include "mongo/transport/message_compressor_manager.h" diff --git a/src/mongo/client/dbclient_base.cpp b/src/mongo/client/dbclient_base.cpp index 2eecc7ae6ec..c283e338d5f 100644 --- a/src/mongo/client/dbclient_base.cpp +++ b/src/mongo/client/dbclient_base.cpp @@ -117,18 +117,6 @@ enum QueryOptions DBClientBase::_lookupAvailableOptions() { return QueryOptions(0); } -rpc::ProtocolSet DBClientBase::getClientRPCProtocols() const { - return rpc::supports::kOpMsgOnly; -} - -rpc::ProtocolSet DBClientBase::getServerRPCProtocols() const { - return _serverRPCProtocols; -} - -void DBClientBase::_setServerRPCProtocols(rpc::ProtocolSet protocols) { - _serverRPCProtocols = std::move(protocols); -} - void DBClientBase::setRequestMetadataWriter(rpc::RequestMetadataWriter writer) { _metadataWriter = std::move(writer); } @@ -221,17 +209,9 @@ void appendMetadata(OperationContext* opCtx, } // namespace DBClientBase* DBClientBase::runFireAndForgetCommand(OpMsgRequest request) { - // Make sure to reconnect if needed before building our request, since the request depends on - // the negotiated protocol which can change due to a reconnect. + // Make sure to reconnect if needed before building our request. checkConnection(); - if (uassertStatusOK(rpc::negotiate(getClientRPCProtocols(), getServerRPCProtocols())) != - rpc::Protocol::kOpMsg) { - // Other protocols don't support fire-and-forget. Downgrade to two-way command and throw - // away reply. - return runCommandWithTarget(request).second; - } - auto opCtx = haveClient() ? cc().getOperationContext() : nullptr; appendMetadata(opCtx, _metadataWriter, _apiParameters, request); auto requestMsg = request.serialize(); @@ -242,8 +222,7 @@ DBClientBase* DBClientBase::runFireAndForgetCommand(OpMsgRequest request) { std::pair<rpc::UniqueReply, DBClientBase*> DBClientBase::runCommandWithTarget( OpMsgRequest request) { - // Make sure to reconnect if needed before building our request, since the request depends on - // the negotiated protocol which can change due to a reconnect. + // Make sure to reconnect if needed before building our request. checkConnection(); // call() oddly takes this by pointer, so we need to put it on the stack. @@ -251,9 +230,6 @@ std::pair<rpc::UniqueReply, DBClientBase*> DBClientBase::runCommandWithTarget( auto opCtx = haveClient() ? cc().getOperationContext() : nullptr; appendMetadata(opCtx, _metadataWriter, _apiParameters, request); - rpc::Protocol protocol = - uassertStatusOK(rpc::negotiate(getClientRPCProtocols(), getServerRPCProtocols())); - invariant(protocol == rpc::Protocol::kOpMsg); auto requestMsg = request.serialize(); Message replyMsg; diff --git a/src/mongo/client/dbclient_base.h b/src/mongo/client/dbclient_base.h index 5d339afc130..ad86f30a6b9 100644 --- a/src/mongo/client/dbclient_base.h +++ b/src/mongo/client/dbclient_base.h @@ -50,7 +50,6 @@ #include "mongo/rpc/message.h" #include "mongo/rpc/metadata.h" #include "mongo/rpc/op_msg.h" -#include "mongo/rpc/protocol.h" #include "mongo/rpc/unique_message.h" #include "mongo/transport/message_compressor_manager.h" #include "mongo/transport/session.h" @@ -99,9 +98,6 @@ public: virtual std::string getServerAddress() const = 0; - rpc::ProtocolSet getClientRPCProtocols() const; - rpc::ProtocolSet getServerRPCProtocols() const; - /** * Reconnect if needed and allowed. */ @@ -757,11 +753,6 @@ protected: virtual void _auth(const BSONObj& params); /** - * Should be set by subclasses during connection. - */ - void _setServerRPCProtocols(rpc::ProtocolSet serverProtocols); - - /** * Controls how chatty the client is about network errors & such. See log.h. */ const logv2::LogSeverity _logLevel; @@ -781,9 +772,6 @@ private: auth::RunCommandHook _makeAuthRunCommandHook(); - // The rpc protocol the remote server(s) support. - rpc::ProtocolSet _serverRPCProtocols{rpc::supports::kOpMsgOnly}; - rpc::RequestMetadataWriter _metadataWriter; rpc::ReplyMetadataReader _metadataReader; diff --git a/src/mongo/client/dbclient_connection.cpp b/src/mongo/client/dbclient_connection.cpp index 48b7977992c..f896b49ca8f 100644 --- a/src/mongo/client/dbclient_connection.cpp +++ b/src/mongo/client/dbclient_connection.cpp @@ -269,9 +269,6 @@ Status DBClientConnection::connect(const HostAndPort& serverAddress, return connectStatus; } - // Clear the auto-detected protocols from any previous connection. - _setServerRPCProtocols(rpc::supports::kOpMsgOnly); - // NOTE: If the 'applicationName' parameter is a view of the '_applicationName' member, as // happens, for instance, in the call to DBClientConnection::connect from // DBClientConnection::_checkConnection then the following line will invalidate the @@ -297,9 +294,9 @@ Status DBClientConnection::connect(const HostAndPort& serverAddress, return isMasterStatus; } - auto swProtocolSet = rpc::parseProtocolSetFromIsMasterReply(swIsMasterReply.data); - if (!swProtocolSet.isOK()) { - return swProtocolSet.getStatus(); + auto replyWireVersion = wire_version::parseWireVersionFromHelloReply(swIsMasterReply.data); + if (!replyWireVersion.isOK()) { + return replyWireVersion.getStatus(); } { @@ -329,7 +326,7 @@ Status DBClientConnection::connect(const HostAndPort& serverAddress, auto wireSpec = WireSpec::instance().get(); auto validateStatus = - rpc::validateWireVersion(wireSpec->outgoing, swProtocolSet.getValue().version); + wire_version::validateWireVersion(wireSpec->outgoing, replyWireVersion.getValue()); if (!validateStatus.isOK()) { LOGV2_WARNING(20126, "Remote host has incompatible wire version: {error}", @@ -339,15 +336,6 @@ Status DBClientConnection::connect(const HostAndPort& serverAddress, return validateStatus; } - _setServerRPCProtocols(swProtocolSet.getValue().protocolSet); - - auto negotiatedProtocol = - rpc::negotiate(getServerRPCProtocols(), rpc::computeProtocolSet(wireSpec->outgoing)); - - if (!negotiatedProtocol.isOK()) { - return negotiatedProtocol.getStatus(); - } - if (_hook) { auto validationStatus = _hook(swIsMasterReply); if (!validationStatus.isOK()) { diff --git a/src/mongo/client/dbclient_connection.h b/src/mongo/client/dbclient_connection.h index 5fc6d464ea9..084600782c7 100644 --- a/src/mongo/client/dbclient_connection.h +++ b/src/mongo/client/dbclient_connection.h @@ -49,7 +49,6 @@ #include "mongo/rpc/message.h" #include "mongo/rpc/metadata.h" #include "mongo/rpc/op_msg.h" -#include "mongo/rpc/protocol.h" #include "mongo/rpc/unique_message.h" #include "mongo/transport/message_compressor_manager.h" #include "mongo/transport/session.h" diff --git a/src/mongo/client/dbclient_cursor.cpp b/src/mongo/client/dbclient_cursor.cpp index 322002a6981..7cbe0eb6330 100644 --- a/src/mongo/client/dbclient_cursor.cpp +++ b/src/mongo/client/dbclient_cursor.cpp @@ -81,9 +81,6 @@ Message assembleCommandRequest(DBClientBase* cli, request.body = bodyBob.obj(); } - rpc::Protocol protocol = - uassertStatusOK(rpc::negotiate(cli->getClientRPCProtocols(), cli->getServerRPCProtocols())); - invariant(protocol == rpc::Protocol::kOpMsg); return request.serialize(); } diff --git a/src/mongo/client/dbclient_cursor_test.cpp b/src/mongo/client/dbclient_cursor_test.cpp index ab3a1d363d5..4aa1ea296a4 100644 --- a/src/mongo/client/dbclient_cursor_test.cpp +++ b/src/mongo/client/dbclient_cursor_test.cpp @@ -49,7 +49,6 @@ namespace { class DBClientConnectionForTest : public DBClientConnection { public: DBClientConnectionForTest() { - _setServerRPCProtocols(rpc::supports::kAll); // allow all protocol types by default. _serverAddress = HostAndPort("localhost", 27017); // dummy server address. } @@ -84,10 +83,6 @@ public: LOGV2(20131, "Killing cursor in DBClientConnectionForTest"); } - void setSupportedProtocols(rpc::ProtocolSet protocols) { - _setServerRPCProtocols(protocols); - } - void setCallResponse(Message reply) { _mockCallResponse = reply; } diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/DefaultNoMaxStaleness.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/DefaultNoMaxStaleness.json index 1e3dd0bfd94..5afebbbdcb2 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/DefaultNoMaxStaleness.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/DefaultNoMaxStaleness.json @@ -7,7 +7,7 @@ "type": "RSSecondary", "avg_rtt_ms": 50, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -19,7 +19,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -37,7 +37,7 @@ "type": "RSSecondary", "avg_rtt_ms": 50, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -49,7 +49,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -63,7 +63,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Incompatible.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Incompatible.json index 7f9fa764c7c..9afe884d75f 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Incompatible.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Incompatible.json @@ -7,7 +7,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.json index e1abef2844b..492d8a2f625 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.json @@ -13,7 +13,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -25,7 +25,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "c:27017", @@ -37,7 +37,7 @@ "$numberLong": "1" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ] }, @@ -56,7 +56,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -68,7 +68,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ], "in_latency_window": [ @@ -82,7 +82,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ] } diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Nearest.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Nearest.json index 53549e64317..6602561c1dc 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Nearest.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Nearest.json @@ -13,7 +13,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -25,7 +25,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "c:27017", @@ -37,7 +37,7 @@ "$numberLong": "1" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ] }, @@ -56,7 +56,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -68,7 +68,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ], "in_latency_window": [ @@ -82,7 +82,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ] } diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Nearest2.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Nearest2.json index e2768c7fb8a..16d9a673bd8 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Nearest2.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Nearest2.json @@ -13,7 +13,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -25,7 +25,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "c:27017", @@ -37,7 +37,7 @@ "$numberLong": "1" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ] }, @@ -56,7 +56,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -68,7 +68,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ], "in_latency_window": [ @@ -82,7 +82,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ] } diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.json index 8c6be6886a7..7956b8e516d 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.json @@ -8,7 +8,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -20,7 +20,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -39,7 +39,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -53,7 +53,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.json index 26007c026ee..453dce6605a 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.json @@ -13,7 +13,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "tokyo" } @@ -28,7 +28,7 @@ "$numberLong": "1" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "nyc" } @@ -58,7 +58,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "tokyo" } @@ -75,7 +75,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "tokyo" } diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Secondary.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Secondary.json index 7d5eb58f4da..b383f275dc4 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Secondary.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/Secondary.json @@ -8,7 +8,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "125002" @@ -23,7 +23,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" @@ -38,7 +38,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -53,7 +53,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" @@ -80,7 +80,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" @@ -97,7 +97,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.json index df0bb5d77f0..7bce7d0aa42 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.json @@ -7,7 +7,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -19,7 +19,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -38,7 +38,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -52,7 +52,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.json index 1ac3ea0aed9..32c9ca770bd 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.json @@ -8,7 +8,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "125002" @@ -23,7 +23,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" @@ -38,7 +38,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -53,7 +53,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" @@ -80,7 +80,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" @@ -97,7 +97,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/ZeroMaxStaleness.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/ZeroMaxStaleness.json index cb5dc5175a9..e50c868bb17 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/ZeroMaxStaleness.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetNoPrimary/ZeroMaxStaleness.json @@ -7,7 +7,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/DefaultNoMaxStaleness.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/DefaultNoMaxStaleness.json index ed18d5837ec..35eaa9d69d6 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/DefaultNoMaxStaleness.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/DefaultNoMaxStaleness.json @@ -7,7 +7,7 @@ "type": "RSPrimary", "avg_rtt_ms": 50, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -19,7 +19,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -37,7 +37,7 @@ "type": "RSPrimary", "avg_rtt_ms": 50, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -49,7 +49,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -63,7 +63,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Incompatible.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Incompatible.json index d27ea11202c..1b2b42849e5 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Incompatible.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Incompatible.json @@ -7,7 +7,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.json index bbd8238e8a9..18450beaedd 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.json @@ -13,7 +13,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -25,7 +25,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "c:27017", @@ -37,7 +37,7 @@ "$numberLong": "1" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ] }, @@ -56,7 +56,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -68,7 +68,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ], "in_latency_window": [ @@ -82,7 +82,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ] } diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/LongHeartbeat.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/LongHeartbeat.json index cb05f52aa26..b9fb407f9e8 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/LongHeartbeat.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/LongHeartbeat.json @@ -8,7 +8,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -20,7 +20,7 @@ "type": "RSSecondary", "avg_rtt_ms": 50, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -39,7 +39,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -51,7 +51,7 @@ "type": "RSSecondary", "avg_rtt_ms": 50, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -65,7 +65,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/LongHeartbeat2.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/LongHeartbeat2.json index be169a3dcb6..b695e1caeb2 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/LongHeartbeat2.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/LongHeartbeat2.json @@ -8,7 +8,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -20,7 +20,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.json index 173f5742a20..9b798d37da1 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.json @@ -8,7 +8,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -20,7 +20,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.json index eee34627831..1fa7bb4dd06 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.json @@ -7,7 +7,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -19,7 +19,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Nearest.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Nearest.json index 753fb82ca32..198be4a681d 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Nearest.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Nearest.json @@ -13,7 +13,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -25,7 +25,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "c:27017", @@ -37,7 +37,7 @@ "$numberLong": "1" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ] }, @@ -56,7 +56,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -68,7 +68,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ], "in_latency_window": [ @@ -82,7 +82,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ] } diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Nearest2.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Nearest2.json index 6233c0815aa..3ae629c898b 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Nearest2.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Nearest2.json @@ -13,7 +13,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -25,7 +25,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "c:27017", @@ -37,7 +37,7 @@ "$numberLong": "1" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ] }, @@ -56,7 +56,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -68,7 +68,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ], "in_latency_window": [ @@ -82,7 +82,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 } ] } diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Nearest_tags.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Nearest_tags.json index 9a1cd3bb124..675df82631b 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Nearest_tags.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Nearest_tags.json @@ -13,7 +13,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "tokyo" } @@ -28,7 +28,7 @@ "$numberLong": "1" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "nyc" } @@ -58,7 +58,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "tokyo" } @@ -75,7 +75,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "tokyo" } diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.json index 107ae2755e2..795b47a1115 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.json @@ -8,7 +8,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -20,7 +20,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -39,7 +39,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -53,7 +53,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.json index a6681f6a130..08519589ee9 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.json @@ -7,7 +7,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.json index 5f8a21f15c9..5455708a70b 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.json @@ -7,7 +7,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -19,7 +19,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -38,7 +38,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -52,7 +52,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.json index 09ce6d6bd0a..6670b54c892 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.json @@ -8,7 +8,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "125002" @@ -20,7 +20,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" @@ -35,7 +35,7 @@ "type": "RSSecondary", "avg_rtt_ms": 50, "lastUpdateTime": 1, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -50,7 +50,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -65,7 +65,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" @@ -92,7 +92,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" @@ -107,7 +107,7 @@ "type": "RSSecondary", "avg_rtt_ms": 50, "lastUpdateTime": 1, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -124,7 +124,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.json index 3700c30453e..642fee1fb30 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.json @@ -13,7 +13,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -25,7 +25,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "tokyo" } @@ -40,7 +40,7 @@ "$numberLong": "1" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "nyc" } @@ -70,7 +70,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "tokyo" } @@ -87,7 +87,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "tokyo" } diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Secondary_tags.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Secondary_tags.json index f117159f64d..502120dce67 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Secondary_tags.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Secondary_tags.json @@ -8,7 +8,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "125002" @@ -20,7 +20,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" @@ -35,7 +35,7 @@ "type": "RSSecondary", "avg_rtt_ms": 50, "lastUpdateTime": 1, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -50,7 +50,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -65,7 +65,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" @@ -92,7 +92,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" @@ -107,7 +107,7 @@ "type": "RSSecondary", "avg_rtt_ms": 50, "lastUpdateTime": 1, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1000001" @@ -124,7 +124,7 @@ "type": "RSSecondary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.json index b739c6141bf..6978a1807b8 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.json @@ -13,7 +13,7 @@ "$numberLong": "125002" } }, - "maxWireVersion": 5 + "maxWireVersion": 6 }, { "address": "b:27017", @@ -25,7 +25,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "tokyo" } @@ -40,7 +40,7 @@ "$numberLong": "1" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "nyc" } @@ -70,7 +70,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "tokyo" } @@ -87,7 +87,7 @@ "$numberLong": "2" } }, - "maxWireVersion": 5, + "maxWireVersion": 6, "tags": { "data_center": "tokyo" } diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.json index f17aa93a3fb..23a9abe65d4 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.json @@ -7,7 +7,7 @@ "type": "RSPrimary", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "2" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Sharded/Incompatible.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Sharded/Incompatible.json index c261383f4a6..e5199c7636e 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Sharded/Incompatible.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Sharded/Incompatible.json @@ -7,7 +7,7 @@ "type": "Mongos", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Sharded/SmallMaxStaleness.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Sharded/SmallMaxStaleness.json index 27b9f1c12fd..91d89720d10 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Sharded/SmallMaxStaleness.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Sharded/SmallMaxStaleness.json @@ -8,7 +8,7 @@ "type": "Mongos", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -20,7 +20,7 @@ "type": "Mongos", "avg_rtt_ms": 50, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -39,7 +39,7 @@ "type": "Mongos", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -51,7 +51,7 @@ "type": "Mongos", "avg_rtt_ms": 50, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -65,7 +65,7 @@ "type": "Mongos", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Single/SmallMaxStaleness.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Single/SmallMaxStaleness.json index c6b10231b87..b8d2db24be7 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Single/SmallMaxStaleness.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Single/SmallMaxStaleness.json @@ -8,7 +8,7 @@ "type": "Standalone", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -27,7 +27,7 @@ "type": "Standalone", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" @@ -41,7 +41,7 @@ "type": "Standalone", "avg_rtt_ms": 5, "lastUpdateTime": 0, - "maxWireVersion": 5, + "maxWireVersion": 6, "lastWrite": { "lastWriteDate": { "$numberLong": "1" diff --git a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Unknown/SmallMaxStaleness.json b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Unknown/SmallMaxStaleness.json index bf6174b8e4d..8d69f46a1ea 100644 --- a/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Unknown/SmallMaxStaleness.json +++ b/src/mongo/client/sdam/json_tests/server_selection_tests/max_staleness/Unknown/SmallMaxStaleness.json @@ -6,7 +6,7 @@ { "address": "a:27017", "type": "Unknown", - "maxWireVersion": 5 + "maxWireVersion": 6 } ] }, diff --git a/src/mongo/client/sdam/topology_description.cpp b/src/mongo/client/sdam/topology_description.cpp index 6cc541311e5..a243eb8075d 100644 --- a/src/mongo/client/sdam/topology_description.cpp +++ b/src/mongo/client/sdam/topology_description.cpp @@ -176,7 +176,7 @@ void TopologyDescription::removeServerDescription(const HostAndPort& HostAndPort } void TopologyDescription::checkWireCompatibilityVersions() { - const WireVersionInfo supportedWireVersion = {BATCH_COMMANDS, LATEST_WIRE_VERSION}; + const WireVersionInfo supportedWireVersion = {SUPPORTS_OP_MSG, LATEST_WIRE_VERSION}; std::ostringstream errorOss; _compatible = true; diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 5d98785ebde..da796c2ecf0 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -552,7 +552,7 @@ env.Library( LIBDEPS=[ '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/executor/task_executor_interface', - "$BUILD_DIR/mongo/rpc/protocol", + "$BUILD_DIR/mongo/rpc/message", "$BUILD_DIR/mongo/util/net/network", 'client_out_of_line_executor', 'service_context', @@ -1986,6 +1986,9 @@ env.Library( LIBDEPS=[ '$BUILD_DIR/mongo/base', ], + LIBDEPS_PRIVATE=[ + '$BUILD_DIR/mongo/bson/util/bson_extract', + ], ) asioEnv = env.Clone() @@ -2044,7 +2047,7 @@ env.Library( '$BUILD_DIR/mongo/base', ], LIBDEPS_PRIVATE=[ - '$BUILD_DIR/mongo/rpc/protocol', + '$BUILD_DIR/mongo/rpc/message', "$BUILD_DIR/mongo/rpc/rpc", ], ) @@ -2056,7 +2059,7 @@ env.Program( ], LIBDEPS=[ '$BUILD_DIR/mongo/base', - '$BUILD_DIR/mongo/rpc/protocol', + '$BUILD_DIR/mongo/rpc/message', '$BUILD_DIR/mongo/util/signal_handlers', 'traffic_reader', ], @@ -2425,6 +2428,7 @@ if wiredtiger: 'update_index_data_test.cpp', 'vector_clock_mongod_test.cpp', 'vector_clock_test.cpp', + 'wire_version_test.cpp', 'write_concern_options_test.cpp', 'error_labels_test.cpp', 'commands_test_example.idl', @@ -2541,7 +2545,7 @@ asioEnv.CppIntegrationTest( LIBDEPS=[ '$BUILD_DIR/mongo/client/clientdriver_network', '$BUILD_DIR/mongo/executor/network_interface_fixture', - '$BUILD_DIR/mongo/rpc/protocol', + '$BUILD_DIR/mongo/rpc/message', '$BUILD_DIR/mongo/transport/transport_layer_egress_init', '$BUILD_DIR/mongo/util/version_impl', ], diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp index 6264c21ddcc..4aad2fce1b1 100644 --- a/src/mongo/db/commands.cpp +++ b/src/mongo/db/commands.cpp @@ -60,7 +60,6 @@ #include "mongo/rpc/factory.h" #include "mongo/rpc/metadata/client_metadata.h" #include "mongo/rpc/op_msg_rpc_impls.h" -#include "mongo/rpc/protocol.h" #include "mongo/rpc/rewrite_state_change_errors.h" #include "mongo/rpc/write_concern_error_detail.h" #include "mongo/s/stale_exception.h" diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index 10d151a21fe..ca66716656c 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -118,7 +118,7 @@ env.Library( '$BUILD_DIR/mongo/db/server_options_core', '$BUILD_DIR/mongo/idl/basic_types', '$BUILD_DIR/mongo/idl/server_parameter', - '$BUILD_DIR/mongo/rpc/protocol', + '$BUILD_DIR/mongo/rpc/message', 'test_commands_enabled', ], ) diff --git a/src/mongo/db/dbdirectclient.cpp b/src/mongo/db/dbdirectclient.cpp index 33edc482347..a7a52851a2c 100644 --- a/src/mongo/db/dbdirectclient.cpp +++ b/src/mongo/db/dbdirectclient.cpp @@ -74,9 +74,7 @@ private: } // namespace -DBDirectClient::DBDirectClient(OperationContext* opCtx) : _opCtx(opCtx) { - _setServerRPCProtocols(rpc::supports::kAll); -} +DBDirectClient::DBDirectClient(OperationContext* opCtx) : _opCtx(opCtx) {} void DBDirectClient::_auth(const BSONObj& params) { uasserted(2625701, "DBDirectClient should not authenticate"); diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp index 08ff5966e1e..29e836f254f 100644 --- a/src/mongo/db/mongod_main.cpp +++ b/src/mongo/db/mongod_main.cpp @@ -291,7 +291,7 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(WireSpec, ("EndStartupOptionHandling"))(Ini WireSpec::Specification spec; spec.incomingInternalClient.minWireVersion = RELEASE_2_4_AND_BEFORE; spec.incomingInternalClient.maxWireVersion = LATEST_WIRE_VERSION; - spec.outgoing.minWireVersion = RELEASE_2_4_AND_BEFORE; + spec.outgoing.minWireVersion = SUPPORTS_OP_MSG; spec.outgoing.maxWireVersion = LATEST_WIRE_VERSION; spec.isInternalClient = true; diff --git a/src/mongo/db/wire_version.cpp b/src/mongo/db/wire_version.cpp index 03fc8543a87..d86306daf55 100644 --- a/src/mongo/db/wire_version.cpp +++ b/src/mongo/db/wire_version.cpp @@ -34,6 +34,7 @@ #include "mongo/db/wire_version.h" #include "mongo/base/error_codes.h" +#include "mongo/bson/util/bson_extract.h" #include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/static_immortal.h" @@ -87,4 +88,78 @@ std::shared_ptr<const WireSpec::Specification> WireSpec::get() const { return _spec; } +namespace wire_version { + +StatusWith<WireVersionInfo> parseWireVersionFromHelloReply(const BSONObj& helloReply) { + long long maxWireVersion; + auto maxWireExtractStatus = + bsonExtractIntegerField(helloReply, "maxWireVersion", &maxWireVersion); + + long long minWireVersion; + auto minWireExtractStatus = + bsonExtractIntegerField(helloReply, "minWireVersion", &minWireVersion); + + // MongoDB 2.4 and earlier do not have maxWireVersion/minWireVersion in their 'isMaster' + // replies. + if ((maxWireExtractStatus == minWireExtractStatus) && + (maxWireExtractStatus == ErrorCodes::NoSuchKey)) { + return {{0, 0}}; + } else if (!maxWireExtractStatus.isOK()) { + return maxWireExtractStatus; + } else if (!minWireExtractStatus.isOK()) { + return minWireExtractStatus; + } + + if (minWireVersion < 0 || maxWireVersion < 0 || + minWireVersion >= std::numeric_limits<int>::max() || + maxWireVersion >= std::numeric_limits<int>::max()) { + return Status(ErrorCodes::IncompatibleServerVersion, + str::stream() << "Server min and max wire version have invalid values (" + << minWireVersion << "," << maxWireVersion << ")"); + } + + return WireVersionInfo{static_cast<int>(minWireVersion), static_cast<int>(maxWireVersion)}; +} + +Status validateWireVersion(const WireVersionInfo client, const WireVersionInfo server) { + // Since this is defined in the code, it should always hold true since this is the versions that + // mongos/d wants to connect to. + invariant(client.minWireVersion <= client.maxWireVersion); + + // Server may return bad data. + if (server.minWireVersion > server.maxWireVersion) { + return Status(ErrorCodes::IncompatibleServerVersion, + str::stream() + << "Server min and max wire version are incorrect (" + << server.minWireVersion << "," << server.maxWireVersion << ")"); + } + + // Determine if the [min, max] tuples overlap. + // We assert the invariant that min < max above. + if (!(client.minWireVersion <= server.maxWireVersion && + client.maxWireVersion >= server.minWireVersion)) { + std::string errmsg = str::stream() + << "Server min and max wire version (" << server.minWireVersion << "," + << server.maxWireVersion << ") is incompatible with client min wire version (" + << client.minWireVersion << "," << client.maxWireVersion << ")."; + if (client.maxWireVersion < server.minWireVersion) { + return Status(ErrorCodes::IncompatibleWithUpgradedServer, + str::stream() + << errmsg + << "You (client) are attempting to connect to a node (server) that " + "no longer accepts connections with your (client’s) binary " + "version. Please upgrade the client’s binary version."); + } + return Status(ErrorCodes::IncompatibleServerVersion, + str::stream() << errmsg + << "You (client) are attempting to connect to a node " + "(server) with a binary version with which " + "you (client) no longer accept connections. Please " + "upgrade the server’s binary version."); + } + + return Status::OK(); +} + +} // namespace wire_version } // namespace mongo diff --git a/src/mongo/db/wire_version.h b/src/mongo/db/wire_version.h index 61e5aab759e..0d43eff5b68 100644 --- a/src/mongo/db/wire_version.h +++ b/src/mongo/db/wire_version.h @@ -31,6 +31,7 @@ #include <boost/optional.hpp> +#include "mongo/base/status.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/stdx/mutex.h" #include "mongo/util/assert_util.h" @@ -159,7 +160,7 @@ public: // outgoing.maxWireVersion - Latest version allowed on remote nodes when the server sends // requests. - WireVersionInfo outgoing = {RELEASE_2_4_AND_BEFORE, LATEST_WIRE_VERSION}; + WireVersionInfo outgoing = {SUPPORTS_OP_MSG, LATEST_WIRE_VERSION}; // Set to true if the client is internal to the cluster---this is a mongod or mongos // connecting to another mongod. @@ -220,4 +221,18 @@ private: std::shared_ptr<const Specification> _spec; }; +namespace wire_version { + +/** + * Validates client and server wire version. The server's wire version is returned from + * hello/isMaster, and the client is from WireSpec.instance(). + */ +Status validateWireVersion(WireVersionInfo client, WireVersionInfo server); + +/** + * Determines the min/max wire version of a remote server from a hello/isMaster command reply. + */ +StatusWith<WireVersionInfo> parseWireVersionFromHelloReply(const BSONObj& helloReply); + +} // namespace wire_version } // namespace mongo diff --git a/src/mongo/rpc/protocol_test.cpp b/src/mongo/db/wire_version_test.cpp index 97f6ac1d763..615f73734a0 100644 --- a/src/mongo/rpc/protocol_test.cpp +++ b/src/mongo/db/wire_version_test.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-present MongoDB, Inc. + * Copyright (C) 2021-present MongoDB, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the Server Side Public License, version 1, @@ -27,146 +27,78 @@ * it in the license file. */ -#include "mongo/platform/basic.h" +#include <vector> -#include "mongo/base/status.h" -#include "mongo/db/jsobj.h" +#include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/wire_version.h" -#include "mongo/rpc/protocol.h" #include "mongo/unittest/unittest.h" -#include <vector> - +namespace mongo { namespace { -using mongo::WireVersion; -using mongo::WireVersionInfo; -using namespace mongo::rpc; -using mongo::BSONObj; -using mongo::unittest::assertGet; - -using std::vector; - -// Checks if negotiation of the first to protocol sets results in the 'proto' -const auto assert_negotiated = [](ProtocolSet fst, ProtocolSet snd, Protocol proto) { - auto negotiated = negotiate(fst, snd); - ASSERT_TRUE(negotiated.isOK()); - ASSERT_TRUE(negotiated.getValue() == proto); -}; - -TEST(Protocol, SuccessfulNegotiation) { - assert_negotiated(supports::kAll, supports::kAll, Protocol::kOpMsg); - assert_negotiated(supports::kAll, supports::kOpMsgOnly, Protocol::kOpMsg); - assert_negotiated(supports::kAll, supports::kOpQueryOnly, Protocol::kOpQuery); +TEST(WireVersionTest, ParseWireVersionFromHelloReply) { + std::vector<std::pair<WireVersion, WireVersion>> minMaxWireVersions{ + {WireVersion::RELEASE_2_4_AND_BEFORE, WireVersion::LATEST_WIRE_VERSION}, + {WireVersion::SUPPORTS_OP_MSG, WireVersion::LATEST_WIRE_VERSION}, + {WireVersion::LATEST_WIRE_VERSION, WireVersion::LATEST_WIRE_VERSION}, + {WireVersion::RELEASE_2_4_AND_BEFORE, WireVersion::LAST_CONT_WIRE_VERSION}, + {WireVersion::RELEASE_2_4_AND_BEFORE, WireVersion::LAST_LTS_WIRE_VERSION}, + {WireVersion::RELEASE_2_4_AND_BEFORE, WireVersion::SUPPORTS_OP_MSG}, + {WireVersion::RELEASE_2_4_AND_BEFORE, WireVersion::COMMANDS_ACCEPT_WRITE_CONCERN}}; + + for (auto&& wireVersions : minMaxWireVersions) { + auto helloCmdReply = + BSON("maxWireVersion" << wireVersions.second << "minWireVersion" << wireVersions.first); + auto parsedWireVersions = + unittest::assertGet(wire_version::parseWireVersionFromHelloReply(helloCmdReply)); + ASSERT_EQ(parsedWireVersions.minWireVersion, wireVersions.first); + ASSERT_EQ(parsedWireVersions.maxWireVersion, wireVersions.second); + } } -// Checks that negotiation fails -const auto assert_not_negotiated = [](ProtocolSet fst, ProtocolSet snd) { - auto proto = negotiate(fst, snd); - ASSERT_TRUE(!proto.isOK()); - ASSERT_TRUE(proto.getStatus().code() == mongo::ErrorCodes::RPCProtocolNegotiationFailed); -}; - -TEST(Protocol, FailedNegotiation) { - assert_not_negotiated(supports::kOpQueryOnly, supports::kOpMsgOnly); - assert_not_negotiated(supports::kAll, supports::kNone); - assert_not_negotiated(supports::kOpQueryOnly, supports::kNone); - assert_not_negotiated(supports::kOpMsgOnly, supports::kNone); +TEST(WireVersionTest, ParseWireVersionFromHelloReply24AndEarlier) { + // MongoDB 2.4 and earlier do not have maxWireVersion/minWireVersion in their 'isMaster' + // replies. The absence of a wire version is interpreted as the min and max wire versions both + // being 0. + BSONObj mongod24{}; + auto parsedWireVersions = + unittest::assertGet(wire_version::parseWireVersionFromHelloReply(mongod24)); + ASSERT_EQ(parsedWireVersions.minWireVersion, WireVersion::RELEASE_2_4_AND_BEFORE); + ASSERT_EQ(parsedWireVersions.maxWireVersion, WireVersion::RELEASE_2_4_AND_BEFORE); } -/* - * Tests the following: - * - Replies from MongoDB 2.4 and older reply with supports::kOpQueryOnly - * - Replies from versions of MongoDB older than 3.6 returns supports::kOpQueryOnly - * - Replies from MongoDB 3.6 reply with supports::kAll - * - Replies from latest, last-continuous, and last-lts versions of MongoDB returns supports::kAll - */ -TEST(Protocol, parseProtocolSetFromIsMasterReply) { - { - // latest version of MongoDB (mongod) - auto latestMongod = - BSON("maxWireVersion" << static_cast<int>(WireVersion::LATEST_WIRE_VERSION) - << "minWireVersion" - << static_cast<int>(WireVersion::RELEASE_2_4_AND_BEFORE)); - - ASSERT_EQ(assertGet(parseProtocolSetFromIsMasterReply(latestMongod)).protocolSet, - supports::kAll); - } - { - // last continuous version of MongoDB (mongod) - auto lastContMongod = - BSON("maxWireVersion" << static_cast<int>(WireVersion::LAST_CONT_WIRE_VERSION) - << "minWireVersion" - << static_cast<int>(WireVersion::RELEASE_2_4_AND_BEFORE)); - - ASSERT_EQ(assertGet(parseProtocolSetFromIsMasterReply(lastContMongod)).protocolSet, - supports::kAll); - } - { - // last LTS version of MongoDB (mongod) - auto lastLtsMongod = - BSON("maxWireVersion" << static_cast<int>(WireVersion::LAST_LTS_WIRE_VERSION) - << "minWireVersion" - << static_cast<int>(WireVersion::RELEASE_2_4_AND_BEFORE)); - - ASSERT_EQ(assertGet(parseProtocolSetFromIsMasterReply(lastLtsMongod)).protocolSet, - supports::kAll); - } - { - // MongoDB 3.6 - auto mongod36 = - BSON("maxWireVersion" << static_cast<int>(WireVersion::SUPPORTS_OP_MSG) // - << "minWireVersion" - << static_cast<int>(WireVersion::RELEASE_2_4_AND_BEFORE)); - - ASSERT_EQ(assertGet(parseProtocolSetFromIsMasterReply(mongod36)).protocolSet, - supports::kAll); - } - { - // MongoDB 3.2 (mongod) - auto mongod32 = - BSON("maxWireVersion" << static_cast<int>(WireVersion::COMMANDS_ACCEPT_WRITE_CONCERN) - << "minWireVersion" - << static_cast<int>(WireVersion::RELEASE_2_4_AND_BEFORE)); - - ASSERT_EQ(assertGet(parseProtocolSetFromIsMasterReply(mongod32)).protocolSet, - supports::kOpQueryOnly); // This used to also include OP_COMMAND. - } - { - // MongoDB 3.2 (mongos) - auto mongos32 = - BSON("maxWireVersion" << static_cast<int>(WireVersion::COMMANDS_ACCEPT_WRITE_CONCERN) - << "minWireVersion" - << static_cast<int>(WireVersion::RELEASE_2_4_AND_BEFORE) << "msg" - << "isdbgrid"); - - ASSERT_EQ(assertGet(parseProtocolSetFromIsMasterReply(mongos32)).protocolSet, - supports::kOpQueryOnly); - } - { - // MongoDB 2.4 and earlier do not have maxWireVersion/minWireVersion in their 'isMaster' - // replies. - auto mongod24 = BSONObj(); - ASSERT_EQ(assertGet(parseProtocolSetFromIsMasterReply(mongod24)).protocolSet, - supports::kOpQueryOnly); +TEST(WireVersionTest, ParseWireVersionFromHelloReplyErrorOnBadWireVersions) { + std::vector<std::pair<long long, long long>> badWireVersions{ + {WireVersion::RELEASE_2_4_AND_BEFORE, -1}, + {-1, WireVersion::LATEST_WIRE_VERSION}, + {WireVersion::RELEASE_2_4_AND_BEFORE, + static_cast<long long>(std::numeric_limits<int>::max()) + 1}, + {static_cast<long long>(std::numeric_limits<int>::max()) + 1, + WireVersion::LATEST_WIRE_VERSION}}; + + for (auto&& wireVersions : badWireVersions) { + auto helloCmdReply = + BSON("maxWireVersion" << wireVersions.second << "minWireVersion" << wireVersions.first); + auto parsedWireVersions = wire_version::parseWireVersionFromHelloReply(helloCmdReply); + ASSERT_EQ(parsedWireVersions.getStatus(), ErrorCodes::IncompatibleServerVersion); } } -#define VALIDATE_WIRE_VERSION(macro, clientMin, clientMax, serverMin, serverMax) \ - do { \ - auto msg = BSON("minWireVersion" << static_cast<int>(serverMin) << "maxWireVersion" \ - << static_cast<int>(serverMax)); \ - auto swReply = parseProtocolSetFromIsMasterReply(msg); \ - ASSERT_OK(swReply.getStatus()); \ - macro(validateWireVersion({clientMin, clientMax}, swReply.getValue().version)); \ +#define VALIDATE_WIRE_VERSION(macro, clientMin, clientMax, serverMin, serverMax) \ + do { \ + auto msg = BSON("minWireVersion" << static_cast<int>(serverMin) << "maxWireVersion" \ + << static_cast<int>(serverMax)); \ + auto swReply = wire_version::parseWireVersionFromHelloReply(msg); \ + ASSERT_OK(swReply.getStatus()); \ + macro(wire_version::validateWireVersion({clientMin, clientMax}, swReply.getValue())); \ } while (0); -TEST(Protocol, validateWireVersion) { +TEST(WireVersionTest, ValidateWireVersion) { // Min, max FCV version pairs representing valid WireVersion ranges for variable binary // versions used to communicate with the MongoD 'latest' binary version. // MongoD 'latest' binary - vector<WireVersionInfo> mongoDLatestBinaryRanges = { + std::vector<WireVersionInfo> mongoDLatestBinaryRanges = { // upgraded FCV {WireVersion::LATEST_WIRE_VERSION, WireVersion::LATEST_WIRE_VERSION}, // downgraded 'last-cont' FCV @@ -175,7 +107,7 @@ TEST(Protocol, validateWireVersion) { {WireVersion::LAST_LTS_WIRE_VERSION, WireVersion::LATEST_WIRE_VERSION}}; // MongoS binary versions - vector<WireVersionInfo> mongoSBinaryRanges = { + std::vector<WireVersionInfo> mongoSBinaryRanges = { // 'latest' binary {WireVersion::LATEST_WIRE_VERSION, WireVersion::LATEST_WIRE_VERSION}, // 'last-cont' binary @@ -318,20 +250,20 @@ TEST(Protocol, validateWireVersion) { } // A mongos is unable to communicate with a fully upgraded cluster with a higher wire version. -TEST(Protocol, validateWireVersionFailsForUpgradedServerNode) { +TEST(WireVersionTest, ValidateWireVersionFailsForUpgradedServerNode) { // Server is fully upgraded to the latest wire version. auto msg = BSON("minWireVersion" << static_cast<int>(WireVersion::LATEST_WIRE_VERSION) << "maxWireVersion" << static_cast<int>(WireVersion::LATEST_WIRE_VERSION)); - auto swReply = parseProtocolSetFromIsMasterReply(msg); + auto swReply = wire_version::parseWireVersionFromHelloReply(msg); ASSERT_OK(swReply.getStatus()); // The client (this mongos server) only has the previous wire version. ASSERT_EQUALS(mongo::ErrorCodes::IncompatibleWithUpgradedServer, - validateWireVersion( + wire_version::validateWireVersion( {WireVersion::LATEST_WIRE_VERSION - 1, WireVersion::LATEST_WIRE_VERSION - 1}, - swReply.getValue().version) - .code()); + swReply.getValue())); } } // namespace +} // namespace mongo diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp index 2f929993bfd..2cdd02e6913 100644 --- a/src/mongo/db/write_concern.cpp +++ b/src/mongo/db/write_concern.cpp @@ -51,7 +51,6 @@ #include "mongo/db/transaction_validation.h" #include "mongo/db/write_concern_options.h" #include "mongo/logv2/log.h" -#include "mongo/rpc/protocol.h" #include "mongo/util/fail_point.h" namespace mongo { diff --git a/src/mongo/dbtests/mock/mock_dbclient_connection.cpp b/src/mongo/dbtests/mock/mock_dbclient_connection.cpp index 1de5ad73484..9b849d051d8 100644 --- a/src/mongo/dbtests/mock/mock_dbclient_connection.cpp +++ b/src/mongo/dbtests/mock/mock_dbclient_connection.cpp @@ -49,7 +49,6 @@ MockDBClientConnection::MockDBClientConnection(MockRemoteDBServer* remoteServer, _sockCreationTime(mongo::curTimeMicros64()) { invariant(remoteServer); _remoteServerInstanceID = remoteServer->getInstanceID(); - _setServerRPCProtocols(rpc::supports::kAll); _callIter = _mockCallResponses.begin(); _recvIter = _mockRecvResponses.begin(); } @@ -62,7 +61,6 @@ bool MockDBClientConnection::connect(const char* hostName, _serverAddress = _remoteServer->getServerHostAndPort(); if (_remoteServer->isRunning()) { _remoteServerInstanceID = _remoteServer->getInstanceID(); - _setServerRPCProtocols(rpc::supports::kAll); return true; } diff --git a/src/mongo/embedded/embedded.cpp b/src/mongo/embedded/embedded.cpp index c6692fbee6b..20395926254 100644 --- a/src/mongo/embedded/embedded.cpp +++ b/src/mongo/embedded/embedded.cpp @@ -90,7 +90,7 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(WireSpec, ("EndStartupOptionHandling"))(Ini WireSpec::Specification spec; spec.incomingInternalClient.minWireVersion = RELEASE_2_4_AND_BEFORE; spec.incomingInternalClient.maxWireVersion = LATEST_WIRE_VERSION; - spec.outgoing.minWireVersion = RELEASE_2_4_AND_BEFORE; + spec.outgoing.minWireVersion = SUPPORTS_OP_MSG; spec.outgoing.maxWireVersion = LATEST_WIRE_VERSION; spec.isInternalClient = true; diff --git a/src/mongo/embedded/embedded_ismaster.cpp b/src/mongo/embedded/embedded_ismaster.cpp index 5964b9e0781..32b1197b154 100644 --- a/src/mongo/embedded/embedded_ismaster.cpp +++ b/src/mongo/embedded/embedded_ismaster.cpp @@ -33,6 +33,7 @@ #include "mongo/db/audit.h" #include "mongo/db/commands.h" #include "mongo/db/ops/write_ops.h" +#include "mongo/db/wire_version.h" #include "mongo/rpc/metadata/client_metadata.h" namespace mongo { diff --git a/src/mongo/embedded/mongo_embedded/SConscript b/src/mongo/embedded/mongo_embedded/SConscript index 5b9ab7ef339..8f84ee065d5 100644 --- a/src/mongo/embedded/mongo_embedded/SConscript +++ b/src/mongo/embedded/mongo_embedded/SConscript @@ -69,7 +69,7 @@ mongoEmbeddedTargets = mongoEmbeddedEnv.Library( LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/embedded/embedded', - '$BUILD_DIR/mongo/rpc/protocol', + '$BUILD_DIR/mongo/rpc/message', '$BUILD_DIR/mongo/transport/transport_layer_mock', ], AIB_COMPONENT='embedded', @@ -96,7 +96,7 @@ if get_option('link-model') != 'dynamic-sdk': '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/db/commands/test_commands_enabled', '$BUILD_DIR/mongo/db/server_options_core', - '$BUILD_DIR/mongo/rpc/protocol', + '$BUILD_DIR/mongo/rpc/message', '$BUILD_DIR/mongo/unittest/unittest', '$BUILD_DIR/mongo/util/net/network', '$BUILD_DIR/mongo/util/options_parser/options_parser', diff --git a/src/mongo/rpc/SConscript b/src/mongo/rpc/SConscript index d4cf4d5cac7..6901ff84661 100644 --- a/src/mongo/rpc/SConscript +++ b/src/mongo/rpc/SConscript @@ -29,12 +29,11 @@ if wiredtiger: protoEnv.Library( target=[ - 'protocol', + 'message', ], source=[ 'message.cpp', 'op_msg.cpp', - 'protocol.cpp', ], LIBDEPS=[ '$BUILD_DIR/mongo/base', @@ -70,8 +69,8 @@ env.Library( '$BUILD_DIR/mongo/idl/basic_types', '$BUILD_DIR/mongo/s/common_s', '$BUILD_DIR/mongo/util/net/network', + 'message', 'metadata', - 'protocol', ], LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/idl/server_parameter', @@ -89,9 +88,9 @@ env.Library( '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/bson/mutable/mutable_bson', '$BUILD_DIR/mongo/db/service_context', - '$BUILD_DIR/mongo/rpc/protocol', '$BUILD_DIR/mongo/s/is_mongos', '$BUILD_DIR/third_party/shim_pcrecpp', + 'message', ], ) @@ -103,7 +102,7 @@ env.CppLibfuzzerTest( LIBDEPS=[ '$BUILD_DIR/mongo/db/ops/write_ops_parsers', '$BUILD_DIR/mongo/transport/message_compressor', - 'protocol', + 'message', 'rpc', ], ) @@ -184,7 +183,6 @@ if wiredtiger: 'metadata_test.cpp', 'object_check_test.cpp', 'op_msg_test.cpp', - 'protocol_test.cpp', 'reply_builder_test.cpp', 'rewrite_state_change_errors_test.cpp', ], @@ -209,6 +207,6 @@ env.CppIntegrationTest( '$BUILD_DIR/mongo/client/clientdriver_network', '$BUILD_DIR/mongo/transport/transport_layer_egress_init', '$BUILD_DIR/mongo/util/version_impl', - 'protocol', + 'message', ], ) diff --git a/src/mongo/rpc/factory.cpp b/src/mongo/rpc/factory.cpp index 8211fb03d39..aa024ac2da8 100644 --- a/src/mongo/rpc/factory.cpp +++ b/src/mongo/rpc/factory.cpp @@ -38,7 +38,6 @@ #include "mongo/rpc/legacy_request.h" #include "mongo/rpc/message.h" #include "mongo/rpc/op_msg_rpc_impls.h" -#include "mongo/rpc/protocol.h" #include "mongo/util/assert_util.h" #include "mongo/util/str.h" diff --git a/src/mongo/rpc/metadata/sharding_metadata.h b/src/mongo/rpc/metadata/sharding_metadata.h index 1956ac4b7e3..5467707b722 100644 --- a/src/mongo/rpc/metadata/sharding_metadata.h +++ b/src/mongo/rpc/metadata/sharding_metadata.h @@ -30,7 +30,6 @@ #include "mongo/db/jsobj.h" #include "mongo/db/repl/optime.h" -#include "mongo/rpc/protocol.h" namespace mongo { class BSONObj; diff --git a/src/mongo/rpc/protocol.cpp b/src/mongo/rpc/protocol.cpp deleted file mode 100644 index c021e79140a..00000000000 --- a/src/mongo/rpc/protocol.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/rpc/protocol.h" - -#include <algorithm> -#include <iterator> - -#include "mongo/base/string_data.h" -#include "mongo/bson/util/bson_extract.h" -#include "mongo/db/jsobj.h" -#include "mongo/db/wire_version.h" -#include "mongo/util/str.h" - -namespace mongo { -namespace rpc { - -namespace { - -/** - * Protocols supported by order of preference. - */ -const Protocol kPreferredProtos[] = {Protocol::kOpMsg, Protocol::kOpQuery}; - -struct ProtocolSetAndName { - StringData name; - ProtocolSet protocols; -}; - -constexpr ProtocolSetAndName protocolSetNames[] = { - // Most common ones go first. - {"all"_sd, supports::kAll}, // new mongod and mongos or very new client. - {"opQueryOnly"_sd, supports::kOpQueryOnly}, // old mongos or mongod or moderately old client. - - // Then the rest (these should never happen in production). - {"none"_sd, supports::kNone}, - {"opMsgOnly"_sd, supports::kOpMsgOnly}, -}; - -} // namespace - -Protocol protocolForMessage(const Message& message) { - switch (message.operation()) { - case mongo::dbMsg: - return Protocol::kOpMsg; - case mongo::dbQuery: - return Protocol::kOpQuery; - default: - uasserted(ErrorCodes::UnsupportedFormat, - str::stream() << "Received a reply message with unexpected opcode: " - << message.operation()); - } -} - -StatusWith<Protocol> negotiate(ProtocolSet fst, ProtocolSet snd) { - using std::begin; - using std::end; - - ProtocolSet common = fst & snd; - - auto it = std::find_if(begin(kPreferredProtos), end(kPreferredProtos), [common](Protocol p) { - return common & static_cast<ProtocolSet>(p); - }); - - if (it == end(kPreferredProtos)) { - return Status(ErrorCodes::RPCProtocolNegotiationFailed, "No common protocol found."); - } - return *it; -} - -StatusWith<StringData> toString(ProtocolSet protocols) { - for (auto& elem : protocolSetNames) { - if (elem.protocols == protocols) - return elem.name; - } - return Status(ErrorCodes::BadValue, - str::stream() << "ProtocolSet " << protocols - << " does not match any well-known value."); -} - -StatusWith<ProtocolSet> parseProtocolSet(StringData name) { - for (auto& elem : protocolSetNames) { - if (elem.name == name) - return elem.protocols; - } - return Status(ErrorCodes::BadValue, - str::stream() << name << " is not a valid name for a ProtocolSet."); -} - -StatusWith<ProtocolSetAndWireVersionInfo> parseProtocolSetFromIsMasterReply( - const BSONObj& isMasterReply) { - long long maxWireVersion; - auto maxWireExtractStatus = - bsonExtractIntegerField(isMasterReply, "maxWireVersion", &maxWireVersion); - - long long minWireVersion; - auto minWireExtractStatus = - bsonExtractIntegerField(isMasterReply, "minWireVersion", &minWireVersion); - - // MongoDB 2.4 and earlier do not have maxWireVersion/minWireVersion in their 'isMaster' replies - if ((maxWireExtractStatus == minWireExtractStatus) && - (maxWireExtractStatus == ErrorCodes::NoSuchKey)) { - return {{supports::kOpQueryOnly, {0, 0}}}; - } else if (!maxWireExtractStatus.isOK()) { - return maxWireExtractStatus; - } else if (!minWireExtractStatus.isOK()) { - return minWireExtractStatus; - } - - if (minWireVersion < 0 || maxWireVersion < 0 || - minWireVersion >= std::numeric_limits<int>::max() || - maxWireVersion >= std::numeric_limits<int>::max()) { - return Status(ErrorCodes::IncompatibleServerVersion, - str::stream() << "Server min and max wire version have invalid values (" - << minWireVersion << "," << maxWireVersion << ")"); - } - - WireVersionInfo version{static_cast<int>(minWireVersion), static_cast<int>(maxWireVersion)}; - - auto protos = computeProtocolSet(version); - return {{protos, version}}; -} - -ProtocolSet computeProtocolSet(const WireVersionInfo version) { - ProtocolSet result = supports::kNone; - if (version.minWireVersion <= version.maxWireVersion) { - if (version.maxWireVersion >= WireVersion::SUPPORTS_OP_MSG) { - result |= supports::kOpMsgOnly; - } - if (version.minWireVersion <= WireVersion::RELEASE_2_4_AND_BEFORE) { - result |= supports::kOpQueryOnly; - } - // Note: this means anything using the internal handshake cannot talk to servers between 2.6 - // and 3.6, since the servers will reply with higher minWireVersions. The shell should still - // be able to connect to those versions but will just use OP_QUERY to run commands. - } - return result; -} - -Status validateWireVersion(const WireVersionInfo client, const WireVersionInfo server) { - // Since this is defined in the code, it should always hold true since this is the versions that - // mongos/d wants to connect to. - invariant(client.minWireVersion <= client.maxWireVersion); - - // Server may return bad data. - if (server.minWireVersion > server.maxWireVersion) { - return Status(ErrorCodes::IncompatibleServerVersion, - str::stream() - << "Server min and max wire version are incorrect (" - << server.minWireVersion << "," << server.maxWireVersion << ")"); - } - - // Determine if the [min, max] tuples overlap. - // We assert the invariant that min < max above. - if (!(client.minWireVersion <= server.maxWireVersion && - client.maxWireVersion >= server.minWireVersion)) { - std::string errmsg = str::stream() - << "Server min and max wire version (" << server.minWireVersion << "," - << server.maxWireVersion << ") is incompatible with client min wire version (" - << client.minWireVersion << "," << client.maxWireVersion << ")."; - if (client.maxWireVersion < server.minWireVersion) { - return Status(ErrorCodes::IncompatibleWithUpgradedServer, - str::stream() - << errmsg - << "You (client) are attempting to connect to a node (server) that " - "no longer accepts connections with your (client’s) binary " - "version. Please upgrade the client’s binary version."); - } - return Status(ErrorCodes::IncompatibleServerVersion, - str::stream() << errmsg - << "You (client) are attempting to connect to a node " - "(server) with a binary version with which " - "you (client) no longer accept connections. Please " - "upgrade the server’s binary version."); - } - - return Status::OK(); -} - -} // namespace rpc -} // namespace mongo diff --git a/src/mongo/rpc/protocol.h b/src/mongo/rpc/protocol.h index 1f0a966e1f2..ea95bc4d844 100644 --- a/src/mongo/rpc/protocol.h +++ b/src/mongo/rpc/protocol.h @@ -29,31 +29,26 @@ #pragma once -#include <cstdint> -#include <string> -#include <type_traits> +#include <fmt/format.h> -#include "mongo/base/status_with.h" -#include "mongo/db/wire_version.h" #include "mongo/rpc/message.h" +#include "mongo/util/assert_util.h" namespace mongo { -class BSONObj; -class OperationContext; namespace rpc { /** - * Bit flags representing support for a particular RPC protocol. - * This is just an internal representation, and is never transmitted over the wire. It should - * never be used for any other feature detection in favor of max/min wire version. + * Bit flags representing support for a particular RPC protocol. This is just an internal + * representation, and is never transmitted over the wire. It should never be used for any other + * feature detection in favor of max/min wire version. * - * A new protocol must be added as the highest order bit flag so that it is prioritized in - * negotiation. + * The system only currently offers full support for the OP_MSG protocol. However, it can continue + * to handle OP_QUERY in some limited cases, in particular for the hello/isMaster command sent by + * clients on connection open. */ enum class Protocol : std::uint64_t { - /** - * The pre-3.2 OP_QUERY on db.$cmd protocol + * The pre-3.6 OP_QUERY on db.$cmd protocol */ kOpQuery = 1 << 0, @@ -63,79 +58,18 @@ enum class Protocol : std::uint64_t { kOpMsg = 1 << 1, }; -/** - * Bitfield representing a set of supported RPC protocols. - */ -using ProtocolSet = std::underlying_type<Protocol>::type; - -/** - * This namespace contains predefined bitfields for common levels of protocol support. - */ -namespace supports { - -const ProtocolSet kNone = ProtocolSet{0}; -const ProtocolSet kOpQueryOnly = static_cast<ProtocolSet>(Protocol::kOpQuery); -const ProtocolSet kOpMsgOnly = static_cast<ProtocolSet>(Protocol::kOpMsg); -const ProtocolSet kAll = kOpQueryOnly | kOpMsgOnly; - -} // namespace supports - -Protocol protocolForMessage(const Message& message); - -/** - * Returns the protocol used to initiate the current operation. - */ -Protocol getOperationProtocol(OperationContext* opCtx); - -/** - * Sets the protocol used to initiate the current operation. - */ -void setOperationProtocol(OperationContext* opCtx, Protocol protocol); - -/** - * Returns the newest protocol supported by two parties. - */ -StatusWith<Protocol> negotiate(ProtocolSet fst, ProtocolSet snd); - -/** - * Converts a ProtocolSet to a string. Currently only the predefined ProtocolSets in the - * 'supports' namespace are supported. - * - * This intentionally does not conform to the STL 'to_string' convention so that it will - * not conflict with the to_string overload for uint64_t. - */ -StatusWith<StringData> toString(ProtocolSet protocols); - -/** - * Parses a ProtocolSet from a string. Currently only the predefined ProtocolSets in the - * 'supports' namespace are supported - */ -StatusWith<ProtocolSet> parseProtocolSet(StringData repr); - -/** - * Validates client and server wire version. The server is returned from isMaster, and the client is - * from WireSpec.instance(). - */ -Status validateWireVersion(WireVersionInfo client, WireVersionInfo server); - -/** - * Struct to pass around information about protocol set and wire version. - */ -struct ProtocolSetAndWireVersionInfo { - ProtocolSet protocolSet; - WireVersionInfo version; -}; - -/** - * Determines the ProtocolSet of a remote server from an isMaster reply. - */ -StatusWith<ProtocolSetAndWireVersionInfo> parseProtocolSetFromIsMasterReply( - const BSONObj& isMasterReply); - -/** - * Computes supported protocols from wire versions. - */ -ProtocolSet computeProtocolSet(WireVersionInfo version); +inline Protocol protocolForMessage(const Message& message) { + switch (message.operation()) { + case mongo::dbMsg: + return Protocol::kOpMsg; + case mongo::dbQuery: + return Protocol::kOpQuery; + default: + uasserted(ErrorCodes::UnsupportedFormat, + fmt::format("Received a reply message with unexpected opcode: {}", + message.operation())); + } +} } // namespace rpc } // namespace mongo diff --git a/src/mongo/scripting/mozjs/mongo.cpp b/src/mongo/scripting/mozjs/mongo.cpp index a850a7a9d1a..6aaf30b8990 100644 --- a/src/mongo/scripting/mozjs/mongo.cpp +++ b/src/mongo/scripting/mozjs/mongo.cpp @@ -67,8 +67,6 @@ const JSFunctionSpec MongoBase::methods[] = { MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(getDataKeyCollection, MongoExternalInfo), MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(encrypt, MongoExternalInfo), MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(decrypt, MongoExternalInfo), - MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(getClientRPCProtocols, MongoExternalInfo), - MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(getServerRPCProtocols, MongoExternalInfo), MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(isReplicaSetConnection, MongoExternalInfo), MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(_markNodeAsFailed, MongoExternalInfo), MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(logout, MongoExternalInfo), @@ -467,34 +465,6 @@ void MongoBase::Functions::cursorHandleFromId::call(JSContext* cx, JS::CallArgs args.rval().setObjectOrNull(c); } -void MongoBase::Functions::getClientRPCProtocols::call(JSContext* cx, JS::CallArgs args) { - auto conn = getConnection(args); - - if (args.length() != 0) - uasserted(ErrorCodes::BadValue, "getClientRPCProtocols takes no args"); - - auto clientRPCProtocols = rpc::toString(conn->getClientRPCProtocols()); - uassertStatusOK(clientRPCProtocols); - - auto protoStr = clientRPCProtocols.getValue().toString(); - - ValueReader(cx, args.rval()).fromStringData(protoStr); -} - -void MongoBase::Functions::getServerRPCProtocols::call(JSContext* cx, JS::CallArgs args) { - auto conn = getConnection(args); - - if (args.length() != 0) - uasserted(ErrorCodes::BadValue, "getServerRPCProtocols takes no args"); - - auto serverRPCProtocols = rpc::toString(conn->getServerRPCProtocols()); - uassertStatusOK(serverRPCProtocols); - - auto protoStr = serverRPCProtocols.getValue().toString(); - - ValueReader(cx, args.rval()).fromStringData(protoStr); -} - void MongoBase::Functions::isReplicaSetConnection::call(JSContext* cx, JS::CallArgs args) { auto conn = getConnection(args); diff --git a/src/mongo/scripting/mozjs/mongo.h b/src/mongo/scripting/mozjs/mongo.h index 86f54913f41..248a5b2a5ae 100644 --- a/src/mongo/scripting/mozjs/mongo.h +++ b/src/mongo/scripting/mozjs/mongo.h @@ -61,8 +61,6 @@ struct MongoBase : public BaseInfo { MONGO_DECLARE_JS_FUNCTION(getDataKeyCollection); MONGO_DECLARE_JS_FUNCTION(encrypt); MONGO_DECLARE_JS_FUNCTION(decrypt); - MONGO_DECLARE_JS_FUNCTION(getClientRPCProtocols); - MONGO_DECLARE_JS_FUNCTION(getServerRPCProtocols); MONGO_DECLARE_JS_FUNCTION(insert); MONGO_DECLARE_JS_FUNCTION(isReplicaSetConnection); MONGO_DECLARE_JS_FUNCTION(_markNodeAsFailed); diff --git a/src/mongo/shell/SConscript b/src/mongo/shell/SConscript index 5e64d6ce24e..14cd26fa9fa 100644 --- a/src/mongo/shell/SConscript +++ b/src/mongo/shell/SConscript @@ -257,7 +257,7 @@ if not has_option('noshell') and usemozjs: "$BUILD_DIR/mongo/executor/network_interface_factory", "$BUILD_DIR/mongo/executor/network_interface_thread_pool", "$BUILD_DIR/mongo/executor/thread_pool_task_executor", - "$BUILD_DIR/mongo/rpc/protocol", + "$BUILD_DIR/mongo/rpc/message", "$BUILD_DIR/mongo/scripting/scripting", "$BUILD_DIR/mongo/transport/message_compressor", "$BUILD_DIR/mongo/transport/message_compressor_options_client", diff --git a/src/mongo/shell/shell_options.cpp b/src/mongo/shell/shell_options.cpp index c1b40a323e5..d67a554d584 100644 --- a/src/mongo/shell/shell_options.cpp +++ b/src/mongo/shell/shell_options.cpp @@ -45,7 +45,6 @@ #include "mongo/db/auth/sasl_command_constants.h" #include "mongo/db/server_options.h" #include "mongo/logv2/log.h" -#include "mongo/rpc/protocol.h" #include "mongo/shell/shell_utils.h" #include "mongo/transport/message_compressor_options_client_gen.h" #include "mongo/transport/message_compressor_registry.h" diff --git a/src/mongo/shell/shell_options.h b/src/mongo/shell/shell_options.h index a4be609b966..ca84f56a311 100644 --- a/src/mongo/shell/shell_options.h +++ b/src/mongo/shell/shell_options.h @@ -34,7 +34,7 @@ #include <vector> #include "mongo/base/status.h" -#include "mongo/rpc/protocol.h" +#include "mongo/util/duration.h" namespace mongo { diff --git a/src/mongo/transport/SConscript b/src/mongo/transport/SConscript index 27856ec3ca0..61b30fed670 100644 --- a/src/mongo/transport/SConscript +++ b/src/mongo/transport/SConscript @@ -121,7 +121,7 @@ env.Library( '$BUILD_DIR/mongo/db/server_options_core', '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/stats/counters', - '$BUILD_DIR/mongo/rpc/protocol', + '$BUILD_DIR/mongo/rpc/message', '$BUILD_DIR/mongo/util/processinfo', 'service_executor', 'transport_layer_common', @@ -191,7 +191,7 @@ tlEnv.CppUnitTest( '$BUILD_DIR/mongo/db/dbmessage', '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/service_context_test_fixture', - '$BUILD_DIR/mongo/rpc/protocol', + '$BUILD_DIR/mongo/rpc/message', '$BUILD_DIR/mongo/rpc/rpc', '$BUILD_DIR/mongo/unittest/unittest', '$BUILD_DIR/mongo/util/clock_source_mock', |