diff options
author | Adam Midvidy <amidvidy@gmail.com> | 2015-10-22 10:32:47 -0400 |
---|---|---|
committer | Adam Midvidy <amidvidy@gmail.com> | 2015-10-30 15:14:06 -0400 |
commit | e62e2e71eff397caf22a0da13ac4669a8546b298 (patch) | |
tree | d170510044130c0c8e34950387b4afac957f097b /src/mongo/db/s/operation_shard_version.cpp | |
parent | cbc6a790dc4ac537b071626dff77d0073512690c (diff) | |
download | mongo-e62e2e71eff397caf22a0da13ac4669a8546b298.tar.gz |
SERVER-20609 use getFields instead of calling getField 4x
Diffstat (limited to 'src/mongo/db/s/operation_shard_version.cpp')
-rw-r--r-- | src/mongo/db/s/operation_shard_version.cpp | 18 |
1 files changed, 12 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)); } |