From c6e439a9ab036e9f20003623f6d95d9864349ed7 Mon Sep 17 00:00:00 2001 From: Silvia Surroca Date: Tue, 9 Aug 2022 14:23:44 +0000 Subject: SERVER-67296 Mark the OpCtx of the configsvr commands used to commit chunk-related DDL ops as interruptible --- .../sharding_catalog_manager_chunk_operations.cpp | 35 ++++++++++++++++++++++ ...rding_catalog_manager_collection_operations.cpp | 4 +++ 2 files changed, 39 insertions(+) diff --git a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp index 3fae066d83c..23137c3436a 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp @@ -538,6 +538,11 @@ StatusWith ShardingCatalogManager::commitChunkSplit( const ChunkRange& range, const std::vector& splitPoints, const std::string& shardName) { + + // Mark opCtx as interruptible to ensure that all reads and writes to the metadata collections + // under the exclusive _kChunkOpLock happen on the same term. + opCtx->setAlwaysInterruptAtStepDownOrUp(); + // Take _kChunkOpLock in exclusive mode to prevent concurrent chunk splits, merges, and // migrations // TODO(SERVER-25359): Replace with a collection-specific lock map to allow splits/merges/ @@ -887,6 +892,10 @@ StatusWith ShardingCatalogManager::commitChunksMerge( return {ErrorCodes::IllegalOperation, "chunk operation requires validAfter timestamp"}; } + // Mark opCtx as interruptible to ensure that all reads and writes to the metadata collections + // under the exclusive _kChunkOpLock happen on the same term. + opCtx->setAlwaysInterruptAtStepDownOrUp(); + // Take _kChunkOpLock in exclusive mode to prevent concurrent chunk splits, merges, and // migrations // TODO(SERVER-25359): Replace with a collection-specific lock map to allow splits/merges/ @@ -1041,6 +1050,10 @@ StatusWith ShardingCatalogManager::commitChunkMigration( return {ErrorCodes::IllegalOperation, "chunk operation requires validAfter timestamp"}; } + // Mark opCtx as interruptible to ensure that all reads and writes to the metadata collections + // under the exclusive _kChunkOpLock happen on the same term. + opCtx->setAlwaysInterruptAtStepDownOrUp(); + // TODO(SERVER-53283): Remove the logic around fcvRegion to re-enable // the concurrent execution of moveChunk() and setFCV(). FixedFCVRegion fcvRegion(opCtx); @@ -1316,6 +1329,10 @@ void ShardingCatalogManager::upgradeChunksHistory(OperationContext* opCtx, auto const catalogClient = Grid::get(opCtx)->catalogClient(); const auto shardRegistry = Grid::get(opCtx)->shardRegistry(); + // Mark opCtx as interruptible to ensure that all reads and writes to the metadata collections + // under the exclusive _kChunkOpLock happen on the same term. + opCtx->setAlwaysInterruptAtStepDownOrUp(); + FixedFCVRegion fcvRegion(opCtx); uassert(ErrorCodes::ConflictingOperationInProgress, "Cannot upgrade the chunks history while the cluster is being upgraded or downgraded", @@ -1458,6 +1475,11 @@ void ShardingCatalogManager::clearJumboFlag(OperationContext* opCtx, const NamespaceString& nss, const OID& collectionEpoch, const ChunkRange& chunk) { + + // Mark opCtx as interruptible to ensure that all reads and writes to the metadata collections + // under the exclusive _kChunkOpLock happen on the same term. + opCtx->setAlwaysInterruptAtStepDownOrUp(); + auto const configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard(); // Take _kChunkOpLock in exclusive mode to prevent concurrent chunk splits, merges, and @@ -1603,6 +1625,11 @@ void ShardingCatalogManager::ensureChunkVersionIsGreaterThan( const BSONObj& minKey, const BSONObj& maxKey, const ChunkVersion& version) { + + // Mark opCtx as interruptible to ensure that all reads and writes to the metadata + // collections under the exclusive _kChunkOpLock happen on the same term. + opCtx->setAlwaysInterruptAtStepDownOrUp(); + auto earlyReturnBeforeDoingWriteGuard = makeGuard([&] { // Ensure waiting for writeConcern of the data read. repl::ReplClientInfo::forClient(opCtx->getClient()).setLastOpToSystemLastOpTime(opCtx); @@ -1804,6 +1831,10 @@ void ShardingCatalogManager::bumpMultipleCollectionVersionsAndChangeMetadataInTx unique_function changeMetadataFunc, const WriteConcernOptions& writeConcern) { + // Mark opCtx as interruptible to ensure that all reads and writes to the metadata collections + // under the exclusive _kChunkOpLock happen on the same term. + opCtx->setAlwaysInterruptAtStepDownOrUp(); + // Take _kChunkOpLock in exclusive mode to prevent concurrent chunk splits, merges, and // migrations Lock::ExclusiveLock lk(opCtx, opCtx->lockState(), _kChunkOpLock); @@ -1918,6 +1949,10 @@ void ShardingCatalogManager::setAllowMigrationsAndBumpOneChunk( bool allowMigrations) { std::set shardsIds; { + // Mark opCtx as interruptible to ensure that all reads and writes to the metadata + // collections under the exclusive _kChunkOpLock happen on the same term. + opCtx->setAlwaysInterruptAtStepDownOrUp(); + // Take _kChunkOpLock in exclusive mode to prevent concurrent chunk splits, merges, and // migrations Lock::ExclusiveLock lk(opCtx, opCtx->lockState(), _kChunkOpLock); 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 95cda739aec..79f1f02df54 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 @@ -297,6 +297,10 @@ std::pair, std::vector> makeChunkAndTagUpdatesForR void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx, const NamespaceString& nss, const ShardKeyPattern& newShardKeyPattern) { + // Mark opCtx as interruptible to ensure that all reads and writes to the metadata collections + // under the exclusive _kChunkOpLock happen on the same term. + opCtx->setAlwaysInterruptAtStepDownOrUp(); + // Take _kChunkOpLock in exclusive mode to prevent concurrent chunk splits, merges, and // migrations. Take _kZoneOpLock in exclusive mode to prevent concurrent zone operations. // TODO(SERVER-25359): Replace with a collection-specific lock map to allow splits/merges/ -- cgit v1.2.1