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/rpc/metadata/client_metadata.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/rpc/metadata/client_metadata.cpp')
| -rw-r--r-- | src/mongo/rpc/metadata/client_metadata.cpp | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/src/mongo/rpc/metadata/client_metadata.cpp b/src/mongo/rpc/metadata/client_metadata.cpp index 8ac4f4a9d97..86d7230120e 100644 --- a/src/mongo/rpc/metadata/client_metadata.cpp +++ b/src/mongo/rpc/metadata/client_metadata.cpp @@ -43,8 +43,6 @@ #include "mongo/db/operation_context.h" #include "mongo/logv2/log.h" #include "mongo/s/is_mongos.h" -#include "mongo/transport/message_compressor_base.h" -#include "mongo/transport/message_compressor_manager.h" #include "mongo/util/debug_util.h" #include "mongo/util/net/socket_utils.h" #include "mongo/util/processinfo.h" @@ -158,7 +156,7 @@ ClientMetadata::ClientMetadata(BSONObj doc) { foundOperatingSystem); } -StatusWith<std::string> ClientMetadata::parseApplicationDocument(const BSONObj& doc) { +StatusWith<StringData> ClientMetadata::parseApplicationDocument(const BSONObj& doc) { BSONObjIterator i(doc); while (i.more()) { @@ -175,7 +173,7 @@ StatusWith<std::string> ClientMetadata::parseApplicationDocument(const BSONObj& << "' field must be a string in the client metadata document"}; } - std::string value = str::escape(e.checkAndGetStringData().toString()); + StringData value = e.checkAndGetStringData(); if (value.size() > kMaxApplicationNameByteLength) { return {ErrorCodes::ClientMetadataAppNameTooLarge, @@ -185,11 +183,11 @@ StatusWith<std::string> ClientMetadata::parseApplicationDocument(const BSONObj& << " bytes in the client metadata document"}; } - return std::move(value); + return {std::move(value)}; } } - return std::string(); + return {StringData()}; } Status ClientMetadata::validateDriverDocument(const BSONObj& doc) { @@ -269,7 +267,6 @@ Status ClientMetadata::validateOperatingSystemDocument(const BSONObj& doc) { void ClientMetadata::setMongoSMetadata(StringData hostAndPort, StringData mongosClient, StringData version) { - _documentWithoutMongosInfo = _document; BSONObjBuilder builder; builder.appendElements(_document); @@ -280,7 +277,25 @@ void ClientMetadata::setMongoSMetadata(StringData hostAndPort, sub.append(kVersion, version); } - _document = builder.obj(); + auto document = builder.obj(); + + if (!_appName.empty()) { + // The _appName field points into the existing _document, which we are about to replace. + // We must redirect _appName to point into the new doc *before* replacing the old doc. We + // expect the 'application' metadata of the new document to be identical to the old. + auto appMetaData = document[kApplication]; + invariant(appMetaData.isABSONObj()); + + auto appNameEl = appMetaData[kName]; + invariant(appNameEl.type() == BSONType::String); + + auto appName = appNameEl.valueStringData(); + invariant(appName == _appName); + + _appName = appName; + } + + _document = std::move(document); } void ClientMetadata::serialize(StringData driverName, @@ -375,40 +390,23 @@ Status ClientMetadata::serializePrivate(StringData driverName, } StringData ClientMetadata::getApplicationName() const { - return StringData(_appName); + return _appName; } const BSONObj& ClientMetadata::getDocument() const { return _document; } -unsigned long ClientMetadata::hashWithoutMongosInfo() const { - return _hashWithoutMongos.get(documentWithoutMongosInfo()); -} - -const BSONObj& ClientMetadata::documentWithoutMongosInfo() const { - return _documentWithoutMongosInfo.get(_document); -} - void ClientMetadata::logClientMetadata(Client* client) const { if (getDocument().isEmpty()) { return; } - auto negotiatedCompressors = - MessageCompressorManager::forSession(client->session()).getNegotiatedCompressors(); - std::vector<StringData> negotiatedCompressorNames(negotiatedCompressors.size(), nullptr); - std::transform( - negotiatedCompressors.begin(), - negotiatedCompressors.end(), - negotiatedCompressorNames.begin(), - [](auto& messageCompressor) { return StringData(messageCompressor->getName()); }); - LOGV2(51800, + "received client metadata from {remote} {client}: {doc}", "client metadata", "remote"_attr = client->getRemote(), "client"_attr = client->desc(), - "negotiatedCompressors"_attr = negotiatedCompressorNames, "doc"_attr = getDocument()); } |
