diff options
author | Antonio Fuschetto <antonio.fuschetto@mongodb.com> | 2021-08-30 17:44:08 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-08-30 18:24:57 +0000 |
commit | 0f5e46ed312f5cfecfa0a07de293cebfb5ac645f (patch) | |
tree | 4296519b5a1d84bdf5c0327e37a7b0d87fe5bca9 /src/mongo/db/s/shard_metadata_util.cpp | |
parent | 637e21b775634146bcd86a4320b06d8e87cf59cf (diff) | |
download | mongo-0f5e46ed312f5cfecfa0a07de293cebfb5ac645f.tar.gz |
SERVER-59661 Refactor construction of persisted chunks collection namespace
Diffstat (limited to 'src/mongo/db/s/shard_metadata_util.cpp')
-rw-r--r-- | src/mongo/db/s/shard_metadata_util.cpp | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/mongo/db/s/shard_metadata_util.cpp b/src/mongo/db/s/shard_metadata_util.cpp index 12e25a256e5..1d64abb728f 100644 --- a/src/mongo/db/s/shard_metadata_util.cpp +++ b/src/mongo/db/s/shard_metadata_util.cpp @@ -70,6 +70,21 @@ Status getStatusFromWriteCommandResponse(const BSONObj& commandResult) { return batchResponse.toStatus(); } +/** + * Returns the namespace of the shard server's chunks collection correspoding to the collection + * namespace. The actual chunks collection namespace is based on the collection namespace or UUID + * depending on the current collection configuration. + */ +NamespaceString getShardChunksNss(const NamespaceString& collectionNss, + const UUID& collectionUuid, + SupportingLongNameStatusEnum supportingLongName) { + const auto chunksNsPostfix{supportingLongName == SupportingLongNameStatusEnum::kDisabled || + collectionNss.isTemporaryReshardingCollection() + ? collectionNss.ns() + : collectionUuid.toString()}; + return NamespaceString{ChunkType::ShardNSPrefix + chunksNsPostfix}; +} + } // namespace QueryAndSort createShardChunkDiffQuery(const ChunkVersion& collectionVersion) { @@ -285,11 +300,7 @@ StatusWith<std::vector<ChunkType>> readShardChunks(OperationContext* opCtx, boost::optional<long long> limit, const OID& epoch, const boost::optional<Timestamp>& timestamp) { - const auto chunksNsPostfix{supportingLongName == SupportingLongNameStatusEnum::kDisabled || - nss.isTemporaryReshardingCollection() - ? nss.ns() - : uuid.toString()}; - const NamespaceString chunksNss{ChunkType::ShardNSPrefix + chunksNsPostfix}; + const auto chunksNss = getShardChunksNss(nss, uuid, supportingLongName); try { DBDirectClient client(opCtx); @@ -327,11 +338,7 @@ Status updateShardChunks(OperationContext* opCtx, const OID& currEpoch) { invariant(!chunks.empty()); - const auto chunksNsPostfix{supportingLongName == SupportingLongNameStatusEnum::kDisabled || - nss.isTemporaryReshardingCollection() - ? nss.ns() - : uuid.toString()}; - const NamespaceString chunksNss{ChunkType::ShardNSPrefix + chunksNsPostfix}; + const auto chunksNss = getShardChunksNss(nss, uuid, supportingLongName); try { DBDirectClient client(opCtx); @@ -484,11 +491,7 @@ void dropChunks(OperationContext* opCtx, const NamespaceString& nss, const UUID& uuid, SupportingLongNameStatusEnum supportingLongName) { - const auto chunksNsPostfix{supportingLongName == SupportingLongNameStatusEnum::kDisabled || - nss.isTemporaryReshardingCollection() - ? nss.ns() - : uuid.toString()}; - const NamespaceString chunksNss{ChunkType::ShardNSPrefix + chunksNsPostfix}; + const auto chunksNss = getShardChunksNss(nss, uuid, supportingLongName); DBDirectClient client(opCtx); BSONObj result; |