summaryrefslogtreecommitdiff
path: root/src/mongo/db/service_entry_point_mongod.cpp
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2018-09-27 15:04:21 -0400
committerHenrik Edin <henrik.edin@mongodb.com>2018-10-04 14:31:16 -0400
commitd19dcfc1ccf76518898c5c6d0ebb3e78e37af45c (patch)
tree6861c500a1f620ff24316dd8203fe494020c896a /src/mongo/db/service_entry_point_mongod.cpp
parent3fcaa553f5c8ade0a4b6d1b66c29478fe7e2d937 (diff)
downloadmongo-d19dcfc1ccf76518898c5c6d0ebb3e78e37af45c.tar.gz
SERVER-37294 Remove dependency on clientdriver_network and transport_layer for embedded.
Diffstat (limited to 'src/mongo/db/service_entry_point_mongod.cpp')
-rw-r--r--src/mongo/db/service_entry_point_mongod.cpp52
1 files changed, 52 insertions, 0 deletions
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);