Wiki Cluster
Reconciliation, scrubbing and repair
How Mirexa keeps a partition's copies identical to its primary — verifying chunks at both ends of a transfer, refusing a copy that holds another history, mirroring retention, scrubbing for rot, and repairing it from the other side.
A Mirexa copy is byte-identical to its primary by construction: it installs the primary's own chunk files and index entries. So the primary is the reference, there is no majority vote, and reconciliation asks a narrower question — what could make a copy hold something other than its primary's flushed state, and how would anyone know? This page lists those causes and the mechanism that answers each one. All of it runs on its own; an operator watches one gauge.
What can make a copy differ
| Cause | Answer |
|---|---|
| A chunk rots on the primary's disk | Verified before it is sent; the seed stops; the primary repairs it from a copy |
| A chunk rots on a copy's disk | Found by the copy's scrub; repaired from its primary |
| Rot in chunks nobody reads | The scrub re-reads every held chunk at a bounded rate |
| A copy holds another history below its floor (data kept from an earlier role, or pulled from a primary a failover abandoned) | The seed's reference check refuses it; the copy is moved aside and re-seeded from nothing |
| The primary's retention dropped data the copy still holds | The copy mirrors the retention |
| A gap the primary closed by a fill is still open on the copy | The copy's gap list is replaced by the primary's on every seed round |
| A copy that was outside a failover's chosen line | Recorded as divergent; quarantined and re-seeded (see Failover) |
Verification at both ends of the seed
storage.VerifyChunk checks that a chunk's bytes are the chunk its index entry names: the byte
size the entry recorded, the chunk's own CRC-32C over its data and its footer, its header, the
record count the entry recorded, and its time range (exactly for a base chunk, within it for a
patch).[1]
- The primary runs it before sending a chunk. A chunk that fails ends the seed with gRPC
DataLoss, is logged at ERROR once, and is recorded for repair — shipping it would put the rot on every copy and destroy the last good version anyone held. - The copy runs it again before writing, so even a primary that sent bad bytes cannot plant them.
Every single-bit flip in a chunk is caught: CRC-32C detects all single-bit errors, and a test flips each bit of a chunk in turn.
Divergence below the floor
A seed round sends only artifacts above the copy's reported floor, so on its own it would trust whatever the copy says it holds. Each stream's seed therefore starts with a reference: the highest chunk sequence number the primary has ever issued, and, for every artifact at or below the copy's floor, its index entry and its chunk footer's data checksum. Before installing anything, the copy refuses the round if:[2]
- it holds a sequence number above what the primary has ever issued;
- an index entry or a footer checksum differs under a sequence number both hold;
- one of its own chunks at or below the floor is missing or rotten at the footer.
An entry the copy lacks is not divergence — the primary's retention may have dropped it.
A copy that refuses leaves the in-sync set (and its catch-up ends only once that has landed), then
its replica supervisor moves the partition aside as quarantine/partition_<id>-epoch_<e>-diverged
and seeds it again from nothing.
A rot under an intact footer on a copy is not visible to this check — the footer is the chunk's own claim about itself — until the copy's scrub reads the chunk.
Mirroring retention
Retention runs inside a primary's live writer; a copy has none. Without help a copy would keep everything its primary retired and serve it once promoted. The reference carries where the primary's oldest base chunk begins, and the copy retires each entry the primary no longer holds that ends before that point, with its patches and files.[3] Two guards, because a copy deleting on a primary's say-so is how one node's loss becomes everyone's:
- Only retention's shape is mirrored. An absent entry that is not older than what the primary keeps stays where it is.
- Retirement happens only after the divergence check has accepted the reference. A primary that lost its index starts its sequence numbers again, reads as another history, and the copy's data goes to quarantine intact rather than being trimmed to match.
Scrubbing
Rot is otherwise found only when something reads it, and a seed re-reads nothing below a copy's
floor. Every node therefore scrubs: it re-reads the chunks of every partition it holds — as
primary or as copy — and verifies each with VerifyChunk. A chunk that fails, or whose file is
gone while its entry still names it, is recorded for repair.[4]
- Rate, not schedule.
cluster.scrub_bytes_per_second(default 8 MiB/s; 0 disables). The budget accrues between supervisor passes (every 2 s) and is capped at ten seconds' worth, so a node that was busy does not then read a burst. - Cycles. A cycle lists every held chunk when the previous one ends and reads them in turn as the budget allows; a pass never starts a second cycle, so no chunk is read twice in one pass.
- At the default rate, scrubbing 100 GB takes about 3.3 hours (arithmetic, not measured).
- Tick chunks are not scrubbed.
Measured 2026-10-16 (BenchmarkQuery_WhileTheScrubRuns, one reader, page-cached, one development
laptop): query latency with the scrub off, at the default rate and saturating at ~3× the default
fell in the same 120–153 µs band. Because the data was cached, this measures CPU contention, not
disk contention.
Repair
Each node keeps one record of its rotten chunks — filled by the seed source and the scrub,
cleared by the repairer on every supervisor pass. Repair fetches a good copy of the chunk over the
replication plane's FetchArtifact RPC:[5]
| This node is | It fetches from | Why |
|---|---|---|
| The partition's primary | Its copies, in-sync ones first | A copy that took the chunk before it rotted holds the last good version |
| A copy | Its primary, and nobody else | Its history is its primary's; another copy's version is one this copy was never sent |
FetchArtifact is answered only for those two pairings, only at the partition's current epoch,
and only with bytes the answering side has itself verified. The fetched entry must be this node's
own entry for that sequence number, and the bytes must verify against it, before the chunk file
is rewritten under the install guard. A chunk no peer holds whole stays recorded, is reported once,
and keeps mirexa_reconcile_rotten_chunks above zero.
Quarantine
Mirexa never deletes a partition's data because of a reconciliation decision. Whatever is set aside
is moved, with one durable rename of the whole partition directory, under <data_dir>/quarantine/,
after its streams are stopped and a WAL floor is recorded so recovery never replays the abandoned
records:[6]
| Directory name | Why it was moved |
|---|---|
partition_ |
A failover set this node's copy aside as divergent |
partition_ |
The seed's reference check found another history |
partition_ |
This node no longer holds any role in the partition (a migration source, a moved or dropped copy) |
partition_ |
A stream index failed to parse at startup, and another node holds the partition in sync |
A -released or -diverged name already taken gets -2, -3, … appended (the epoch does not move when a copy is re-seeded, so one partition can be set aside more than once at one epoch). Nothing ever deletes a quarantine — reclaiming the
space is an operator's decision, made by hand once the data is known to be unneeded. Plan disk for
it: a completed migration's source keeps its files there.
At startup, a clustered node finding a stream.idx that does not parse sets that partition
aside as -corrupt and starts, returning as a copy and re-seeding — but only while the directory
names another in-sync holder. A node still named primary waits for the failover first; the sole
holder, or a single-node build, still refuses to start.
Metrics
| Metric | Kind | Read it as |
|---|---|---|
mirexa_ |
gauge | Chunks known to fail verification and not yet repaired. Alert on this staying above zero: it means no peer holds that chunk whole |
mirexa_ |
counter | Bytes the scrub has verified |
mirexa_ |
counter | Completed scrub cycles |
mirexa_ |
counter | Chunks rebuilt from a peer |
mirexa_ |
counter | Times a copy held another history and was moved aside |
mirexa_ |
counter | Chunks a copy dropped because its primary's retention had |
mirexa_ |
counter | Partitions set aside at startup over a corrupt index |
Measured behaviour
Measured 2026-10-16 on one development laptop (cmd/server/reconcile_measure_test.go):
- A cut network. A proxy cut a copy off from its primary while both ran; during the cut the primary wrote, cut chunks and restated two bars, and one of the copy's chunks rotted. The copy left the in-sync set in about 0.5 s. After the link healed it was byte-identical, repaired and back in sync in about 0.8 s, with no operator action.
- Repair under writes. A repair landed in about 167 ms while the primary kept writing and the copy kept seeding.
- Scrub coverage. On a moved clock, 60 injected rots (a data bit, a footer bit, a missing file) were each found by the end of the next full cycle, and nothing else was reported.
- Repair under read load. A repair failed no read that touched no rot, with the node sustaining
at least 50,000 successful reads per second throughout (72–91K/s over six runs; checked by
make perf-check, not bymake test).
References
Source
storage.VerifyChunk,SeedInstaller.RepairChunk,MirrorRetention,Layout.QuarantinePartitionErrArtifactCorrupt, the seed reference,FetchArtifactserverchunkScrubber,chunkRepairer, quarantine,rottenChunks- Startup quarantine, its policy
Tests
TestVerifyChunk_RefusesBytesThatAreNotTheChunkTheirEntryNames,TestSeedInstaller_ARottenChunkIsRefusedBeforeAnythingLands— /internal/storage/seed_install_test.goTestUnmarshal_RefusesEverySingleBitFlip— /internal/compression/chunk_integration_test.goTestSeed_AnArtifactThatFailsVerificationEndsTheSeedAsDataLoss— /internal/replication/seed_test.goTestReplica_ACorruptChunkOnThePrimaryIsNeverInstalledOnACopy,TestReplica_ACopyDropsWhatItsPrimarysRetentionDropped— /cmd/server/reconcile_test.goTestSeedInstaller_ACopyHoldingAnotherHistoryBelowItsFloorIsRefused,TestSeedInstaller_RetirementMirrorsOnlyWhatRetentionDropped— /internal/storage/seed_reference_test.goTestSeedSink_NothingIsMirroredFromAPrimaryWithAnotherHistory— /cmd/server/seed_index_test.goTestCatchup_ACopyHoldingAnotherHistoryLeavesTheInSyncSetAndEnds— /internal/replication/catchup_test.goTestReplicaSupervisor_ACopyHoldingAnotherHistoryIsMovedAsideAndSeedsAgain,TestReplicaSupervisor_ACopyWhoseRoleEndedIsMovedAsideAndNothingOfItIsDeleted— /cmd/server/release_test.goTestChunkScrubber_ReadsWithinItsBudgetAndResumesWhereItStopped— /cmd/server/scrub_test.goTestReplicaSupervisor_AChunkThatRotsBelowEveryFloorIsFoundAndRepaired,TestReplicaSupervisor_APrimarysRottenChunkIsRepairedFromItsCopy,TestReplicaSupervisor_ACopysRottenChunkIsRepairedFromItsPrimary,TestReplicaSupervisor_ACopyRepairsOnlyFromItsPrimary— /cmd/server/repair_test.goTestFetchArtifact_AnswersOnlyThePrimaryAndItsCopiesAtTheCurrentEpoch— /internal/replication/fetch_server_test.goTestStartup_ACorruptIndexSetsItsPartitionAsideAndTheNodeStarts— /internal/ingestion/startup_quarantine_test.goTestReplica_ACopyCutOffFromItsPrimaryReconcilesWhenTheLinkHeals,TestReplicaSupervisor_ARepairLandsWhileThePrimaryKeepsTakingWrites,TestChunkScrubber_FindsEveryInjectedRotWithinOneFullCycle,TestPerfCheck_APrimaryRepairsWhileServing50KReadsPerSecond,BenchmarkQuery_WhileTheScrubRuns— /cmd/server/reconcile_measure_test.go
Further reading
External
- Guy Castagnoli, Stefan Bräuer, Martin Herrmann, "Optimization of Cyclic Redundancy-Check Codes with 24 and 32 Parity Bits", IEEE Transactions on Communications 41(6), 1993
- OpenZFS documentation, "zpool-scrub" (rate-limited background verification) — https://openzfs.github.io/openzfs-docs/man/master/8/zpool-scrub.8.html
VerifyChunkininternal/storage/chunk_file.go. ↩︎StreamArtifacts.IssuedThroughininternal/replication/seed.go;StreamReferenceinproto/mirexa/replication/v1/replication.proto. ↩︎StreamArtifacts.RetainedFromininternal/replication/seed.go;SeedInstaller.MirrorRetentionininternal/storage/seed_install.go. ↩︎chunkScrubberandscrubBurstincmd/server/scrub.go;ClusterConfig.ScrubBytesPerSecondininternal/config/config.go. ↩︎chunkRepairerincmd/server/replica.go;rottenChunksincmd/server/replication.go;internal/replication/fetch_server.go. ↩︎Layout.QuarantinePartitionininternal/storage/layout.go; quarantine naming incmd/server/replica.goandinternal/ingestion/startup_quarantine.go. ↩︎