summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/collection_sharding_runtime.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-14 14:26:38 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-14 14:26:38 -0300
commit294bc6ecabf14c09c9bc8644704921dcf97cb44e (patch)
tree279b1e0bab53901a1647ac63c1c724f0f789a663 /src/mongo/db/s/collection_sharding_runtime.cpp
parent70be7c27a251621187a1de533462ae2bb1e3bd39 (diff)
parent1e917fd798aa25b7066d4b414b51184f13d5a092 (diff)
Update upstream source from tag 'upstream/6.0.10'debian/6.0.10-1
Update to upstream version '6.0.10' with Debian dir 2d176fa254eee97b139f712fec5709641335a8c3
Diffstat (limited to 'src/mongo/db/s/collection_sharding_runtime.cpp')
-rw-r--r--src/mongo/db/s/collection_sharding_runtime.cpp59
1 files changed, 38 insertions, 21 deletions
diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp
index 91a8d3d6090..4c5950b4f75 100644
--- a/src/mongo/db/s/collection_sharding_runtime.cpp
+++ b/src/mongo/db/s/collection_sharding_runtime.cpp
@@ -102,8 +102,9 @@ ScopedCollectionFilter CollectionShardingRuntime::getOwnershipFilter(
if (!supportNonVersionedOperations) {
optReceivedShardVersion = getOperationReceivedVersion(opCtx, _nss);
// No operations should be calling getOwnershipFilter without a shard version
- invariant(optReceivedShardVersion,
- "getOwnershipFilter called by operation that doesn't specify shard version");
+ tassert(7032300,
+ "getOwnershipFilter called by operation that doesn't specify shard version",
+ optReceivedShardVersion);
}
auto metadata =
@@ -111,13 +112,6 @@ ScopedCollectionFilter CollectionShardingRuntime::getOwnershipFilter(
repl::ReadConcernArgs::get(opCtx).getArgsAtClusterTime(),
supportNonVersionedOperations);
- if (!supportNonVersionedOperations) {
- invariant(!ChunkVersion::isIgnoredVersion(*optReceivedShardVersion) ||
- !metadata->get().allowMigrations() || !metadata->get().isSharded(),
- "For sharded collections getOwnershipFilter cannot be relied on without a valid "
- "shard version");
- }
-
return {std::move(metadata)};
}
@@ -163,6 +157,10 @@ void CollectionShardingRuntime::checkShardVersionOrThrow(OperationContext* opCtx
void CollectionShardingRuntime::enterCriticalSectionCatchUpPhase(const CSRLock&,
const BSONObj& reason) {
_critSec.enterCriticalSectionCatchUpPhase(reason);
+
+ if (_shardVersionInRecoverOrRefresh) {
+ _shardVersionInRecoverOrRefresh->cancellationSource.cancel();
+ }
}
void CollectionShardingRuntime::enterCriticalSectionCommitPhase(const CSRLock&,
@@ -198,8 +196,9 @@ void CollectionShardingRuntime::setFilteringMetadata(OperationContext* opCtx,
void CollectionShardingRuntime::setFilteringMetadata_withLock(OperationContext* opCtx,
CollectionMetadata newMetadata,
const CSRLock& csrExclusiveLock) {
- invariant(!newMetadata.isSharded() || !_nss.isNamespaceAlwaysUnsharded(),
- str::stream() << "Namespace " << _nss.ns() << " must never be sharded.");
+ tassert(7032302,
+ str::stream() << "Namespace " << _nss.ns() << " must never be sharded.",
+ !newMetadata.isSharded() || !_nss.isNamespaceAlwaysUnsharded());
stdx::lock_guard lk(_metadataManagerLock);
@@ -211,9 +210,11 @@ void CollectionShardingRuntime::setFilteringMetadata_withLock(OperationContext*
_metadataType = MetadataType::kUnsharded;
_metadataManager.reset();
++_numMetadataManagerChanges;
- } else if (!_metadataManager ||
- !newMetadata.uuidMatches(_metadataManager->getCollectionUuid())) {
- _metadataType = MetadataType::kSharded;
+ return;
+ }
+
+ _metadataType = MetadataType::kSharded;
+ if (!_metadataManager || !newMetadata.uuidMatches(_metadataManager->getCollectionUuid())) {
_metadataManager = std::make_shared<MetadataManager>(
opCtx->getServiceContext(), _nss, _rangeDeleterExecutor, newMetadata);
++_numMetadataManagerChanges;
@@ -222,7 +223,8 @@ void CollectionShardingRuntime::setFilteringMetadata_withLock(OperationContext*
}
}
-void CollectionShardingRuntime::clearFilteringMetadata(OperationContext* opCtx) {
+void CollectionShardingRuntime::_clearFilteringMetadata(OperationContext* opCtx,
+ bool clearMetadataManager) {
const auto csrLock = CSRLock::lockExclusive(opCtx, this);
if (_shardVersionInRecoverOrRefresh) {
_shardVersionInRecoverOrRefresh->cancellationSource.cancel();
@@ -234,12 +236,23 @@ void CollectionShardingRuntime::clearFilteringMetadata(OperationContext* opCtx)
1,
"Clearing metadata for collection {namespace}",
"Clearing collection metadata",
- "namespace"_attr = _nss);
+ "namespace"_attr = _nss,
+ "clearMetadataManager"_attr = clearMetadataManager);
_metadataType = MetadataType::kUnknown;
- _metadataManager.reset();
+ if (clearMetadataManager)
+ _metadataManager.reset();
}
}
+void CollectionShardingRuntime::clearFilteringMetadata(OperationContext* opCtx) {
+ _clearFilteringMetadata(opCtx, /* clearMetadataManager */ false);
+}
+
+void CollectionShardingRuntime::clearFilteringMetadataForDroppedCollection(
+ OperationContext* opCtx) {
+ _clearFilteringMetadata(opCtx, /* clearMetadataManager */ true);
+}
+
SharedSemiFuture<void> CollectionShardingRuntime::cleanUpRange(ChunkRange const& range,
const UUID& migrationId,
CleanWhen when) {
@@ -263,7 +276,7 @@ Status CollectionShardingRuntime::waitForClean(OperationContext* opCtx,
// If the metadata was reset, or the collection was dropped and recreated since the
// metadata manager was created, return an error.
- if (!self->_metadataManager ||
+ if (self->_metadataType != MetadataType::kSharded ||
(collectionUuid != self->_metadataManager->getCollectionUuid())) {
return {ErrorCodes::ConflictingOperationInProgress,
"Collection being migrated was dropped and created or otherwise had its "
@@ -421,7 +434,7 @@ void CollectionShardingRuntime::appendShardVersion(BSONObjBuilder* builder) {
size_t CollectionShardingRuntime::numberOfRangesScheduledForDeletion() const {
stdx::lock_guard lk(_metadataManagerLock);
- if (_metadataManager) {
+ if (_metadataType == MetadataType::kSharded) {
return _metadataManager->numberOfRangesScheduledForDeletion();
}
return 0;
@@ -461,7 +474,9 @@ CollectionCriticalSection::CollectionCriticalSection(OperationContext* opCtx,
Milliseconds(migrationLockAcquisitionMaxWaitMS.load()));
auto* const csr = CollectionShardingRuntime::get(_opCtx, _nss);
auto csrLock = CollectionShardingRuntime::CSRLock::lockExclusive(opCtx, csr);
- invariant(csr->getCurrentMetadataIfKnown());
+ tassert(7032305,
+ "Collection metadata unknown when entering critical section",
+ csr->getCurrentMetadataIfKnown());
csr->enterCriticalSectionCatchUpPhase(csrLock, _reason);
}
@@ -482,7 +497,9 @@ void CollectionCriticalSection::enterCommitPhase() {
Milliseconds(migrationLockAcquisitionMaxWaitMS.load()));
auto* const csr = CollectionShardingRuntime::get(_opCtx, _nss);
auto csrLock = CollectionShardingRuntime::CSRLock::lockExclusive(_opCtx, csr);
- invariant(csr->getCurrentMetadataIfKnown());
+ tassert(7032304,
+ "Collection metadata unknown when entering critical section commit phase",
+ csr->getCurrentMetadataIfKnown());
csr->enterCriticalSectionCommitPhase(csrLock, _reason);
}