From db2e46857ce1c2bf90fda9842287cc5940fce81c Mon Sep 17 00:00:00 2001 From: Max Hirschhorn Date: Mon, 8 Mar 2021 22:37:40 +0000 Subject: SERVER-54980 Split donor and recipent documents into im/mutable state. Removes the unused strictConsistencyTimestamp field from the recipient document. Also explicitly sets strict:true and strict:false for all of resharding's IDL types. --- .../db/s/resharding/resharding_recipient_service.h | 38 +++++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'src/mongo/db/s/resharding/resharding_recipient_service.h') diff --git a/src/mongo/db/s/resharding/resharding_recipient_service.h b/src/mongo/db/s/resharding/resharding_recipient_service.h index 59e41df7b63..a5fab606b8b 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service.h +++ b/src/mongo/db/s/resharding/resharding_recipient_service.h @@ -133,6 +133,8 @@ public: const ReshardingRecipientDocument& recipientDoc); private: + RecipientStateMachine(const ReshardingRecipientDocument& recipientDoc); + // The following functions correspond to the actions to take at a particular recipient state. ExecutorFuture _awaitAllDonorsPreparedToDonateThenTransitionToCreatingCollection( const std::shared_ptr& executor); @@ -153,17 +155,26 @@ private: void _renameTemporaryReshardingCollection(); - // Transitions the state on-disk and in-memory to 'endState'. - void _transitionState(RecipientStateEnum endState, - boost::optional fetchTimestamp = boost::none, - boost::optional abortReason = boost::none); + // Transitions the on-disk and in-memory state to 'newState'. + void _transitionState(RecipientStateEnum newState); + + void _transitionState(RecipientShardContext&& newRecipientCtx, + boost::optional&& fetchTimestamp); + + // Transitions the on-disk and in-memory state to RecipientStateEnum::kCreatingCollection. + void _transitionToCreatingCollection(Timestamp fetchTimestamp); + + // Transitions the on-disk and in-memory state to RecipientStateEnum::kError. + void _transitionToError(Status abortReason); void _updateCoordinator(); - // Updates the recipient document on-disk and in-memory with the 'replacementDoc.' - void _updateRecipientDocument(ReshardingRecipientDocument&& replacementDoc); + // Updates the mutable portion of the on-disk and in-memory recipient document with + // 'newRecipientCtx' and 'fetchTimestamp'. + void _updateRecipientDocument(RecipientShardContext&& newRecipientCtx, + boost::optional&& fetchTimestamp); - // Removes the local recipient document from disk and clears the in-memory state. + // Removes the local recipient document from disk. void _removeRecipientDocument(); // Removes any docs from the oplog applier progress and txn applier progress collections that @@ -180,12 +191,15 @@ private: // (abort resharding). void _onAbortOrStepdown(WithLock, Status status); - // The in-memory representation of the underlying document in + // The in-memory representation of the immutable portion of the document in // config.localReshardingOperations.recipient. - ReshardingRecipientDocument _recipientDoc; + const CommonReshardingMetadata _metadata; + const std::vector _donorShardIds; - // The id both for the resharding operation and for the primary-only-service instance. - const UUID _id; + // The in-memory representation of the mutable portion of the document in + // config.localReshardingOperations.recipient. + RecipientShardContext _recipientCtx; + boost::optional _fetchTimestamp; std::unique_ptr _collectionCloner; std::vector> _txnCloners; @@ -200,7 +214,7 @@ private: std::vector> _oplogFetcherFutures; // Protects the promises below - Mutex _mutex = MONGO_MAKE_LATCH("ReshardingRecipient::_mutex"); + Mutex _mutex = MONGO_MAKE_LATCH("RecipientStateMachine::_mutex"); boost::optional _critSec; -- cgit v1.2.1