diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/client/dbclient_connection.cpp | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/client/dbclient_connection.cpp')
| -rw-r--r-- | src/mongo/client/dbclient_connection.cpp | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/src/mongo/client/dbclient_connection.cpp b/src/mongo/client/dbclient_connection.cpp index 3e52ad0a33c..55202e0c907 100644 --- a/src/mongo/client/dbclient_connection.cpp +++ b/src/mongo/client/dbclient_connection.cpp @@ -96,27 +96,28 @@ StatusWith<bool> completeSpeculativeAuth(DBClientConnection* conn, auth::SpeculativeAuthType speculativeAuthType, std::shared_ptr<SaslClientSession> session, const MongoURI& uri, - BSONObj helloReply) { - auto specAuthElem = helloReply[auth::kSpeculativeAuthenticate]; + BSONObj isMaster) { + auto specAuthElem = isMaster[auth::kSpeculativeAuthenticate]; if (specAuthElem.eoo()) { return false; } if (speculativeAuthType == auth::SpeculativeAuthType::kNone) { return {ErrorCodes::BadValue, - str::stream() << "Unexpected hello." << auth::kSpeculativeAuthenticate << " reply"}; + str::stream() << "Unexpected isMaster." << auth::kSpeculativeAuthenticate + << " reply"}; } if (specAuthElem.type() != Object) { return {ErrorCodes::BadValue, - str::stream() << "hello." << auth::kSpeculativeAuthenticate + str::stream() << "isMaster." << auth::kSpeculativeAuthenticate << " reply must be an object"}; } auto specAuth = specAuthElem.Obj(); if (specAuth.isEmpty()) { return {ErrorCodes::BadValue, - str::stream() << "hello." << auth::kSpeculativeAuthenticate + str::stream() << "isMaster." << auth::kSpeculativeAuthenticate << " reply must be a non-empty obejct"}; } @@ -150,7 +151,7 @@ StatusWith<bool> completeSpeculativeAuth(DBClientConnection* conn, } /** - * Initializes the wire version of conn, and returns the "hello" reply. + * Initializes the wire version of conn, and returns the isMaster reply. */ executor::RemoteCommandResponse initWireVersion( DBClientConnection* conn, @@ -161,7 +162,7 @@ executor::RemoteCommandResponse initWireVersion( std::shared_ptr<SaslClientSession>* saslClientSession) try { BSONObjBuilder bob; - bob.append("hello", 1); + bob.append(conn->getApiParameters().getVersion() ? "hello" : "isMaster", 1); if (uri.isHelloOk()) { // Attach "helloOk: true" to the initial handshake to indicate that the client supports the @@ -181,7 +182,7 @@ executor::RemoteCommandResponse initWireVersion( } if (getTestCommandsEnabled()) { - // Only include the host:port of this process in the "hello" command request if test + // Only include the host:port of this process in the isMaster command request if test // commands are enabled. mongobridge uses this field to identify the process opening a // connection to it. StringBuilder sb; @@ -207,24 +208,25 @@ executor::RemoteCommandResponse initWireVersion( auto result = conn->runCommand(OpMsgRequest::fromDBAndBody("admin", bob.obj())); Date_t finish{Date_t::now()}; - BSONObj helloObj = result->getCommandReply().getOwned(); + BSONObj isMasterObj = result->getCommandReply().getOwned(); - if (helloObj.hasField("minWireVersion") && helloObj.hasField("maxWireVersion")) { - int minWireVersion = helloObj["minWireVersion"].numberInt(); - int maxWireVersion = helloObj["maxWireVersion"].numberInt(); + if (isMasterObj.hasField("minWireVersion") && isMasterObj.hasField("maxWireVersion")) { + int minWireVersion = isMasterObj["minWireVersion"].numberInt(); + int maxWireVersion = isMasterObj["maxWireVersion"].numberInt(); conn->setWireVersions(minWireVersion, maxWireVersion); } - if (helloObj.hasField("saslSupportedMechs") && helloObj["saslSupportedMechs"].type() == Array) { - auto array = helloObj["saslSupportedMechs"].Array(); + if (isMasterObj.hasField("saslSupportedMechs") && + isMasterObj["saslSupportedMechs"].type() == Array) { + auto array = isMasterObj["saslSupportedMechs"].Array(); for (const auto& elem : array) { saslMechsForAuth->push_back(elem.checkAndGetStringData().toString()); } } - conn->getCompressorManager().clientFinish(helloObj); + conn->getCompressorManager().clientFinish(isMasterObj); - return executor::RemoteCommandResponse{std::move(helloObj), finish - start}; + return executor::RemoteCommandResponse{std::move(isMasterObj), finish - start}; } catch (...) { return exceptionToStatus(); @@ -282,41 +284,41 @@ Status DBClientConnection::connect(const HostAndPort& serverAddress, auto speculativeAuthType = auth::SpeculativeAuthType::kNone; std::shared_ptr<SaslClientSession> saslClientSession; - auto swHelloReply = initWireVersion( + auto swIsMasterReply = initWireVersion( this, _applicationName, _uri, &_saslMechsForAuth, &speculativeAuthType, &saslClientSession); - if (!swHelloReply.isOK()) { + if (!swIsMasterReply.isOK()) { _markFailed(kSetFlag); - swHelloReply.status.addContext( + swIsMasterReply.status.addContext( "Connection handshake failed. Is your mongod/mongos 3.4 or older?"_sd); - return swHelloReply.status; + return swIsMasterReply.status; } - // Ensure that the "hello" response is "ok:1". - auto helloStatus = getStatusFromCommandResult(swHelloReply.data); - if (!helloStatus.isOK()) { - return helloStatus; + // Ensure that the isMaster response is "ok:1". + auto isMasterStatus = getStatusFromCommandResult(swIsMasterReply.data); + if (!isMasterStatus.isOK()) { + return isMasterStatus; } - auto replyWireVersion = wire_version::parseWireVersionFromHelloReply(swHelloReply.data); + auto replyWireVersion = wire_version::parseWireVersionFromHelloReply(swIsMasterReply.data); if (!replyWireVersion.isOK()) { return replyWireVersion.getStatus(); } { // The Server Discovery and Monitoring (SDAM) specification identifies a replica set member - // as either (a) having a "setName" field in the "hello" response, or (b) having - // "isreplicaset: true" in the "hello" response. + // as either (a) having a "setName" field in the isMaster response, or (b) having + // "isreplicaset: true" in the isMaster response. // // https://github.com/mongodb/specifications/blob/c386e23724318e2fa82f4f7663d77581b755b2c3/ // source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#type - const bool hasSetNameField = swHelloReply.data.hasField("setName"); - const bool isReplicaSetField = swHelloReply.data.getBoolField("isreplicaset"); + const bool hasSetNameField = swIsMasterReply.data.hasField("setName"); + const bool isReplicaSetField = swIsMasterReply.data.getBoolField("isreplicaset"); _isReplicaSetMember = hasSetNameField || isReplicaSetField; } { std::string msgField; - auto msgFieldExtractStatus = bsonExtractStringField(swHelloReply.data, "msg", &msgField); + auto msgFieldExtractStatus = bsonExtractStringField(swIsMasterReply.data, "msg", &msgField); if (msgFieldExtractStatus == ErrorCodes::NoSuchKey) { _isMongos = false; @@ -340,7 +342,7 @@ Status DBClientConnection::connect(const HostAndPort& serverAddress, } if (_hook) { - auto validationStatus = _hook(swHelloReply); + auto validationStatus = _hook(swIsMasterReply); if (!validationStatus.isOK()) { // Disconnect and mark failed. _markFailed(kReleaseSession); @@ -350,7 +352,7 @@ Status DBClientConnection::connect(const HostAndPort& serverAddress, { auto swAuth = completeSpeculativeAuth( - this, speculativeAuthType, saslClientSession, _uri, swHelloReply.data); + this, speculativeAuthType, saslClientSession, _uri, swIsMasterReply.data); if (!swAuth.isOK()) { return swAuth.getStatus(); } |
