summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/operation_shard_version.cpp18
-rw-r--r--src/mongo/db/s/operation_shard_version.h3
2 files changed, 15 insertions, 6 deletions
diff --git a/src/mongo/db/s/operation_shard_version.cpp b/src/mongo/db/s/operation_shard_version.cpp
index d51ae7d9cb8..5f47d80ef4f 100644
--- a/src/mongo/db/s/operation_shard_version.cpp
+++ b/src/mongo/db/s/operation_shard_version.cpp
@@ -39,7 +39,7 @@ namespace {
const OperationContext::Decoration<OperationShardVersion> shardingMetadataDecoration =
OperationContext::declareDecoration<OperationShardVersion>();
-const char* kShardVersionField = "shardVersion";
+const char kShardVersionField[] = "shardVersion";
const ChunkVersion kUnshardedVersion(ChunkVersion::UNSHARDED());
} // namespace mongo
@@ -50,26 +50,32 @@ OperationShardVersion& OperationShardVersion::get(OperationContext* txn) {
return shardingMetadataDecoration(txn);
}
+StringData OperationShardVersion::fieldName() {
+ return kShardVersionField;
+}
+
void OperationShardVersion::initializeFromCommand(NamespaceString ns, const BSONObj& cmdObj) {
+ initializeFromCommand(std::move(ns), cmdObj[fieldName()]);
+}
+
+void OperationShardVersion::initializeFromCommand(NamespaceString ns,
+ const BSONElement& shardVersionElt) {
if (ns.isSystemDotIndexes()) {
setShardVersion(std::move(ns), ChunkVersion::IGNORED());
return;
}
- BSONElement versionElt;
- Status status = bsonExtractTypedField(cmdObj, kShardVersionField, BSONType::Array, &versionElt);
- if (!status.isOK()) {
+ if (shardVersionElt.eoo() || shardVersionElt.type() != BSONType::Array) {
return;
}
- const BSONArray versionArr(versionElt.Obj());
+ const BSONArray versionArr(shardVersionElt.Obj());
bool hasVersion = false;
ChunkVersion newVersion = ChunkVersion::fromBSON(versionArr, &hasVersion);
if (!hasVersion) {
return;
}
-
setShardVersion(std::move(ns), std::move(newVersion));
}
diff --git a/src/mongo/db/s/operation_shard_version.h b/src/mongo/db/s/operation_shard_version.h
index 33021dcdbae..1ec6e2bc1c1 100644
--- a/src/mongo/db/s/operation_shard_version.h
+++ b/src/mongo/db/s/operation_shard_version.h
@@ -53,6 +53,8 @@ public:
OperationShardVersion();
+ static StringData fieldName();
+
/**
* Retrieves a reference to the shard version decorating the OperationContext, 'txn'.
*/
@@ -66,6 +68,7 @@ public:
* Expects the format { ..., shardVersion: [<version>, <epoch>] }.
*/
void initializeFromCommand(NamespaceString ns, const BSONObj& cmdObj);
+ void initializeFromCommand(NamespaceString ns, const BSONElement& shardVersionElement);
/**
* Returns whether or not there is a shard version associated with this operation.