From d19dcfc1ccf76518898c5c6d0ebb3e78e37af45c Mon Sep 17 00:00:00 2001 From: Henrik Edin Date: Thu, 27 Sep 2018 15:04:21 -0400 Subject: SERVER-37294 Remove dependency on clientdriver_network and transport_layer for embedded. --- src/mongo/db/service_entry_point_mongod.cpp | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'src/mongo/db/service_entry_point_mongod.cpp') diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp index c0281fe7460..52656b7ddcc 100644 --- a/src/mongo/db/service_entry_point_mongod.cpp +++ b/src/mongo/db/service_entry_point_mongod.cpp @@ -45,12 +45,17 @@ #include "mongo/db/service_entry_point_common.h" #include "mongo/logger/redaction.h" #include "mongo/rpc/get_status_from_command_result.h" +#include "mongo/rpc/metadata/config_server_metadata.h" +#include "mongo/rpc/metadata/sharding_metadata.h" #include "mongo/s/cannot_implicitly_create_collection_info.h" +#include "mongo/s/grid.h" #include "mongo/s/stale_exception.h" #include "mongo/util/log.h" namespace mongo { +constexpr auto kLastCommittedOpTimeFieldName = "lastCommittedOpTime"_sd; + class ServiceEntryPointMongod::Hooks final : public ServiceEntryPointCommon::Hooks { public: bool lockedForWriting() const override { @@ -149,6 +154,53 @@ public: } } + // Called from the error contexts where request may not be available. + void appendReplyMetadataOnError(OperationContext* opCtx, + BSONObjBuilder* metadataBob) const override { + const bool isConfig = serverGlobalParams.clusterRole == ClusterRole::ConfigServer; + if (ShardingState::get(opCtx)->enabled() || isConfig) { + auto lastCommittedOpTime = + repl::ReplicationCoordinator::get(opCtx)->getLastCommittedOpTime(); + metadataBob->append(kLastCommittedOpTimeFieldName, lastCommittedOpTime.getTimestamp()); + } + } + + void appendReplyMetadata(OperationContext* opCtx, + const OpMsgRequest& request, + BSONObjBuilder* metadataBob) const override { + const bool isShardingAware = ShardingState::get(opCtx)->enabled(); + const bool isConfig = serverGlobalParams.clusterRole == ClusterRole::ConfigServer; + auto const replCoord = repl::ReplicationCoordinator::get(opCtx); + const bool isReplSet = + replCoord->getReplicationMode() == repl::ReplicationCoordinator::modeReplSet; + + if (isReplSet) { + // Attach our own last opTime. + repl::OpTime lastOpTimeFromClient = + repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp(); + replCoord->prepareReplMetadata(request.body, lastOpTimeFromClient, metadataBob); + // For commands from mongos, append some info to help getLastError(w) work. + // TODO: refactor out of here as part of SERVER-18236 + if (isShardingAware || isConfig) { + rpc::ShardingMetadata(lastOpTimeFromClient, replCoord->getElectionId()) + .writeToMetadata(metadataBob) + .transitional_ignore(); + } + + if (isShardingAware || isConfig) { + auto lastCommittedOpTime = replCoord->getLastCommittedOpTime(); + metadataBob->append(kLastCommittedOpTimeFieldName, + lastCommittedOpTime.getTimestamp()); + } + } + + // If we're a shard other than the config shard, attach the last configOpTime we know about. + if (isShardingAware && !isConfig) { + auto opTime = Grid::get(opCtx)->configOpTime(); + rpc::ConfigServerMetadata(opTime).writeToMetadata(metadataBob); + } + } + void advanceConfigOptimeFromRequestMetadata(OperationContext* opCtx) const override { // Handle config optime information that may have been sent along with the command. rpc::advanceConfigOptimeFromRequestMetadata(opCtx); -- cgit v1.2.1