diff options
author | Silvia Surroca <silvia.surroca@mongodb.com> | 2022-08-09 14:23:44 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-09 16:02:31 +0000 |
commit | c6e439a9ab036e9f20003623f6d95d9864349ed7 (patch) | |
tree | 9592eaad7eee787c7cdfc34162727d1eee3904eb | |
parent | 0d3499eef76a29bc28015113dd4cc7cb412abf27 (diff) | |
download | mongo-c6e439a9ab036e9f20003623f6d95d9864349ed7.tar.gz |
SERVER-67296 Mark the OpCtx of the configsvr commands used to commit chunk-related DDL ops as interruptible
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp | 35 | ||||
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp | 4 |
2 files changed, 39 insertions, 0 deletions
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<BSONObj> ShardingCatalogManager::commitChunkSplit( const ChunkRange& range, const std::vector<BSONObj>& 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<BSONObj> 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<BSONObj> 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<void(OperationContext*, TxnNumber)> 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<ShardId> 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<BSONObj>, std::vector<BSONObj>> 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/ |