summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/collection_sharding_runtime.cpp
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2020-11-03 14:08:19 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-11-11 14:52:36 +0000
commit7950f071b21957be1ab8e5ac2db8b650695a2bd0 (patch)
treec18442fd863b1d955d8194a2ddf6759201182e08 /src/mongo/db/s/collection_sharding_runtime.cpp
parentb43f6fefe1ac3e941fd55d5452a1ee21e7ff0ae6 (diff)
downloadmongo-7950f071b21957be1ab8e5ac2db8b650695a2bd0.tar.gz
SERVER-50027 Implement an 'allowMigrations' collection property
Diffstat (limited to 'src/mongo/db/s/collection_sharding_runtime.cpp')
-rw-r--r--src/mongo/db/s/collection_sharding_runtime.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp
index c5c264af4c7..0e95190e915 100644
--- a/src/mongo/db/s/collection_sharding_runtime.cpp
+++ b/src/mongo/db/s/collection_sharding_runtime.cpp
@@ -112,11 +112,22 @@ CollectionShardingRuntime* CollectionShardingRuntime::get_UNSAFE(ServiceContext*
ScopedCollectionFilter CollectionShardingRuntime::getOwnershipFilter(
OperationContext* opCtx, OrphanCleanupPolicy orphanCleanupPolicy) {
const auto optReceivedShardVersion = getOperationReceivedVersion(opCtx, _nss);
- invariant(!optReceivedShardVersion || !ChunkVersion::isIgnoredVersion(*optReceivedShardVersion),
- "getOwnershipFilter called by operation that doesn't have a valid shard version");
+ // TODO (SERVER-52764): No operations should be calling getOwnershipFilter without a shard
+ // version
+ //
+ // invariant(optReceivedShardVersion,
+ // "getOwnershipFilter called by operation that doesn't specify shard version");
+ if (!optReceivedShardVersion)
+ return {kUnshardedCollection};
+
+ auto metadata = _getMetadataWithVersionCheckAt(
+ opCtx, repl::ReadConcernArgs::get(opCtx).getArgsAtClusterTime());
+ invariant(!ChunkVersion::isIgnoredVersion(*optReceivedShardVersion) ||
+ !metadata->get().allowMigrations() || !metadata->get().isSharded(),
+ "For sharded collections getOwnershipFilter cannot be relied on without a valid "
+ "shard version");
- return _getMetadataWithVersionCheckAt(opCtx,
- repl::ReadConcernArgs::get(opCtx).getArgsAtClusterTime());
+ return {std::move(metadata)};
}
ScopedCollectionDescription CollectionShardingRuntime::getCollectionDescription(
@@ -335,10 +346,8 @@ CollectionShardingRuntime::_getMetadataWithVersionCheckAt(
!criticalSectionSignal);
}
- if (ChunkVersion::isIgnoredVersion(receivedShardVersion))
- return kUnshardedCollection;
-
- if (receivedShardVersion.isWriteCompatibleWith(wantedShardVersion))
+ if (wantedShardVersion.isWriteCompatibleWith(receivedShardVersion) ||
+ ChunkVersion::isIgnoredVersion(receivedShardVersion))
return optCurrentMetadata;
StaleConfigInfo sci(