diff options
Diffstat (limited to 'src/mongo/db/s/collection_sharding_runtime.cpp')
| -rw-r--r-- | src/mongo/db/s/collection_sharding_runtime.cpp | 59 |
1 files changed, 21 insertions, 38 deletions
diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp index 4c5950b4f75..91a8d3d6090 100644 --- a/src/mongo/db/s/collection_sharding_runtime.cpp +++ b/src/mongo/db/s/collection_sharding_runtime.cpp @@ -102,9 +102,8 @@ ScopedCollectionFilter CollectionShardingRuntime::getOwnershipFilter( if (!supportNonVersionedOperations) { optReceivedShardVersion = getOperationReceivedVersion(opCtx, _nss); // No operations should be calling getOwnershipFilter without a shard version - tassert(7032300, - "getOwnershipFilter called by operation that doesn't specify shard version", - optReceivedShardVersion); + invariant(optReceivedShardVersion, + "getOwnershipFilter called by operation that doesn't specify shard version"); } auto metadata = @@ -112,6 +111,13 @@ 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)}; } @@ -157,10 +163,6 @@ 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&, @@ -196,9 +198,8 @@ void CollectionShardingRuntime::setFilteringMetadata(OperationContext* opCtx, void CollectionShardingRuntime::setFilteringMetadata_withLock(OperationContext* opCtx, CollectionMetadata newMetadata, const CSRLock& csrExclusiveLock) { - tassert(7032302, - str::stream() << "Namespace " << _nss.ns() << " must never be sharded.", - !newMetadata.isSharded() || !_nss.isNamespaceAlwaysUnsharded()); + invariant(!newMetadata.isSharded() || !_nss.isNamespaceAlwaysUnsharded(), + str::stream() << "Namespace " << _nss.ns() << " must never be sharded."); stdx::lock_guard lk(_metadataManagerLock); @@ -210,11 +211,9 @@ void CollectionShardingRuntime::setFilteringMetadata_withLock(OperationContext* _metadataType = MetadataType::kUnsharded; _metadataManager.reset(); ++_numMetadataManagerChanges; - return; - } - - _metadataType = MetadataType::kSharded; - if (!_metadataManager || !newMetadata.uuidMatches(_metadataManager->getCollectionUuid())) { + } else if (!_metadataManager || + !newMetadata.uuidMatches(_metadataManager->getCollectionUuid())) { + _metadataType = MetadataType::kSharded; _metadataManager = std::make_shared<MetadataManager>( opCtx->getServiceContext(), _nss, _rangeDeleterExecutor, newMetadata); ++_numMetadataManagerChanges; @@ -223,8 +222,7 @@ void CollectionShardingRuntime::setFilteringMetadata_withLock(OperationContext* } } -void CollectionShardingRuntime::_clearFilteringMetadata(OperationContext* opCtx, - bool clearMetadataManager) { +void CollectionShardingRuntime::clearFilteringMetadata(OperationContext* opCtx) { const auto csrLock = CSRLock::lockExclusive(opCtx, this); if (_shardVersionInRecoverOrRefresh) { _shardVersionInRecoverOrRefresh->cancellationSource.cancel(); @@ -236,23 +234,12 @@ void CollectionShardingRuntime::_clearFilteringMetadata(OperationContext* opCtx, 1, "Clearing metadata for collection {namespace}", "Clearing collection metadata", - "namespace"_attr = _nss, - "clearMetadataManager"_attr = clearMetadataManager); + "namespace"_attr = _nss); _metadataType = MetadataType::kUnknown; - if (clearMetadataManager) - _metadataManager.reset(); + _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) { @@ -276,7 +263,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->_metadataType != MetadataType::kSharded || + if (!self->_metadataManager || (collectionUuid != self->_metadataManager->getCollectionUuid())) { return {ErrorCodes::ConflictingOperationInProgress, "Collection being migrated was dropped and created or otherwise had its " @@ -434,7 +421,7 @@ void CollectionShardingRuntime::appendShardVersion(BSONObjBuilder* builder) { size_t CollectionShardingRuntime::numberOfRangesScheduledForDeletion() const { stdx::lock_guard lk(_metadataManagerLock); - if (_metadataType == MetadataType::kSharded) { + if (_metadataManager) { return _metadataManager->numberOfRangesScheduledForDeletion(); } return 0; @@ -474,9 +461,7 @@ CollectionCriticalSection::CollectionCriticalSection(OperationContext* opCtx, Milliseconds(migrationLockAcquisitionMaxWaitMS.load())); auto* const csr = CollectionShardingRuntime::get(_opCtx, _nss); auto csrLock = CollectionShardingRuntime::CSRLock::lockExclusive(opCtx, csr); - tassert(7032305, - "Collection metadata unknown when entering critical section", - csr->getCurrentMetadataIfKnown()); + invariant(csr->getCurrentMetadataIfKnown()); csr->enterCriticalSectionCatchUpPhase(csrLock, _reason); } @@ -497,9 +482,7 @@ void CollectionCriticalSection::enterCommitPhase() { Milliseconds(migrationLockAcquisitionMaxWaitMS.load())); auto* const csr = CollectionShardingRuntime::get(_opCtx, _nss); auto csrLock = CollectionShardingRuntime::CSRLock::lockExclusive(_opCtx, csr); - tassert(7032304, - "Collection metadata unknown when entering critical section commit phase", - csr->getCurrentMetadataIfKnown()); + invariant(csr->getCurrentMetadataIfKnown()); csr->enterCriticalSectionCommitPhase(csrLock, _reason); } |
