ExportXMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Cluster Scalability
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Motivation
      A pre-check validates a transition before it is persisted. It cannot tell whether the write that followed is what a new primary would see once the write is majority-committed. That is a separate class of bug: SERVER-129060 (a donor acknowledged a coordinator command before its document was majority-committed), SERVER-124162 and SERVER-124931 (the coordinator’s in-memory state disagreeing with its document). The post-check exists to catch it, so that a recipient that believes it moved to a state which a new primary would not find fails at that transition.

      Today the recipient has one post-validator for every transition, and nothing calls it. Its input has no source state, so a post constraint cannot depend on the transition, and its failure message cannot name it. The donor dispatches per transition and calls its post-check from _transitionState (resharding_donor_service.cpp:1367). Without the same here, per-transition post constraints (for example “the promise this state fulfils is settled”) cannot be added.

      Context

      Proposed approach
      Validator:

      • Add the pre-write snapshot (before) to the post-check’s input, as the donor does; the source state comes from before.ctx.getState().
      • Change the table’s value from a bare pre-validator to a struct holding a pre-validator and a post-validator whose default requires durableMatchesProposed and inMemoryMatchesProposed, so every transition keeps today’s behavior. This ticket adds the mechanism, not new constraints.
      • The post-check looks the transition up. One that is not in the table is reported as not allowed, with ReshardingPostconditionFailure.

      Service (_transitionState):

      • Reuse the flag evaluation from the top of _transitionState (SERVER-139806), so a flag change mid-transition cannot run a post-check without a pre-check.
      • After the wait for majority, and outside the _mutex scope that fulfils the promises (_mutex is non-recursive and _makeOperationContext takes it), read the durable snapshot and call the post-validator.
        before and proposed are the snapshots SERVER-139806 builds. proposed is handed back from _updateRecipientDocument, not rebuilt, because the monitor start is computed there and must not be computed twice. In-memory input: a copy of _recipientCtx taken on the state machine’s own chain (no lock needed; see SERVER-139803).
      • Durable input: _readDurableSnapshot (SERVER-139803) under ScopedReadConcern majority, as the donor does (resharding_donor_service.cpp:1317; the DBDirectClient rejects a read concern on the find itself). The post-check exists to see what a new primary would see, so a local read is not enough. SERVER-139806's pre-check read can stay local.
      • Leave a seam between the read and the validation for the corruption failpoint (SERVER-139809).

      Failure policy

      • Every post failure is (for this ticket) reported with tassertNoThrow: it logs the failure and records a tripwire (which fails a test at shutdown) but does not throw, so the transition and the operation carry on. A post-check runs after the new state is already persisted and held in memory, so it can report a bad transition but cannot prevent it.
      • A read-back that throws a DBException logs a warning with a new log id and skips the check; it is not evidence of a bad transition. A missing document is tassertedNoThrow (new error code). Use the caller’s opCtx so a stepdown or abort interrupts the read. No special skip for stepdown, as on the donor.
      • Keep the reaction to a failed post-check in one function, so that deciding to throw later is a small change (a switch on the destination state, as the donor has).
      • Making a post-check throw is deliberately not part of this ticket; it will be a follow-up ticket(https://jira.mongodb.org/browse/SERVER-139810 ). Background for that ticket:
        • The sources disagree. The donor throws (tassert) for post failures on transitions before its point of no return and uses tassertNoThrow after it; the technical design says tassertNoThrow throughout; the project’s scope says a postcondition failure should abort the operation.
        • For the recipient the only safe place to throw is a transition before kStrictConsistency (kCreatingCollection, kCloning, kBuildingIndex, kApplying): the run chain’s error handler then moves the recipient to kError (resharding_recipient_service.cpp:459).]
        • The post-checks for kStrictConsistency, kError and kDone cannot throw. For kStrictConsistency, the transition runs in a continuation that writes the strict-consistency oplog entry right after _transitionState returns (resharding_recipient_service.cpp:1470, then resharding_recipient_service.cpp:1476), and the error handler asserts the state is still before kStrictConsistency (resharding_recipient_service.cpp:459), so a throw would skip the oplog entry and then hit the assertion. For kError and kDone no handler is left: by reading the run chain, the error reaches the final error handler of run(), which is fatal unless the node is stepping down (resharding_recipient_service.cpp:739; kDone is written in resharding_recipient_service.cpp:525). This was read from the code and not exercised.
        • ReshardingPostconditionFailure has only the InternalOnly error category and the recipient’s retry predicate adds only WriteConcernTimeout and LockTimeout, so a throw would not be retried (read from the code; the default predicate was not read).
        • The follow-up should use the flag-on service tests (SERVER-139810) to see how often post-checks fire on legal paths before deciding, because a false positive that throws aborts a real resharding operation, and should record the decision in the recipient section of the design.

      Notes and constraints

      • Do not read _changeStreamsMonitorCtx for the post-check. The monitor’s batch callback (resharding_recipient_service.cpp:1046) replaces it from its own thread. The comparison needs only the monitor start, which the callback preserves (it copies the context and changes only the resume token, document delta and completed flag), so comparing the durable start with the proposed start is unaffected by progress writes.
      • Out of scope: new post constraints and runtime facts; comparing the in-memory donor list; the corruption failpoint and negative service tests (SERVER-139809); enabling the flag in the service-test fixture (SERVER-139810); the pre-check (SERVER-139806); validating state recovered from disk after a step-up.

      Acceptance criteria

      • Flag off: no durable read is issued and behavior is unchanged.
      • Unit test, exhaustive over the table: each of the 17 transitions has a post-validator that requires durableMatchesProposed and inMemoryMatchesProposed. A transition outside the table fails the post-check with ReshardingPostconditionFailure and the message names it.
      • Unit test: a post constraint registered for one transition runs only on that transition. Removing a default constraint fails a test.
      • Flag on: the existing recipient service tests pass, and the post-check read uses majority read concern.
      • A read-back error logs a warning and produces no violation. Add a service test if the fixture can inject the failure; otherwise record the gap on SERVER-139809.
      • The resharding service unit test targets (parts 1, 2 and 3) and the recipient, donor and coordinator validation unit tests pass.

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

              Created:
              Updated: