summaryrefslogtreecommitdiff
path: root/src/mongo/rpc/metadata
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2015-09-16 15:16:44 -0400
committerSpencer T Brody <spencer@mongodb.com>2015-09-17 11:55:12 -0400
commit3619498a9f4ff383cdd546a320abbec11a511bc6 (patch)
tree07c72a7861c0ef171fc562e76acef2a343bbd1c7 /src/mongo/rpc/metadata
parent0e0a4e5e8a70ce1f6208c613d2897186a0b8a1c3 (diff)
downloadmongo-3619498a9f4ff383cdd546a320abbec11a511bc6.tar.gz
SERVER-19905 SERVER-19855 Put config server optime into its own subobject when sending with commands
Diffstat (limited to 'src/mongo/rpc/metadata')
-rw-r--r--src/mongo/rpc/metadata/sharding_metadata.cpp16
-rw-r--r--src/mongo/rpc/metadata/sharding_metadata.h26
2 files changed, 42 insertions, 0 deletions
diff --git a/src/mongo/rpc/metadata/sharding_metadata.cpp b/src/mongo/rpc/metadata/sharding_metadata.cpp
index 4fc3a2feae2..71566a2a5da 100644
--- a/src/mongo/rpc/metadata/sharding_metadata.cpp
+++ b/src/mongo/rpc/metadata/sharding_metadata.cpp
@@ -34,11 +34,14 @@
#include "mongo/bson/util/bson_extract.h"
#include "mongo/db/jsobj.h"
+#include "mongo/db/repl/optime.h"
#include "mongo/util/mongoutils/str.h"
namespace mongo {
namespace rpc {
+const char ShardingRequestMetadata::kConfigsvrOpTimeFieldName[] = "configsvrOpTime";
+
namespace {
const char kGLEStatsFieldName[] = "$gleStats";
@@ -141,5 +144,18 @@ const OID& ShardingMetadata::getLastElectionId() const {
return _lastElectionId;
}
+StatusWith<boost::optional<repl::OpTime>>
+ShardingRequestMetadata::extractConfigServerOpTimeIfPresent(const BSONObj& cmdObj) {
+ repl::OpTime opTime;
+ Status status = bsonExtractOpTimeField(cmdObj, kConfigsvrOpTimeFieldName, &opTime);
+ if (status == ErrorCodes::NoSuchKey) {
+ return {boost::none};
+ } else if (!status.isOK()) {
+ return status;
+ }
+
+ return {opTime};
+}
+
} // namespace rpc
} // namespace mongo
diff --git a/src/mongo/rpc/metadata/sharding_metadata.h b/src/mongo/rpc/metadata/sharding_metadata.h
index 048473064b4..b18e415ffb4 100644
--- a/src/mongo/rpc/metadata/sharding_metadata.h
+++ b/src/mongo/rpc/metadata/sharding_metadata.h
@@ -27,6 +27,8 @@
*/
#pragma once
+#include <boost/optional.hpp>
+
#include "mongo/db/jsobj.h"
namespace mongo {
@@ -35,11 +37,17 @@ class BSONObjBuilder;
class Status;
template <typename T>
class StatusWith;
+
+namespace repl {
+class OpTime;
+} // namespace repl
+
namespace rpc {
/**
* This class compromises the reply metadata fields that concern sharding. MongoD attaches
* this information to a command reply, which MongoS uses to process getLastError.
+ * TODO(spencer): Rename this to ShardingResponseMetadata.
*/
class ShardingMetadata {
public:
@@ -87,5 +95,23 @@ private:
OID _lastElectionId;
};
+class ShardingRequestMetadata {
+public:
+ static const char kConfigsvrOpTimeFieldName[];
+
+ /**
+ * Looks in the given command object for a field containing the config server optime, and
+ * returns it if present, or boost::none if not. Returns a non-ok status on parsing error.
+ * Used for extracting the config server optime on mongod that was sent from a mongos.
+ *
+ * TODO(SERVER-20442): Currently this method extracts this information from the main command
+ * description rather than the actual OP_COMMAND metadata section. Ideally this information
+ * should be in the metadata, but we currently have no good way to add metadata to all commands
+ * being *sent* to another server.
+ */
+ static StatusWith<boost::optional<repl::OpTime>> extractConfigServerOpTimeIfPresent(
+ const BSONObj& cmdObj);
+};
+
} // namespace rpc
} // namespace mongo