diff options
author | Jordi Serra Torrens <jordi.serra-torrens@mongodb.com> | 2021-06-14 14:50:05 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-15 07:53:30 +0000 |
commit | d5ab25a22cdfd7d60aedae5fb3e455502e330bdb (patch) | |
tree | 20641c232fb766bb2d74e18bf9ea6b52dbd7cd8c | |
parent | 184b0285b25a2801998eabf1b315ef4b444bc941 (diff) | |
download | mongo-d5ab25a22cdfd7d60aedae5fb3e455502e330bdb.tar.gz |
SERVER-57641 Legacy renameCollection may proceed renaming a sharded collection
-rw-r--r-- | src/mongo/db/s/shardsvr_rename_collection_command.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/mongo/db/s/shardsvr_rename_collection_command.cpp b/src/mongo/db/s/shardsvr_rename_collection_command.cpp index dbe8883535e..8ea2eb6a1f0 100644 --- a/src/mongo/db/s/shardsvr_rename_collection_command.cpp +++ b/src/mongo/db/s/shardsvr_rename_collection_command.cpp @@ -52,10 +52,14 @@ namespace mongo { namespace { bool isCollectionSharded(OperationContext* opCtx, const NamespaceString& nss) { - AutoGetCollectionForRead lock(opCtx, nss); - return opCtx->writesAreReplicated() && - CollectionShardingState::get(opCtx, nss)->getCollectionDescription(opCtx).isSharded(); -} + try { + Grid::get(opCtx)->catalogClient()->getCollection(opCtx, nss); + return true; + } catch (ExceptionFor<ErrorCodes::NamespaceNotFound>&) { + // The collection is unsharded or doesn't exist + return false; + } +} // namespace bool renameIsAllowedOnNS(const NamespaceString& nss) { if (nss.isSystem()) { |