Chapter 12 — Digest-Based Difference Detection and Replica Repair
Chapter objective: After this chapter, a developer can detect differences with a digest, explain replay/snapshot selection, and reject a repair that would move the requester backward.
Learning objectives
- Connect digest, anti-entropy, and repair.
- Select replay or snapshot from retention and estimated cost.
- Detect regression when the requester is newer or more complete at the same sequence.
- Separate current-state repair from business-event replay.
Prerequisites
- The delta path from Chapter 11 is understood.
- Online messages can be lost while collections still need eventual convergence.
- Repair is a background process outside the local write transaction.
Case progress
node-b misses ten route-hint updates while offline. On
return it reports its collection digest. The source decides whether
retained deltas can close the gap or a current-state snapshot is more
appropriate; B does not request every business event.
From difference to repair plan
A digest summarizes state so peers can compare observed sequence, entry count, or bucket hash. It carries no complete values and is not automatically authoritative; it supplies input to negotiation.
AdaptiveRepairPlanner follows four boundaries:
- No difference produces
NONE. - A requester that is ahead, or more complete at the same sequence, does not receive an older snapshot.
- When the requester remains inside the source's replay window, estimated replay and snapshot costs are compared.
- When replay is unavailable, snapshot restores current state.
Replay and snapshot differ in more than size
| Dimension | Replay | Snapshot |
|---|---|---|
| Content | retained deltas after a sequence | chunked current collection state |
| Fit | continuous gap inside retention | gap too old/large or snapshot cheaper |
| Benefit | incremental and ordered evolution | independent of complete delta history |
| Risk | retention exhausted; many small messages | large transfer; safe assembly and switch needed |
| It is not | business audit replay | database backup or cross-resource recovery |
Adaptive choice uses latency, throughput, and history in a peer profile. Without a profile, the planner falls back to a fixed strategy, which is more predictable than reacting to one slow request.
Repair cannot move state backward
If requester sequence is 101 while the source has 100, a hash
difference does not authorize the source to overwrite the requester. At
an equal sequence, a requester with more entries also rejects a smaller
source snapshot. AdaptiveRepairPlannerTest fixes both cases
at RepairMode.NONE.
Anti-entropy is a continuing control loop
exchange digest → detect difference → plan repair → transfer → apply → compare again
Control messages can also be lost. ChaosIntegrationTest
injects 50% control-plane loss and shows that later sweeps can still
detect and repair the difference. Completion of one request only proves
one operation; equal final digests establish the repair outcome.
Counterexample and fault injection
- Put requester sequence ahead of the source and observe regression rejection.
- Move the requester outside replay retention and observe snapshot selection.
- Supply a profile that estimates snapshot as faster and observe snapshot even while replay is possible.
- Drop the first control round and observe compensation by a later sweep.
Experiment
cd submodule/dsm
mvn -q -pl dsm-sync,dsm-integration-test -am \
-Dtest=AdaptiveRepairPlannerTest,ChaosIntegrationTest \
-Dsurefire.failIfNoSpecifiedTests=false testFor each requester/source pair in repair-scenarios.json,
select NONE, REPLAY, or SNAPSHOT
and state the reason for avoiding regression.
Experiment acceptance card
| Field | Content |
|---|---|
| Command | The focused Maven tests above;
node --test tests/chapter-assets.test.mjs |
| Input or fault | inside/outside replay retention, cost samples, requester ahead, and control loss |
| Observable result | explainable planner choice; requester never regresses; a later sweep repairs the gap |
| Evidence level | E2 planner behavior plus E3 chaos repair |
| This experiment does not prove | Optimal thresholds at production scale, cross-region bandwidth cost, or complete business history |
Review
- Digest detects a difference; a repair plan decides how to close it.
- Available replay is not always cheaper, and a snapshot is not automatically authoritative.
- An ahead or more complete requester is protected from regression.
- Anti-entropy repeats; current-state convergence does not replay business history.
Next
Chapter 13 turns to observers: a slow subscriber can overflow the local change buffer even when collection replicas converge.