ExportXMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Cluster Scalability
    • ClusterScalability 9Nov-23Nov, ClusterScalability 23Nov-7Dec
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Motivation
      Resharding changes a collection’s shard key. Each shard takes part as a donor (it sends data), a recipient (it receives data) or both, under a coordinator on the config server. Project SPM-4936 states the conditions that must hold at every state transition of these participants and checks them behind featureFlagReshardingPrePostConditionsValidations, so that a broken assumption fails the operation at the transition where it happens instead of surfacing later as a hang, a crash or a wrong result.

      The recipient’s contract (a table of legal transitions with a validator each) exists but nothing calls it. The donor and the coordinator already run their pre-checks (resharding_donor_service.cpp:1424, resharding_coordinator.inl:2255). Until the recipient does too, recipient bugs of the kinds the project targets keep surfacing late: the recipient’s in-memory state disagreeing with its document, an unintended transition, a changed immutable field, dropped clone details, a wrong abort reason, or a bad change-streams-monitor start that later stalls or silently skips verification.

      Context

      A pre-check validates a proposed transition before the new state is persisted or reported to the coordinator.
      The recipient persists every transition through one write, resharding_recipient_service.cpp:1945, called by resharding_recipient_service.cpp:1727. The change-streams monitor’s starting point (the last operation time plus one, read from ReplClientInfo) is created only inside it, and only when verification is on, cloning and applying are not skipped, and the new state is kApplying.
      If a step of the recipient’s run chain throws, its error handler moves the recipient to kError and records the exception as the abort reason (resharding_recipient_service.cpp:459 shows the handler’s precondition that the state is before kStrictConsistency).
      tassert throws; tassertNoThrow logs and records a tripwire (which fails a test at shutdown) without throwing.
      Not part of this ticket: the post-check (SERVER-139808).

      Proposed approach

      • Gate on resharding::isTransitionValidationEnabled(_forwardableOpMetadata) (resharding_util.cpp:1143; it guards on a VersionContext). Evaluate it once at the top of _transitionState so the post-check (SERVER-139808) reuses the same answer. Flag off: no behavior change and no extra read.
      • Run the check inside _updateRecipientDocument, after the $set is built and before the write. Build the monitor context before the check, use the same value in the snapshot and in the $set, and do not compute it twice (the post-check compares the durable start with it). Keep the computation inside _updateRecipientDocument so the last-operation read stays right before the write.
      • Inputs: before from _readDurableSnapshot (SERVER-139803, local read) and proposed from makeProposedSnapshot(before, changes) built from the same values as the $set. Hand proposed back to _transitionState for the post-check. outgoingPhase is the state held in _recipientCtx, read directly on the state machine’s chain (see the SERVER-139803 audit); because before is persisted, a mismatch means memory and disk diverged.
      • Failure policy, as on the donor: for destination kError or kDone use tassertNoThrow, so the recipient can still record its failure or finish; for any other destination use tassert. It throws before the write, and the run chain’s error handler moves the recipient to kError with the violation as the abort reason.
      • No special skip for stepdown, as on the donor. Add one only if the flag-on service tests (SERVER-139810) show false positives, and record why.

      Notes and constraints

      Why a pre-check for the monitor and not a post-check: a bad monitor start (for example null, which would read the oplog from its beginning) is better refused before it is durable; afterwards it would need a manual abort, and a recipient that fails over appears to reload the monitor context from the document. This came up in review of SERVER-139682 and was settled this way.
      The pre-check reads the persisted document, one local read per transition. The technical design (WRITING-40550) says pre-checks are in-memory. The reason for the difference: _recipientCtx is not a faithful copy of the document (_updateContextMetrics, resharding_recipient_service.cpp:2266, changes totals, index count and metrics in memory without writing them). Record this in the recipient section of the design.
      For transitions after kApplying, take the monitor from before (the durable document), not from _changeStreamsMonitorCtx: the monitor’s batch callback (resharding_recipient_service.cpp:1046) replaces that member from its own thread.
      The kStrictConsistency pre-check may throw, because it runs before the write: the in-memory state is still kApplying, so the error handler’s precondition holds. The critical section the recipient acquires just before that transition (resharding_recipient_service.cpp:1462) must still be released on that path; cover it with a test.

      Acceptance criteria

      • Flag off: no behavior change and no extra read.
      • Flag on: every legal transition in the existing recipient service tests passes the pre-check.
      • A violating proposal on a destination other than kError or kDone aborts the recipient through kError with ReshardingPreconditionFailure. A violation on kError or kDone only fires the tripwire.
      • The monitor start for the kApplying transition is computed once and is the same value in the $set and the snapshot.
      • The resharding service unit test targets (parts 1, 2 and 3) pass. Run part 1: parts 2 and 3 set a VersionContext in their fixtures and missed an earlier defect.

            Assignee:
            Kruti Shah
            Reporter:
            Nandini Bhartiya
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: