Skip to content

fix: count only verified copies and pass over targets that stop confirming them - #175

Merged
Mearman merged 4 commits into
mainfrom
fix/verified-copies
Dec 4, 2026
Merged

Mearman merged 4 commits into
mainfrom
fix/verified-copies

Conversation

@Mearman

@Mearman Mearman commented Dec 4, 2026

Copy link
Copy Markdown
Member

Fixes #140. Refs #57, #58.

Composite placement counted a named, connected machine as a copy of a file without knowing it held any block. In the composite acceptance run every node logged under_replicated: [] while 8 files sat at one real copy, and a named store that never completes (full disk, persistent fetch error, a pass that never reaches the file) would have left them there for good. A cache could also evict the last real copy on the same assumption.

Verified copies. A machine now counts as a copy only once it has said, over a new holdings exchange, that it holds every block of the version this node holds. The P2P backend records each confirmation in its index against that version (migration 8, peer_copies), so counts survive a restart without asking again and an edit makes every peer prove its copy afresh. A cache's blocks are never counted (HolderBlocks.cache), so complete_holders/degraded are honest from any one node.

Promotion. Each holdings answer carries the peer's count of blocks fetched since it started. A named target owing copies whose count does not move for IDLE_PASSES_BEFORE_PROMOTION (2) consecutive passes, that reports the same fetch error as often, or that cannot answer at all, is treated as down for those files. Every node computes that the same way, so the next-ranked target finds itself named and fetches, with no coordinator. The bound counts passes and blocks, not time: one idle pass can be a healthy target between files of its serial walk, two in a row means it fetched nothing for a whole pass. A stalled target is reported once per cause change, asked again with exponential backoff (2, 4, ... 64 passes) and named again once it confirms or moves; a stalled must_hold target stays named and counted short while the copies are filled from the ranking.

Reporting. under_replicated lists files below min_copies verified copies (or missing a must_hold copy), each with its verified holders and its pending ones (blocks so far, cause). Each pass's counts are kept as Backend::replication_status, served at GET /v1/folders/{folder}/replication (status:read), logged at info when the number of short files changes, and checked by scripts/composite-acceptance.py verify on every host. path_holdings now includes the copies other machines confirmed, so one host shows every verified copy. Cache eviction uses the same verified count.

Protocol compatibility. A new capability domain holdings (wire tag 4) with HoldingsRequest (24) and HoldingsResponse (25), protocol version unchanged at 1 since no existing frame changes meaning. A node sends the frames only to a peer that advertised the domain, and a decoder that predates it drops the unknown domain tag (handshake_drops_unknown_domain_discriminant), so old peers never see an unknown frame and keep syncing content as before. An old peer's copies cannot be verified, so it is reported stalled with that cause and never counted. Answers sit behind the same read gate as block requests. Conformance vectors and docs/node-protocol.md cover both frames and the extended negotiation.

Tests (all counted in passes and blocks): a named peer that connects but never fetches stays listed under-replicated through the bound, then the next store is promoted and fetches it; a peer holding part of a file is not counted; verified counts survive a restart with the exchange turned off afterwards; an old peer syncs but is never counted; a cache keeps blocks no store has confirmed and evicts them once one has. With the verified filter mutated to count any answering peer, four of these go red.

A replication policy needs to know which blocks of a file a peer holds before
it counts that peer as a copy, and nothing on the wire carried that.

The new holdings capability domain (wire tag 4) adds HoldingsRequest (type 24)
and HoldingsResponse (type 25): per path, the peer's version vector, total and
held blocks and its last fetch error, plus a fetched-block progress counter.
A node sends them only to a peer that advertised the domain, and an older
decoder drops the unknown domain tag, so peers that predate it interoperate
unchanged. CapabilityDomain moves into protocol/domain.rs to keep
protocol.rs under the source-length cap. The frame and handshake conformance
vectors and node-protocol.md cover the new frames.

The sync engine answers holdings requests from its index and block store
behind the same read gate as block requests, counts the blocks it fetches,
and keeps each path's last fetch error. BlockHolder::peer_holdings answers
Complete only when the peer has every block of the version this node holds,
and records the confirmation in the index (migration 8, peer_copies), so it
is answered from the record after a restart and asked again only once the
file changes.

HolderBlocks gains the fetch error and a cache flag, so complete_holders and
degraded never count a cache's blocks as a copy, and Backend gains
replication_status for a backend that places copies by policy.
…led targets

Placement counted a named, connected machine as holding a file without
knowing it held any block, so a named store that never fetched (a full disk,
a persistent fetch error, a pass that never reached the file) left a file at
one real copy while every node reported nothing under-replicated, and a
cache could evict the last real copy.

A machine now counts only once it has answered the holdings exchange with
every block of the current version. under_replicated lists files below
min_copies verified copies, or missing a must_hold copy, with each one's
verified holders and its pending ones (blocks so far and cause). A target
owing copies whose fetched-block counter does not move for
IDLE_PASSES_BEFORE_PROMOTION consecutive passes, that reports the same
fetch error as often, or that cannot answer, is treated as down for those
files: every node computes the same promotion, so the next-ranked target
names itself and fetches with no coordinator. A stalled target is asked
again with exponential backoff and is named again once it confirms or
moves. Cache eviction uses the same verified count.

Each pass's counts are kept as the backend's replication_status and logged
when the number of under-replicated files changes, and path_holdings lists
the copies other machines confirmed, so one node shows every verified copy.
GET /v1/folders/{folder}/replication returns the last placement pass's
verified counts (files meeting min_copies, each under-replicated file with
its verified and pending holders, stalled targets and promoted files) under
status:read, and 404 for a backend that places no copies.
verify now reads each host's /replication and fails while any file is under
min_copies verified copies, printing the pending holders, their block counts
and causes, and the stalled targets. complete_stores skips holders flagged
as caches.
Copilot AI balanced review requested due to automatic review settings December 4, 2026 07:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Mearman
Mearman merged commit 85e5462 into main Dec 4, 2026
111 of 112 checks passed
@Mearman
Mearman deleted the fix/verified-copies branch December 4, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exchange block holdings between peers so placement counts verified copies

2 participants