advanced26 min studyLesson 270 in Engineering

Test cross-shard invariants and recovery histories

Construct fault schedules and history oracles that distinguish atomicity, isolation, durability, and conditional progress.

On this page

What you’ll understand

  • Translate a business invariant into an observable test oracle.
  • Inject faults around durable transaction boundaries and preserve ambiguous operations.
  • Distinguish invariant checks, serializability checks, and bounded liveness observations.

A test suite that counts successful responses can pass while quota disappears after a recovery. Another suite can preserve a final total while allowing clients to observe impossible intermediate states. Cross-shard testing needs explicit claims, a declared failure model, and evidence at the same scope as those claims. The goal is to explain a failing history, not merely accumulate a large number of requests that happened to return success.

Start with a model and observable claims

For an internal transfer system, a conserved total and nonnegative per-account balances are useful invariants, provided fees, deposits, withdrawals, and in-flight representations are specified. Conservation alone is weak: a broken transfer that does nothing preserves the total. Record operation identity, input amounts, observed reads, invocation and response boundaries, and terminal evidence. A reference model should describe allowed operations independently of the storage implementation, so the checker is not simply repeating the same arithmetic and bugs through another code path.

Atomicity, isolation, and durability require different observations. All required participant outcomes should agree; read histories should satisfy the promised isolation model; acknowledged durable effects should survive failures within the declared storage model. A final-state scan cannot by itself establish serializability of every earlier read. Conversely, a serialization checker may accept an incomplete history only after considering possible outcomes of operations whose replies were lost. Do not remove ambiguous commits from the record merely because they make the oracle harder to write.

∑i=1nbi(t)=B0\sum_{i=1}^{n}b_i(t)=B_0
For an isolated internal-transfer test with no fees, creation, destruction, or external flows, account balances b_i in quota units conserve initial total B_0. The checker must use a consistent observation or explicit in-flight model; a mixed-time scan can appear to violate conservation spuriously.↔ Scroll wide equations horizontally.

Fault placement is part of the experiment

Choose crashes immediately before and after prepare persistence, decision persistence, participant application, and response delivery. Partition the coordinator from one participant while leaving other links available. Delay or duplicate messages where the transport model permits it, then restart processes with their intended durable state. Separately test storage-loss or Byzantine behavior only if the promised fault model includes it. Calling every fault a network outage hides which assumptions the protocol relies on and can lead to either false failures or unjustified confidence.

Use deterministic seeds or controlled scheduling barriers to reproduce critical interleavings. Preserve the seed, configuration, binary version, and event trace for a failing run. Reduce a long failing schedule while keeping the violation, so a reviewer can see which dependency or durability edge was missing. FoundationDB’s simulation work demonstrates the value of integrating fault exploration with system execution, but simulation remains bounded by the modeled environment. Passing simulated tests does not prove correctness for unmodeled device behavior, clock assumptions, or application misuse.

ackCommit⁡(T)⟹effectAfterRecovery⁡(T)\operatorname{ackCommit}(T)\Longrightarrow\operatorname{effectAfterRecovery}(T)
Within the declared durability and recovery fault model, an acknowledged committed transaction must retain its logical effect. This test obligation requires defining acknowledgment, successful recovery, and permitted storage failures; it is not a guarantee after arbitrary loss of all durable copies.↔ Scroll wide equations horizontally.

Check progress without weakening safety

After healing faults, check that unresolved work reaches a valid outcome when the protocol’s liveness assumptions hold. An ordinary two-phase-commit participant may legitimately remain blocked while its decision authority is unavailable. A bounded test timeout detects failure to finish within that experiment; it does not automatically distinguish a liveness defect from violated recovery assumptions. Report safety violations separately from unresolved outcomes and slow progress. Keep sufficient evidence to explain whether locks, decision records, or compensation obligations prevent quiescence.

The sampling lab illustrates uncertainty in a deliberately artificial test process. Reset, set success probability to 0.1 and independent samples to 20, predict the sample-mean variance, then Step. For a separate comparison, Reset and explicitly set probability to 0.1 and samples to 100, predict, then Step. The exact binomial masses describe independent marked outcomes; playback highlights possibilities rather than running tests. A smaller variance in this model cannot prove a transaction invariant or establish that fault schedules in a real campaign are independent or representative.

A final total can hide a missing effect

Accounts A and B begin with 80 and 20 quota units. A client requests a 15-unit transfer from A to B and receives a committed acknowledgment. After a permitted crash and recovery, a consistent scan reports 80 and 20 again. No other operations occurred.

  1. Initial total is 80 + 20 = 100. The recovered total is also 100, so a conservation-only checker passes.

  2. The acknowledged transfer’s expected state is A = 80 − 15 = 65 and B = 20 + 15 = 35. With no other operations, the observed recovered state lacks its required effect.

  3. The durability and operation-semantics oracle therefore rejects the history even though the aggregate sum is correct. Preserve the acknowledgment and recovery trace to locate the lost durable boundary.

The result

Different properties need different evidence. Conserving a total does not establish that an acknowledged transaction happened.

Explore the model

Interactive lab

Interactive lab · sampling

More modeled samples are not a correctness proof

Reset, set success probability p = 0.1 and independent samples n = 20, predict sample-mean variance, then Step. Compare a new Reset with both p = 0.1 and n = 100, predicting before Step. Exact binomial masses and highlighted outcomes are not executed fault tests.

More modeled samples are not a correctness proofExact binomial masses for the mean of n independent Bernoulli trials, compared with normal mass between adjacent half-count boundaries; normal tails outside the finite support remain outside the bars. Playback highlights outcomes, not random samples. The Berry–Esseen bound applies to standardized CDFs, not individual bars or continuity-corrected errors. At p = 0 or 1, normal comparison and that bound are disabled. Normal-CDF evaluation uses a numerical approximation with absolute error below 7.5×10⁻⁸ (at most 1.5×10⁻⁷ per interval, before rounding). Current readings: Mean sample proportion: 0.5; Sample-mean variance: 0.0125; Uniform CDF error bound: ≤ 0.1062. All parameters are adjustable with the labeled controls below.Exact distribution of the mean of 20 independent Bernoulli variables with success probability 0.5; playback highlights outcome 0.00.250.50.75100.0580.1150.1730.23Sample mean · k / nProbability massNormal bin masses are an approximationk = 0 · exact probability = 9.54e-7
Exact binomial massNormal interval massHighlighted outcome / mean
Mean sample proportion
0.5
Sample-mean variance
0.0125
Uniform CDF error bound
≤ 0.1062
t = 0 s

Exact binomial masses for the mean of n independent Bernoulli trials, compared with normal mass between adjacent half-count boundaries; normal tails outside the finite support remain outside the bars. Playback highlights outcomes, not random samples. The Berry–Esseen bound applies to standardized CDFs, not individual bars or continuity-corrected errors. At p = 0 or 1, normal comparison and that bound are disabled. Normal-CDF evaluation uses a numerical approximation with absolute error below 7.5×10⁻⁸ (at most 1.5×10⁻⁷ per interval, before rounding). Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forSampling precision under independence cannot substitute for a history oracle, fault-model coverage, or a proof of transaction correctness.

Check your understanding

A recovered database preserves its original total balance, but one acknowledged transfer is absent and no other operations explain it. Which conclusion follows?

Try it yourself

For the sampling model with p = 0.1, compute the sample-mean variance at n = 20 and n = 100. Then describe why 1,000 passing randomly generated transfer histories cannot prove strict serializability under every possible fault schedule.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

The Bernoulli sample-mean variance is p(1 − p)/n. Separate numerical precision from coverage of possible histories.

Compare with the solution

The variances are 0.1 × 0.9 / 20 = 0.0045 and 0.1 × 0.9 / 100 = 0.0009. The second is five times smaller under the specified independence model. Passing 1,000 histories covers only those generated executions and the oracle’s observed information. Rare interleavings, unmodeled failures, missing real-time constraints, or an incomplete checker can remain, so retain bounded test evidence without elevating it to an exhaustive proof.

Take it with you

  • State invariants, operation semantics, and history properties need separate oracles.
  • Faults must target durable and communication boundaries within a declared model.
  • Reproducible passing campaigns provide bounded evidence rather than universal correctness.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.