diff options
Diffstat (limited to 'src/mongo/db')
17 files changed, 82 insertions, 77 deletions
diff --git a/src/mongo/db/s/cleanup_orphaned_cmd.cpp b/src/mongo/db/s/cleanup_orphaned_cmd.cpp index 2e6ab879782..2a122a284bd 100644 --- a/src/mongo/db/s/cleanup_orphaned_cmd.cpp +++ b/src/mongo/db/s/cleanup_orphaned_cmd.cpp @@ -207,7 +207,7 @@ public: return false; } - onShardVersionMismatch(opCtx, nss, boost::none); + onCollectionPlacementVersionMismatch(opCtx, nss, boost::none); CleanupResult cleanupResult = cleanupOrphanedData(opCtx, nss, startingFromKey, &errmsg); diff --git a/src/mongo/db/s/flush_resharding_state_change_command.cpp b/src/mongo/db/s/flush_resharding_state_change_command.cpp index 2e665e5a280..b9494be2d30 100644 --- a/src/mongo/db/s/flush_resharding_state_change_command.cpp +++ b/src/mongo/db/s/flush_resharding_state_change_command.cpp @@ -120,8 +120,8 @@ public: } auto opCtx = tc->makeOperationContext(); - onShardVersionMismatch( - opCtx.get(), nss, boost::none /* shardVersionReceived */); + onCollectionPlacementVersionMismatch( + opCtx.get(), nss, boost::none /* chunkVersionReceived */); }) .onError([](const Status& status) { LOGV2_WARNING(5808100, diff --git a/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp b/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp index 5ddda7894a8..7c49db1f8a4 100644 --- a/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp +++ b/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp @@ -142,7 +142,7 @@ public: "Forcing remote routing table refresh for {namespace}", "Forcing remote routing table refresh", "namespace"_attr = ns()); - onShardVersionMismatch(opCtx, ns(), boost::none); + onCollectionPlacementVersionMismatch(opCtx, ns(), boost::none); } CatalogCacheLoader::get(opCtx).waitForCollectionFlush(opCtx, ns()); diff --git a/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp b/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp index f0dfc08b1c1..fc9f046339a 100644 --- a/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp +++ b/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp @@ -129,7 +129,7 @@ public: // We force a refresh immediately after registering this migration to guarantee that this // shard will not receive a chunk after refreshing. - onShardVersionMismatch(opCtx, nss, boost::none); + onCollectionPlacementVersionMismatch(opCtx, nss, boost::none); const auto shardId = ShardingState::get(opCtx)->shardId(); const auto collectionEpoch = [&] { diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp index 45be08187fa..340e3c0a983 100644 --- a/src/mongo/db/s/migration_source_manager.cpp +++ b/src/mongo/db/s/migration_source_manager.cpp @@ -162,7 +162,7 @@ MigrationSourceManager::MigrationSourceManager(OperationContext* opCtx, // Make sure the latest shard version is recovered as of the time of the invocation of the // command. - onShardVersionMismatch(_opCtx, nss(), boost::none); + onCollectionPlacementVersionMismatch(_opCtx, nss(), boost::none); const auto shardId = ShardingState::get(opCtx)->shardId(); @@ -514,8 +514,8 @@ void MigrationSourceManager::commitChunkMetadataOnConfig() { } scopedGuard.dismiss(); _cleanup(false); - // Best-effort recover of the shard version. - onShardVersionMismatchNoExcept(_opCtx, nss(), boost::none).ignore(); + // Best-effort recover of the chunk version. + onCollectionPlacementVersionMismatchNoExcept(_opCtx, nss(), boost::none).ignore(); throw; } diff --git a/src/mongo/db/s/migration_util.cpp b/src/mongo/db/s/migration_util.cpp index d3110cb8f13..104d7e43f18 100644 --- a/src/mongo/db/s/migration_util.cpp +++ b/src/mongo/db/s/migration_util.cpp @@ -249,7 +249,7 @@ void refreshFilteringMetadataUntilSuccess(OperationContext* opCtx, const Namespa hangInRefreshFilteringMetadataUntilSuccessInterruptible.pauseWhileSet(newOpCtx); try { - onShardVersionMismatch(newOpCtx, nss, boost::none); + onCollectionPlacementVersionMismatch(newOpCtx, nss, boost::none); } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) { // Can throw NamespaceNotFound if the collection/database was dropped } @@ -259,7 +259,7 @@ void refreshFilteringMetadataUntilSuccess(OperationContext* opCtx, const Namespa hangInRefreshFilteringMetadataUntilSuccessThenSimulateErrorUninterruptible .pauseWhileSet(); uasserted(ErrorCodes::InternalError, - "simulate an error response for onShardVersionMismatch"); + "simulate an error response for onCollectionPlacementVersionMismatch"); } }); } @@ -507,7 +507,7 @@ ExecutorFuture<void> submitRangeDeletionTask(OperationContext* opCtx, logAttrs(deletionTask.getNss()), "status"_attr = redact(status)); - onShardVersionMismatch( + onCollectionPlacementVersionMismatch( uniqueOpCtx.get(), deletionTask.getNss(), boost::none); return status; @@ -1224,7 +1224,7 @@ void drainMigrationsPendingRecovery(OperationContext* opCtx) { while (store.count(opCtx)) { store.forEach(opCtx, BSONObj(), [opCtx](const MigrationCoordinatorDocument& doc) { try { - onShardVersionMismatch(opCtx, doc.getNss(), boost::none); + onCollectionPlacementVersionMismatch(opCtx, doc.getNss(), boost::none); } catch (DBException& ex) { ex.addContext(str::stream() << "Failed to recover pending migration for document " << doc.toBSON()); diff --git a/src/mongo/db/s/range_deleter_service.cpp b/src/mongo/db/s/range_deleter_service.cpp index 12d544794a6..267905c0632 100644 --- a/src/mongo/db/s/range_deleter_service.cpp +++ b/src/mongo/db/s/range_deleter_service.cpp @@ -66,7 +66,7 @@ BSONObj getShardKeyPattern(OperationContext* opCtx, optNss = collection.getNss(); } - onShardVersionMismatchNoExcept(opCtx, *optNss, boost::none).ignore(); + onCollectionPlacementVersionMismatchNoExcept(opCtx, *optNss, boost::none).ignore(); continue; } } diff --git a/src/mongo/db/s/resharding/resharding_data_copy_util.h b/src/mongo/db/s/resharding/resharding_data_copy_util.h index 807ddaf6bfc..dbe098ef8da 100644 --- a/src/mongo/db/s/resharding/resharding_data_copy_util.h +++ b/src/mongo/db/s/resharding/resharding_data_copy_util.h @@ -169,7 +169,8 @@ auto withOneStaleConfigRetry(OperationContext* opCtx, Callable&& callable) { } catch (const ExceptionForCat<ErrorCategory::StaleShardVersionError>& ex) { if (auto sce = ex.extraInfo<StaleConfigInfo>()) { const auto refreshed = - onShardVersionMismatchNoExcept(opCtx, sce->getNss(), sce->getVersionReceived()) + onCollectionPlacementVersionMismatchNoExcept( + opCtx, sce->getNss(), ChunkVersion(sce->getVersionReceived())) .isOK(); if (refreshed) { diff --git a/src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp b/src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp index 22dae7b285d..3070482a434 100644 --- a/src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp +++ b/src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp @@ -367,7 +367,8 @@ void clearFilteringMetadata(OperationContext* opCtx, } auto opCtx = tc->makeOperationContext(); - onShardVersionMismatch(opCtx.get(), nss, boost::none /* shardVersionReceived */); + onCollectionPlacementVersionMismatch( + opCtx.get(), nss, boost::none /* chunkVersionReceived */); }) .until([](const Status& status) { if (!status.isOK()) { diff --git a/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp b/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp index e228de1cd62..f8cc395dd29 100644 --- a/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp +++ b/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp @@ -92,8 +92,8 @@ ScopedOperationCompletionShardingActions::~ScopedOperationCompletionShardingActi resharding_metrics::onCriticalSectionError(_opCtx, *staleInfo); } - auto handleMismatchStatus = onShardVersionMismatchNoExcept( - _opCtx, staleInfo->getNss(), staleInfo->getVersionReceived()); + auto handleMismatchStatus = onCollectionPlacementVersionMismatchNoExcept( + _opCtx, staleInfo->getNss(), ChunkVersion(staleInfo->getVersionReceived())); if (!handleMismatchStatus.isOK()) LOGV2(22053, "Failed to handle stale version exception as part of the current operation: " diff --git a/src/mongo/db/s/shard_filtering_metadata_refresh.cpp b/src/mongo/db/s/shard_filtering_metadata_refresh.cpp index b5174ae65bb..3bff53c1488 100644 --- a/src/mongo/db/s/shard_filtering_metadata_refresh.cpp +++ b/src/mongo/db/s/shard_filtering_metadata_refresh.cpp @@ -294,16 +294,18 @@ void onDbVersionMismatch(OperationContext* opCtx, /** * Blocking method, which will wait for any concurrent operations that could change the shard - * version to complete (namely critical section and concurrent onShardVersionMismatch invocations). + * version to complete (namely critical section and concurrent onCollectionPlacementVersionMismatch + * invocations). * * Returns 'true' if there were concurrent operations that had to be joined (in which case all locks * will be dropped). If there were none, returns false and the locks continue to be held. */ -bool joinShardVersionOperation(OperationContext* opCtx, - CollectionShardingRuntime* csr, - boost::optional<Lock::DBLock>* dbLock, - boost::optional<Lock::CollectionLock>* collLock, - boost::optional<CollectionShardingRuntime::CSRLock>* csrLock) { +bool joinCollectionPlacementVersionOperation( + OperationContext* opCtx, + CollectionShardingRuntime* csr, + boost::optional<Lock::DBLock>* dbLock, + boost::optional<Lock::CollectionLock>* collLock, + boost::optional<CollectionShardingRuntime::CSRLock>* csrLock) { invariant(dbLock->has_value()); invariant(collLock->has_value()); invariant(csrLock->has_value()); @@ -337,10 +339,11 @@ bool joinShardVersionOperation(OperationContext* opCtx, return false; } -SharedSemiFuture<void> recoverRefreshShardVersion(ServiceContext* serviceContext, - const NamespaceString& nss, - bool runRecover, - CancellationToken cancellationToken) { +SharedSemiFuture<void> recoverRefreshCollectionPlacementVersion( + ServiceContext* serviceContext, + const NamespaceString& nss, + bool runRecover, + CancellationToken cancellationToken) { auto executor = Grid::get(serviceContext)->getExecutorPool()->getFixedExecutor(); return ExecutorFuture<void>(executor) .then([=] { @@ -432,8 +435,8 @@ SharedSemiFuture<void> recoverRefreshShardVersion(ServiceContext* serviceContext if (cancellationToken.isCanceled() && (status.isOK() || status == ErrorCodes::Interrupted)) { uasserted(ErrorCodes::ShardVersionRefreshCanceled, - "Shard version refresh canceled by an interruption, probably due to a " - "'clearFilteringMetadata'"); + "Collection placement version refresh canceled by an interruption, " + "probably due to a 'clearFilteringMetadata'"); } return status; }) @@ -443,9 +446,9 @@ SharedSemiFuture<void> recoverRefreshShardVersion(ServiceContext* serviceContext } // namespace -void onShardVersionMismatch(OperationContext* opCtx, - const NamespaceString& nss, - boost::optional<ShardVersion> shardVersionReceived) { +void onCollectionPlacementVersionMismatch(OperationContext* opCtx, + const NamespaceString& nss, + boost::optional<ChunkVersion> chunkVersionReceived) { invariant(!opCtx->lockState()->isLocked()); invariant(!opCtx->getClient()->isInDirectClient()); invariant(ShardingState::get(opCtx)->canAcceptShardedCommands()); @@ -460,11 +463,11 @@ void onShardVersionMismatch(OperationContext* opCtx, LOGV2_DEBUG(22061, 2, - "Metadata refresh requested for {namespace} at shard version " - "{shardVersionReceived}", + "Metadata refresh requested for {namespace} at chunk version " + "{chunkVersionReceived}", "Metadata refresh requested for collection", "namespace"_attr = nss, - "shardVersionReceived"_attr = shardVersionReceived); + "chunkVersionReceived"_attr = chunkVersionReceived); while (true) { boost::optional<SharedSemiFuture<void>> inRecoverOrRefresh; @@ -477,19 +480,21 @@ void onShardVersionMismatch(OperationContext* opCtx, auto* const csr = CollectionShardingRuntime::get(opCtx, nss); - if (shardVersionReceived) { + if (chunkVersionReceived) { boost::optional<CollectionShardingRuntime::CSRLock> csrLock = CollectionShardingRuntime::CSRLock::lockShared(opCtx, csr); - if (joinShardVersionOperation(opCtx, csr, &dbLock, &collLock, &csrLock)) { + if (joinCollectionPlacementVersionOperation( + opCtx, csr, &dbLock, &collLock, &csrLock)) { continue; } if (auto metadata = csr->getCurrentMetadataIfKnown()) { - const auto currentShardVersion = metadata->getShardVersion(); + const auto currentCollectionPlacementVersion = metadata->getShardVersion(); // Don't need to remotely reload if the requested version is smaller than the // known one. This means that the remote side is behind. - if (shardVersionReceived->isOlderOrEqualThan(currentShardVersion)) { + if (chunkVersionReceived->isOlderOrEqualThan( + currentCollectionPlacementVersion)) { return; } } @@ -498,7 +503,7 @@ void onShardVersionMismatch(OperationContext* opCtx, boost::optional<CollectionShardingRuntime::CSRLock> csrLock = CollectionShardingRuntime::CSRLock::lockExclusive(opCtx, csr); - if (joinShardVersionOperation(opCtx, csr, &dbLock, &collLock, &csrLock)) { + if (joinCollectionPlacementVersionOperation(opCtx, csr, &dbLock, &collLock, &csrLock)) { continue; } @@ -510,7 +515,7 @@ void onShardVersionMismatch(OperationContext* opCtx, CancellationSource cancellationSource; CancellationToken cancellationToken = cancellationSource.token(); csr->setShardVersionRecoverRefreshFuture( - recoverRefreshShardVersion( + recoverRefreshCollectionPlacementVersion( opCtx->getServiceContext(), nss, runRecover, std::move(cancellationToken)), std::move(cancellationSource), *csrLock); @@ -528,11 +533,12 @@ void onShardVersionMismatch(OperationContext* opCtx, } } -Status onShardVersionMismatchNoExcept(OperationContext* opCtx, - const NamespaceString& nss, - boost::optional<ShardVersion> shardVersionReceived) noexcept { +Status onCollectionPlacementVersionMismatchNoExcept( + OperationContext* opCtx, + const NamespaceString& nss, + boost::optional<ChunkVersion> chunkVersionReceived) noexcept { try { - onShardVersionMismatch(opCtx, nss, shardVersionReceived); + onCollectionPlacementVersionMismatch(opCtx, nss, chunkVersionReceived); return Status::OK(); } catch (const DBException& ex) { LOGV2(22062, diff --git a/src/mongo/db/s/shard_filtering_metadata_refresh.h b/src/mongo/db/s/shard_filtering_metadata_refresh.h index 641eb870bfb..6da07eb6d8b 100644 --- a/src/mongo/db/s/shard_filtering_metadata_refresh.h +++ b/src/mongo/db/s/shard_filtering_metadata_refresh.h @@ -40,10 +40,11 @@ class OperationContext; /** * Must be invoked whenever code, which is executing on a shard encounters a StaleConfig exception - * and should be passed the 'version received' from the exception. If the shard's current version is - * behind 'shardVersionReceived', causes the shard's filtering metadata to be refreshed from the - * config server, otherwise does nothing and immediately returns. If there are other threads - * currently performing refresh, blocks so that only one of them hits the config server. + * and should be passed the placement version from the 'version received' in the exception. If the + * shard's current placement version is behind 'chunkVersionReceived', causes the shard's filtering + * metadata to be refreshed from the config server, otherwise does nothing and immediately returns. + * If there are other threads currently performing refresh, blocks so that only one of them hits the + * config server. * * If refresh fails for any reason (most commonly ExceededTimeLimit), returns a failed status. * @@ -55,13 +56,14 @@ class OperationContext; * execution state in the response. This is specifically problematic for write commands, which are * expected to return the set of write batch entries that succeeded. */ -Status onShardVersionMismatchNoExcept(OperationContext* opCtx, - const NamespaceString& nss, - boost::optional<ShardVersion> shardVersionReceived) noexcept; +Status onCollectionPlacementVersionMismatchNoExcept( + OperationContext* opCtx, + const NamespaceString& nss, + boost::optional<ChunkVersion> chunkVersionReceived) noexcept; -void onShardVersionMismatch(OperationContext* opCtx, - const NamespaceString& nss, - boost::optional<ShardVersion> shardVersionReceived); +void onCollectionPlacementVersionMismatch(OperationContext* opCtx, + const NamespaceString& nss, + boost::optional<ChunkVersion> chunkVersionReceived); /** * Unconditionally get the shard's filtering metadata from the config server on the calling thread. diff --git a/src/mongo/db/s/shardsvr_merge_chunks_command.cpp b/src/mongo/db/s/shardsvr_merge_chunks_command.cpp index de7bf83bc26..4fc798e10b7 100644 --- a/src/mongo/db/s/shardsvr_merge_chunks_command.cpp +++ b/src/mongo/db/s/shardsvr_merge_chunks_command.cpp @@ -95,7 +95,7 @@ void mergeChunks(OperationContext* opCtx, // Check that the preconditions for merge chunks are met and throw StaleShardVersion otherwise. const auto metadataBeforeMerge = [&]() { - onShardVersionMismatch(opCtx, nss, boost::none); + onCollectionPlacementVersionMismatch(opCtx, nss, boost::none); OperationShardingState::unsetShardRoleForLegacyDDLOperationsSentWithShardVersionIfNeeded( opCtx, nss); const auto metadata = checkCollectionIdentity(opCtx, nss, expectedEpoch, expectedTimestamp); @@ -107,20 +107,14 @@ void mergeChunks(OperationContext* opCtx, auto cmdResponse = commitMergeOnConfigServer( opCtx, nss, expectedEpoch, expectedTimestamp, chunkRange, metadataBeforeMerge); - auto shardVersionReceived = [&]() -> boost::optional<ShardVersion> { + auto chunkVersionReceived = [&]() -> boost::optional<ChunkVersion> { // Old versions might not have the shardVersion field if (cmdResponse.response[ChunkVersion::kChunkVersionField]) { - ChunkVersion placementVersion = - ChunkVersion::parse(cmdResponse.response[ChunkVersion::kChunkVersionField]); - return ShardVersion( - placementVersion, - CollectionIndexes{ - CollectionGeneration{placementVersion.epoch(), placementVersion.getTimestamp()}, - boost::none}); + return ChunkVersion::parse(cmdResponse.response[ChunkVersion::kChunkVersionField]); } return boost::none; }(); - onShardVersionMismatch(opCtx, nss, std::move(shardVersionReceived)); + onCollectionPlacementVersionMismatch(opCtx, nss, std::move(chunkVersionReceived)); uassertStatusOKWithContext(cmdResponse.commandStatus, "Failed to commit chunk merge"); uassertStatusOKWithContext(cmdResponse.writeConcernStatus, "Failed to commit chunk merge"); diff --git a/src/mongo/db/s/shardsvr_split_chunk_command.cpp b/src/mongo/db/s/shardsvr_split_chunk_command.cpp index c62a3d07c27..0e540e347a1 100644 --- a/src/mongo/db/s/shardsvr_split_chunk_command.cpp +++ b/src/mongo/db/s/shardsvr_split_chunk_command.cpp @@ -161,7 +161,7 @@ public: // Check that the preconditions for split chunk are met and throw StaleShardVersion // otherwise. { - onShardVersionMismatch(opCtx, nss, boost::none); + onCollectionPlacementVersionMismatch(opCtx, nss, boost::none); OperationShardingState:: unsetShardRoleForLegacyDDLOperationsSentWithShardVersionIfNeeded(opCtx, nss); const auto metadata = checkCollectionIdentity( diff --git a/src/mongo/db/s/split_chunk.cpp b/src/mongo/db/s/split_chunk.cpp index 5cdec99ab46..1b0d2b3806f 100644 --- a/src/mongo/db/s/split_chunk.cpp +++ b/src/mongo/db/s/split_chunk.cpp @@ -254,20 +254,14 @@ StatusWith<boost::optional<ChunkRange>> splitChunk( const Shard::CommandResponse& cmdResponse = cmdResponseStatus.getValue(); - boost::optional<ShardVersion> shardVersionReceived = [&]() -> boost::optional<ShardVersion> { + boost::optional<ChunkVersion> chunkVersionReceived = [&]() -> boost::optional<ChunkVersion> { // old versions might not have the shardVersion field if (cmdResponse.response[ChunkVersion::kChunkVersionField]) { - ChunkVersion placementVersion = - ChunkVersion::parse(cmdResponse.response[ChunkVersion::kChunkVersionField]); - return ShardVersion( - placementVersion, - CollectionIndexes{ - CollectionGeneration{placementVersion.epoch(), placementVersion.getTimestamp()}, - boost::none}); + return ChunkVersion::parse(cmdResponse.response[ChunkVersion::kChunkVersionField]); } return boost::none; }(); - onShardVersionMismatch(opCtx, nss, shardVersionReceived); + onCollectionPlacementVersionMismatch(opCtx, nss, chunkVersionReceived); // Check commandStatus and writeConcernStatus auto commandStatus = cmdResponse.commandStatus; diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp index 631637a50c1..e8ac671c52a 100644 --- a/src/mongo/db/service_entry_point_mongod.cpp +++ b/src/mongo/db/service_entry_point_mongod.cpp @@ -225,7 +225,9 @@ public: bool refreshCollection(OperationContext* opCtx, const StaleConfigInfo& se) const noexcept override { - return onShardVersionMismatchNoExcept(opCtx, se.getNss(), se.getVersionReceived()).isOK(); + return onCollectionPlacementVersionMismatchNoExcept( + opCtx, se.getNss(), ChunkVersion(se.getVersionReceived())) + .isOK(); } bool refreshCatalogCache(OperationContext* opCtx, diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp index 551554322a1..eb78bb6f0b6 100644 --- a/src/mongo/db/ttl.cpp +++ b/src/mongo/db/ttl.cpp @@ -483,7 +483,12 @@ bool TTLMonitor::_doTTLIndexDelete(OperationContext* opCtx, auto uniqueOpCtx = tc->makeOperationContext(); auto opCtx = uniqueOpCtx.get(); - onShardVersionMismatchNoExcept(opCtx, *nss, staleInfo->getVersionWanted()) + onCollectionPlacementVersionMismatchNoExcept( + opCtx, + *nss, + staleInfo->getVersionWanted() + ? boost::make_optional(ChunkVersion(*staleInfo->getVersionWanted())) + : boost::none) .ignore(); }) .getAsync([](auto) {}); |