diff options
Diffstat (limited to 'src/mongo/s/commands')
-rw-r--r-- | src/mongo/s/commands/cluster_is_master_cmd.cpp | 31 | ||||
-rw-r--r-- | src/mongo/s/commands/strategy.cpp | 31 |
2 files changed, 22 insertions, 40 deletions
diff --git a/src/mongo/s/commands/cluster_is_master_cmd.cpp b/src/mongo/s/commands/cluster_is_master_cmd.cpp index 532f29c7e04..1ae4b497576 100644 --- a/src/mongo/s/commands/cluster_is_master_cmd.cpp +++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp @@ -42,7 +42,6 @@ #include "mongo/db/wire_version.h" #include "mongo/logv2/log.h" #include "mongo/rpc/metadata/client_metadata.h" -#include "mongo/rpc/metadata/client_metadata_ismaster.h" #include "mongo/rpc/topology_version_gen.h" #include "mongo/s/mongos_topology_coordinator.h" #include "mongo/transport/message_compressor_manager.h" @@ -99,34 +98,8 @@ public: waitInHello.pauseWhileSet(opCtx); - auto& clientMetadataIsMasterState = ClientMetadataIsMasterState::get(opCtx->getClient()); - bool seenIsMaster = clientMetadataIsMasterState.hasSeenIsMaster(); - if (!seenIsMaster) { - clientMetadataIsMasterState.setSeenIsMaster(); - } - - BSONElement element = cmdObj[kMetadataDocumentName]; - if (!element.eoo()) { - if (seenIsMaster) { - uasserted(ErrorCodes::ClientMetadataCannotBeMutated, - "The client metadata document may only be sent in the first isMaster"); - } - - auto swParseClientMetadata = ClientMetadata::parse(element); - uassertStatusOK(swParseClientMetadata.getStatus()); - - invariant(swParseClientMetadata.getValue()); - - swParseClientMetadata.getValue().get().logClientMetadata(opCtx->getClient()); - - swParseClientMetadata.getValue().get().setMongoSMetadata( - getHostNameCachedAndPort(), - opCtx->getClient()->clientAddress(true), - VersionInfoInterface::instance().version()); - - clientMetadataIsMasterState.setClientMetadata( - opCtx->getClient(), std::move(swParseClientMetadata.getValue())); - } + auto client = opCtx->getClient(); + ClientMetadata::tryFinalize(client); // If a client is following the awaitable isMaster protocol, maxAwaitTimeMS should be // present if and only if topologyVersion is present in the request. diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp index d2b88b8c78f..364b385ec8d 100644 --- a/src/mongo/s/commands/strategy.cpp +++ b/src/mongo/s/commands/strategy.cpp @@ -68,6 +68,7 @@ #include "mongo/logv2/log.h" #include "mongo/rpc/factory.h" #include "mongo/rpc/get_status_from_command_result.h" +#include "mongo/rpc/metadata/client_metadata.h" #include "mongo/rpc/metadata/tracking_metadata.h" #include "mongo/rpc/op_msg.h" #include "mongo/rpc/op_msg_rpc_impls.h" @@ -312,11 +313,12 @@ void runCommand(OperationContext* opCtx, return; } + const auto isHello = command->getName() == "hello"_sd || command->getName() == "isMaster"_sd; + opCtx->setExhaust(OpMsg::isFlagSet(m, OpMsg::kExhaustSupported)); const auto session = opCtx->getClient()->session(); if (session) { - if (!opCtx->isExhaust() || - (command->getName() != "hello"_sd && command->getName() != "isMaster"_sd)) { + if (!opCtx->isExhaust() || !isHello) { InExhaustHello::get(session.get())->setInExhaust(false, commandName); } } @@ -390,19 +392,26 @@ void runCommand(OperationContext* opCtx, return; } - auto& apiParams = APIParameters::get(opCtx); - auto& apiVersionMetrics = APIVersionMetrics::get(opCtx->getServiceContext()); - const auto& clientMetadata = ClientMetadataIsMasterState::get(client).getClientMetadata(); - if (clientMetadata) { - auto appName = clientMetadata.get().getApplicationName().toString(); - apiVersionMetrics.update(appName, apiParams); - } - - boost::optional<RouterOperationContextSession> routerSession; try { + if (isHello) { + // Preload generic ClientMetadata ahead of our first hello request. After the first + // request, metaElement should always be empty. + auto metaElem = request.body[kMetadataDocumentName]; + ClientMetadata::setFromMetadata(opCtx->getClient(), metaElem); + } + + auto& apiParams = APIParameters::get(opCtx); + auto& apiVersionMetrics = APIVersionMetrics::get(opCtx->getServiceContext()); + if (auto clientMetadata = ClientMetadata::get(client)) { + auto appName = clientMetadata->getApplicationName().toString(); + apiVersionMetrics.update(appName, apiParams); + } + rpc::readRequestMetadata(opCtx, request.body, command->requiresAuth()); CommandHelpers::evaluateFailCommandFailPoint(opCtx, invocation.get()); + + boost::optional<RouterOperationContextSession> routerSession; bool startTransaction = false; if (osi.getAutocommit()) { routerSession.emplace(opCtx); |