Repository navigation
feat(node): batch DHT re-publish by receiver; drop BatchStore fallback (#1616) - #1748
Merged
Merged
Conversation
#1616) The BatchStore handler (admission + two-stage rate-limit accounting) already shipped in #713. What was missing: the outbound batch primitive was dead code (tests only) and the re-publish scheduler never batched. BatchStore is mandatory in cdn/dht/v1 — every node ships discriminants 4/5 from day one — so the "optional-with-fallback" framing was a version-negotiation shim for a peer that cannot exist pre-launch. Per the pre-launch rule (no version negotiation; delete the old shape), rip it out and batch unconditionally. - publish.rs: the periodic drain groups due hashes by receiver (each hash's K+3 closest) and sends one client::batch_store per receiver, split at the 256-hash cap. Eager per-insert publish stays per-hash Store (a size-1 batch buys nothing). New pure group_by_receiver, unit-tested. - Delete the fallback shim: batch_fallback.rs (BatchStoreFallback), batch_store_with_fallback, classify_batch_error, per_hash_fallback, extract_app_error_code + downcast helpers, and the exchange_on reset-probing that only fed them. Keep client::batch_store, client::store, and the whole receiver-side handler. - ADR 022: BatchStore/BatchStoreAck are mandatory in cdn/dht/v1 (no fallback, no negotiation); rewrite §STORE Flow Batched STORE, §Schema Evolution, and AC 19. Fix the stale "handler deferred to a follow-up issue" docstrings in protocol/src/dht.rs. Net -1054/+210. cargo fmt/clippy clean; nextest 1009 passed. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR completes DHT BatchStore adoption end-to-end by wiring unconditional publisher-side batching into the node republish scheduler and deleting the now-unneeded “optional batching + per-hash fallback” shim. It aligns the implementation and docs/ADR 022 with the repo’s pre-launch rule (no version-negotiation shims): BatchStore is treated as mandatory for cdn/dht/v1.
Changes:
- Implement receiver-grouped republish batching (
group_by_receiver+publish_batch) so periodic republish sends oneBatchStore(split to 256) per receiver instead of per-hash fanout. - Remove publisher-side fallback machinery (
BatchStoreFallback,batch_store_with_fallback, per-hash fallback helpers) and associated tests/exports. - Update protocol docs and ADR 022 to reflect
BatchStoreas mandatory and specify publisher-side batching behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/dht/publish.rs | Implements receiver-grouped batching for periodic republish and adds unit tests for grouping logic. |
| crates/node/src/dht/client.rs | Removes fallback/negotiation helpers; positions batch_store as the mandatory primitive used by republish batching. |
| crates/node/src/dht/mod.rs | Drops batch_fallback module and re-exports. |
| crates/node/src/dht/batch_fallback.rs | Deletes the fallback cache implementation (no longer needed with mandatory batching). |
| crates/node/tests/dht_loopback.rs | Removes fallback-negotiation integration tests; keeps loopback coverage for the batch_store primitive. |
| crates/protocol/src/dht.rs | Updates BatchStore/BatchStoreAck documentation to match mandatory support and new scheduler behavior. |
| adr/022-content-discovery.md | Updates STORE flow and acceptance criteria to require publisher-side batching and remove fallback negotiation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 80.64% (was 80.72%, ▼ 0.07%) — 58015/71941 lines
History
|
…e select loop Address PR review: - client::batch_store now errors on a BatchStoreAck whose results length doesn't match the request, instead of silently returning a vector that mis-maps onto the request hashes. The deleted fallback wrapper used to guard this; the primitive is now called directly, so it must guard itself. - The periodic republish drain reschedules the held hashes, then fires the batched publish on a detached task rather than awaiting it inside the run_republish select loop. A slow/unreachable receiver could otherwise hold the loop for up to (chunks × DHT_CLIENT_TIMEOUT), delaying the shutdown signal and eager cache-insert publishes. The sweep is best-effort — abandoned on shutdown, retried next cycle. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1616.
Context
The
BatchStorehandler this issue describes (admission + two-stage rate-limit accounting) already shipped in PR #713 (closes #648) — the issue was filed from a stale reading of the code. The genuinely-missing pieces were:client::batch_store) + fallback cache were dead code (referenced only in tests) — nothing in production ever sent aBatchStore.Storeper (peer, hash) and never batched, even at cold-start where ADR 022 calls for it.Key decision: BatchStore is mandatory in
cdn/dht/v1Every node ships discriminants 4/5 from day one, so no node speaks the DHT ALPN without implementing
BatchStore. The "optional-with-fallback" framing was a version-negotiation shim for a peer that cannot exist pre-launch. Per the repo's pre-launch rule (no version negotiation; change the format and delete the old shape), this PR batches unconditionally and rips the shim out.What changed
Wire batching into the re-publish scheduler (
crates/node/src/dht/publish.rs)group_by_receiverinverts a drain cycle's due hashes intoreceiver → hashes(each hash's K+3 closest), unit-tested.publish_batchsends oneclient::batch_storeper receiver, split at theMAX_BATCH_STORE_HASHES(256) cap, one task per receiver.Store— a size-1 batch buys nothing.Delete the fallback shim (−1054 lines)
batch_fallback.rs(BatchStoreFallback),batch_store_with_fallback,classify_batch_error,per_hash_fallback,extract_app_error_code+ downcast helpers, and theexchange_onreset-probing that existed only to feed them.client::batch_store,client::store, and the whole receiver-side handler (handle_batch_store,admit_batch_extra).ADR 022 + docstrings
BatchStore/BatchStoreAckare now documented as mandatory incdn/dht/v1(no fallback, no negotiation); rewrote §STORE Flow Batched STORE, §Schema Evolution, and AC 19 (was the fallback-cache requirement, now the publisher-side batching behavior).crates/protocol/src/dht.rs.Reviewer notes
UNSUPPORTED_MESSAGE— that's unchanged. Only the sender-side treatment ofUNSUPPORTEDas "fall back to per-hash" is removed.BatchStore/BatchStoreAckalready occupied discriminants 4/5.Verification
cargo fmt --check,cargo clippy --all-targets— clean (all pre-commit hooks passed)cargo nextest run -p decdn-protocol -p decdn-node— 1009 passed, 0 failedcargo test --no-run -p decdn-e2e --features anvil-e2e— compilesgroup_by_receiverwritten test-first (watched it fail, then pass)🤖 Generated with Claude Code