diff options
author | Nathan Myers <nathan.myers@10gen.com> | 2017-10-17 14:07:38 -0400 |
---|---|---|
committer | Nathan Myers <nathan.myers@10gen.com> | 2017-10-17 14:07:38 -0400 |
commit | aeabbf96ff3c2990f553ba0a5e6e1d18ebddab2f (patch) | |
tree | cfb67393fadfd03d0c40d5082711da5dfa44edc4 /src/mongo/s/catalog/type_shard_collection.cpp | |
parent | bd0c03a8816985f74f7bd24245aa81f9cb5b37f7 (diff) | |
download | mongo-aeabbf96ff3c2990f553ba0a5e6e1d18ebddab2f.tar.gz |
SERVER-31191 Plumb Collection UUIDs through catalog cache
Diffstat (limited to 'src/mongo/s/catalog/type_shard_collection.cpp')
-rw-r--r-- | src/mongo/s/catalog/type_shard_collection.cpp | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/src/mongo/s/catalog/type_shard_collection.cpp b/src/mongo/s/catalog/type_shard_collection.cpp index 186b35fbb44..3a98a15f7ba 100644 --- a/src/mongo/s/catalog/type_shard_collection.cpp +++ b/src/mongo/s/catalog/type_shard_collection.cpp @@ -42,8 +42,8 @@ namespace mongo { const std::string ShardCollectionType::ConfigNS = NamespaceString::kShardConfigCollectionsCollectionName.toString(); -const BSONField<std::string> ShardCollectionType::uuid("_id"); -const BSONField<std::string> ShardCollectionType::ns("ns"); +const BSONField<std::string> ShardCollectionType::ns("_id"); +const BSONField<UUID> ShardCollectionType::uuid("uuid"); const BSONField<OID> ShardCollectionType::epoch("epoch"); const BSONField<BSONObj> ShardCollectionType::keyPattern("key"); const BSONField<BSONObj> ShardCollectionType::defaultCollation("defaultCollation"); @@ -52,28 +52,20 @@ const BSONField<bool> ShardCollectionType::refreshing("refreshing"); const BSONField<Date_t> ShardCollectionType::lastRefreshedCollectionVersion( "lastRefreshedCollectionVersion"); -ShardCollectionType::ShardCollectionType(const NamespaceString& uuid, - const NamespaceString& nss, - const OID& epoch, +ShardCollectionType::ShardCollectionType(NamespaceString nss, + boost::optional<UUID> uuid, + OID epoch, const KeyPattern& keyPattern, const BSONObj& defaultCollation, - const bool& unique) - : _uuid(uuid), - _nss(nss), - _epoch(epoch), + bool unique) + : _nss(std::move(nss)), + _uuid(uuid), + _epoch(std::move(epoch)), _keyPattern(keyPattern.toBSON()), _defaultCollation(defaultCollation.getOwned()), _unique(unique) {} StatusWith<ShardCollectionType> ShardCollectionType::fromBSON(const BSONObj& source) { - NamespaceString uuid; - { - std::string ns; - Status status = bsonExtractStringField(source, ShardCollectionType::uuid.name(), &ns); - if (!status.isOK()) - return status; - uuid = NamespaceString{ns}; - } NamespaceString nss; { @@ -85,6 +77,23 @@ StatusWith<ShardCollectionType> ShardCollectionType::fromBSON(const BSONObj& sou nss = NamespaceString{ns}; } + boost::optional<UUID> uuid; + { + BSONElement uuidElem; + Status status = bsonExtractTypedField( + source, ShardCollectionType::uuid.name(), BSONType::BinData, &uuidElem); + if (status.isOK()) { + auto uuidWith = UUID::parse(uuidElem); + if (!uuidWith.isOK()) + return uuidWith.getStatus(); + uuid = uuidWith.getValue(); + } else if (status == ErrorCodes::NoSuchKey) { + // The field is not set, which is okay. + } else { + return status; + } + } + OID epoch; { BSONElement oidElem; @@ -134,7 +143,8 @@ StatusWith<ShardCollectionType> ShardCollectionType::fromBSON(const BSONObj& sou } } - ShardCollectionType shardCollectionType(uuid, nss, epoch, pattern, collation, unique); + ShardCollectionType shardCollectionType( + std::move(nss), uuid, std::move(epoch), pattern, collation, unique); // Below are optional fields. @@ -170,8 +180,10 @@ StatusWith<ShardCollectionType> ShardCollectionType::fromBSON(const BSONObj& sou BSONObj ShardCollectionType::toBSON() const { BSONObjBuilder builder; - builder.append(uuid.name(), _uuid.ns()); builder.append(ns.name(), _nss.ns()); + if (_uuid) { + _uuid->appendToBuilder(&builder, uuid.name()); + } builder.append(epoch.name(), _epoch); builder.append(keyPattern.name(), _keyPattern.toBSON()); @@ -196,19 +208,18 @@ std::string ShardCollectionType::toString() const { return toBSON().toString(); } -void ShardCollectionType::setUUID(const NamespaceString& uuid) { - invariant(uuid.isValid()); +void ShardCollectionType::setUUID(UUID uuid) { _uuid = uuid; } -void ShardCollectionType::setNss(const NamespaceString& nss) { +void ShardCollectionType::setNss(NamespaceString nss) { invariant(nss.isValid()); - _nss = nss; + _nss = std::move(nss); } -void ShardCollectionType::setEpoch(const OID& epoch) { +void ShardCollectionType::setEpoch(OID epoch) { invariant(epoch.isSet()); - _epoch = epoch; + _epoch = std::move(epoch); } void ShardCollectionType::setKeyPattern(const KeyPattern& keyPattern) { |