summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorJason Zhang <jason.zhang@mongodb.com>2019-08-19 13:44:49 -0400
committerJason Zhang <jason.zhang@mongodb.com>2019-08-21 15:13:06 -0400
commit0609b68b1b841bb46a0ff6ef299f59fac06eb672 (patch)
tree0d343086dae519c9c0bdc2b69cea1e2ced2ddf79 /src/mongo
parentc6e8dec61cf71d1776110a8f13c6368c8a28e436 (diff)
downloadmongo-0609b68b1b841bb46a0ff6ef299f59fac06eb672.tar.gz
SERVER-42833 Make _configsvrRenameCollection return an error if the source and target collections are on different primary shards.
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp14
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client_impl.cpp4
2 files changed, 17 insertions, 1 deletions
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp
index bfbd17c2968..12192c7c7b4 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp
@@ -495,6 +495,20 @@ void ShardingCatalogManager::renameCollection(OperationContext* opCtx,
const NamespaceString& nssTarget = request.getTo();
const auto catalogClient = Grid::get(opCtx)->catalogClient();
+ const auto dbTypeSource =
+ uassertStatusOK(
+ Grid::get(opCtx)->catalogClient()->getDatabase(
+ opCtx, nssSource.db().toString(), repl::ReadConcernArgs::get(opCtx).getLevel()))
+ .value;
+ const auto dbTypeTarget =
+ uassertStatusOK(
+ Grid::get(opCtx)->catalogClient()->getDatabase(
+ opCtx, nssTarget.db().toString(), repl::ReadConcernArgs::get(opCtx).getLevel()))
+ .value;
+ uassert(ErrorCodes::IllegalOperation,
+ "Source and target cannot be on different namespaces.",
+ dbTypeSource.getPrimary() == dbTypeTarget.getPrimary());
+
ShardsvrRenameCollection shardsvrRenameCollectionRequest;
shardsvrRenameCollectionRequest.setRenameCollection(nssSource);
shardsvrRenameCollectionRequest.setTo(nssTarget);
diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
index a070397e08f..501f24f39a0 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
@@ -372,8 +372,10 @@ std::vector<NamespaceString> ShardingCatalogClientImpl::getAllShardedCollections
std::vector<NamespaceString> collectionsToReturn;
for (const auto& coll : collectionsOnConfig) {
- if (coll.getDropped())
+ if (coll.getDropped() ||
+ coll.getDistributionMode() == CollectionType::DistributionMode::kUnsharded) {
continue;
+ }
collectionsToReturn.push_back(coll.getNs());
}