diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp')
| -rw-r--r-- | src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp | 57 |
1 files changed, 12 insertions, 45 deletions
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 99ab47fc11a..e9a466a1cb6 100644 --- a/src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp +++ b/src/mongo/db/s/resharding/resharding_donor_recipient_common.cpp @@ -51,35 +51,10 @@ using DonorStateMachine = ReshardingDonorService::DonorStateMachine; using RecipientStateMachine = ReshardingRecipientService::RecipientStateMachine; namespace { -MONGO_FAIL_POINT_DEFINE(reshardingInterruptAfterInsertStateMachineDocument); - using namespace fmt::literals; const Backoff kExponentialBackoff(Seconds(1), Milliseconds::max()); -template <class StateMachine, class ReshardingDocument> -void ensureStateDocumentInserted(OperationContext* opCtx, const ReshardingDocument& doc) { - try { - StateMachine::insertStateDocument(opCtx, doc); - } catch (const ExceptionFor<ErrorCodes::DuplicateKey>& ex) { - // It's possible that the state document was already previously inserted in the following - // cases: - // 1. The document was inserted previously, but the opCtx was interrupted before the - // state machine was started in-memory with getOrCreate(), e.g. due to a chunk migration - // (see SERVER-74647) - // 2. Similar to the ErrorCategory::NotPrimaryError clause below, it is - // theoretically possible for a series of stepdowns and step-ups to lead a scenario where a - // stale but now re-elected primary attempts to insert the state document when another node - // which was primary had already done so. Again, rather than attempt to prevent replica set - // member state transitions during the shard version refresh, we instead swallow the - // DuplicateKey exception. This is safe because PrimaryOnlyService::onStepUp() will have - // constructed a new instance of the resharding state machine. - auto dupeKeyInfo = ex.extraInfo<DuplicateKeyErrorInfo>(); - invariant(dupeKeyInfo->getDuplicatedKeyValue().binaryEqual( - BSON("_id" << doc.getReshardingUUID()))); - } -} - /* * Creates a ReshardingStateMachine if this node is primary and the ReshardingStateMachine doesn't * already exist. @@ -92,10 +67,7 @@ void createReshardingStateMachine(OperationContext* opCtx, const ReshardingDocum // Inserting the resharding state document must happen synchronously with the shard version // refresh for the w:majority wait from the resharding coordinator to mean that this replica // set shard cannot forget about being a participant. - ensureStateDocumentInserted<StateMachine>(opCtx, doc); - - reshardingInterruptAfterInsertStateMachineDocument.execute( - [&opCtx](const BSONObj& data) { opCtx->markKilled(); }); + StateMachine::insertStateDocument(opCtx, doc); auto registry = repl::PrimaryOnlyServiceRegistry::get(opCtx->getServiceContext()); auto service = registry->lookupServiceByName(Service::kServiceName); @@ -110,6 +82,17 @@ void createReshardingStateMachine(OperationContext* opCtx, const ReshardingDocum // secondary (or primary which stepped down) must do for an active resharding operation upon // refreshing its shard version. The primary is solely responsible for advancing the // participant state as a result of the shard version refresh. + } catch (const ExceptionFor<ErrorCodes::DuplicateKey>& ex) { + // Similar to the ErrorCategory::NotPrimaryError clause above, it is theoretically possible + // for a series of stepdowns and step-ups to lead a scenario where a stale but now + // re-elected primary attempts to insert the state document when another node which was + // primary had already done so. Again, rather than attempt to prevent replica set member + // state transitions during the shard version refresh, we instead swallow the DuplicateKey + // exception. This is safe because PrimaryOnlyService::onStepUp() will have constructed a + // new instance of the resharding state machine. + auto dupeKeyInfo = ex.extraInfo<DuplicateKeyErrorInfo>(); + invariant(dupeKeyInfo->getDuplicatedKeyValue().binaryEqual( + BSON("_id" << doc.getReshardingUUID()))); } } @@ -155,13 +138,6 @@ void processReshardingFieldsForDonorCollection(OperationContext* opCtx, return; } - // We clear the routing information for the temporary resharding namespace to ensure this donor - // shard primary will refresh from the config server and see the chunk distribution for the new - // resharding operation. - auto* catalogCache = Grid::get(opCtx)->catalogCache(); - catalogCache->invalidateCollectionEntry_LINEARIZABLE( - reshardingFields.getDonorFields()->getTempReshardingNss()); - auto donorDoc = constructDonorDocumentFromReshardingFields(nss, metadata, reshardingFields); createReshardingStateMachine<ReshardingDonorService, DonorStateMachine, @@ -352,16 +328,7 @@ void clearFilteringMetadata(OperationContext* opCtx, bool scheduleAsyncRefresh) }); } - auto* catalogCache = Grid::get(opCtx)->catalogCache(); - for (const auto& nss : namespacesToRefresh) { - if (nss.isTemporaryReshardingCollection()) { - // We clear the routing information for the temporary resharding namespace to ensure all - // new donor shard primaries will refresh from the config server and see the chunk - // distribution for the ongoing resharding operation. - catalogCache->invalidateCollectionEntry_LINEARIZABLE(nss); - } - AutoGetCollection autoColl(opCtx, nss, MODE_IX); CollectionShardingRuntime::get(opCtx, nss)->clearFilteringMetadata(opCtx); |
