Repository navigation
Tags
Tags
subduction_core: Decouple watch delivery from peer sync Problem: the driver for `load_and_watch` waited for the initial replay of storage events into the stream to finish before starting peer sync. A slow stream can thus delay synchronization. Solution: run the peer sync as soon as the local scan has complete, independently of whether the stream consumer is keeping up.
subduction_wasm: 0.29.0-automerge-repo-niceties.0
Make `RemoteHeadsObserver` actually reach quiescence (#299) * Fire on_peer_disconnect on every disconnect path `Handler::on_peer_disconnect` fired only from the listen loop, when a failed or closed connection was removed. The application's own disconnect calls (`disconnect`, `disconnect_from_peer`, `disconnect_all`) tore the peer down without telling handlers, so per-peer handler state outlived the peer: ephemeral subscriptions, the nonce cache and in-flight counters (see the FIXME this removes from `EphemeralHandler`), and keyhive's peer registrations. Every per-peer path, `remove_connection` included, already ends in `teardown_peer`, so the hook moves there and fires once the peer's last connection is gone. `disconnect_all` does the same for each peer after draining. The listen loop no longer fires it separately. The hook runs after the `connections` lock is released, because a handler may call back in, and is skipped for a peer that reconnected in the meantime. `peer_disconnect_hook.rs` checks that it fires exactly once per departure on each path, and not while another connection to the peer is live. * Wait for the heads filter lock instead of dropping updates `FilteredHeadsNotifier::notify` took its lock with `try_lock` and silently dropped the update when the lock was contended. That was tolerable while the critical section was one counter comparison. The next commit delivers to the observer while the lock is held, so contention becomes routine, and a dropped update would leave the observer with old heads. `notify` now waits for the lock, so it is `async`. `RemoteHeadsNotifier` takes the `FutureForm` as a parameter and returns `Async::Future`, matching `Handler`; every implementation and bound is updated. Breaking: implementors of `RemoteHeadsNotifier` must return a future. * Notify heads observers only when heads change `RemoteHeadsObserver` promised to fire "when a peer's heads change", and `design/sync/README.md` said the same, but `FilteredHeadsNotifier` filtered on the monotonic counter alone. That counter comes from `PeerCounter::next`, which increments on every heads-carrying message a peer sends, so it is always strictly greater and the filter never suppressed anything. Every `HeadsUpdate`, every `sender_heads` on a push, and every `responder_heads` on a sync response reached the observer, unchanged heads included. An application that answers the callback with a sync (the obvious reading) therefore never quiesces: the sync's own response carries `responder_heads`, which fires the callback, which syncs again. Six syncs of a converged tree produced six notifications carrying identical heads. Two independent defects in one filter: the key was too coarse for the counter check, and the counter check was the only check. Because one counter sequence covers every tree, a message about tree Y (counter 6) arriving before one about tree X (counter 5) also discarded X's update as stale. The filter now keys on `(PeerId, SedimentreeId)` and remembers the heads last reported, not just the counter: an update is forwarded when its counter is newer for that pair _and_ its heads differ. Heads are sorted and deduplicated first, since senders build them from a `Set` whose order is unspecified. A peer's entries are capped at 4096 trees; updates past the cap are delivered but not recorded. Consequences for the surrounding code, each of which the old filter hid: - Delivery happens while the filter's per-peer lock is held. Reporting after releasing it let two concurrent notifications for one tree deliver newest-first, leaving the observer permanently holding the older heads: the newer ones are recorded, so they are never reported again. The observer contract now says to return promptly and not call back into Subduction synchronously. - `sender_heads` is reported after the signature check, the storage policy gate and storage, not before. Filter state is per-tree now, so reporting first let any connected peer plant entries for trees it has no access to, from messages whose signatures then failed. - `SyncHandler::on_peer_disconnect` clears the peer's entries. They are per-session: a peer that restarts its process starts a new `PeerCounter`, and old marks would drop its updates as stale. Observers receive strictly fewer callbacks than before. That is a change to a published contract: anything relying on the old fires-on-every-mention behaviour (as a liveness ping, say) will see it stop. * Reset the heads filter on every new connection Receivers cleared a peer's high-water marks only when they saw it disconnect. A sender that restarts and reconnects while its old connection still looks live here (a half-open TCP connection, a reloaded page) starts a new counter below its old marks, so every report it sends is dropped as stale for the whole session. Seeding the counter from the wall clock hid this, but needs a clock (unavailable under `no_std`) and trusts it not to step backwards. `Handler` gains a required `on_peer_connect`, called for each new authenticated connection before any message on it is dispatched: from `add_connection`, and from `on_reconnect_success` even when the redialled connection was deduplicated against a stale entry. `SyncHandler` clears the peer's marks there, so marks are per-session and a restarted sender may start again from zero; seeding is now optional. Wrapping handlers forward the hook. The receiver cannot tell a restarted sender from a live peer's extra connection, so it resets on both. That costs one extra report per tree, and opens a narrow window in which a delayed report on the older connection lands after the reset and is delivered out of order. Breaking: `Handler` implementors must add `on_peer_connect`.
subduction_core: add a conformance suite for MinimizedTreeStore (#401) The store contract describes behaviour over time and across nodes, which the compiler cannot check. A store that breaks it compiles and mostly works, then hides commits that are in storage. Teams writing their own networked store need a way to check theirs. `minimized_tree_store::conformance`, behind a new `conformance` feature, mirrors `storage::conformance`: - Checks every store must pass, through one handle. - Checks of rules 1 to 3 through two handles to one backing store, which accept only a `SharedMinimizedTreeStore`. - `check_ops`, which runs generated operation sequences (`Op` implements `Arbitrary`) against both handles and compares every result with a model of storage: a hit always equals storage, a removed tree never hits, and a populate is kept only if no write happened since its miss. Trees include fragments and parent edges, so a store that loses them in serialization fails. The feature pulls in no executor, so the suite builds on a store's own target, including Wasm. `tests/minimized_tree_store_conformance.rs` runs it against every stock store, including a bounded shared store small enough that most sequences sweep. The shared store's unit tests that the suite now covers are removed; its reclamation tests stay, since the suite cannot force a store to forget a marker.
Extract out a minimized tree store (#397) * subduction_core: benchmark minimized-tree hot paths The next commits move the node's minimized-tree LRU behind a trait. Its reads are the per-commit hot path, so the change has to stay as fast as the concrete map. Land the benchmark first so it can be run on both sides of that change. It uses only the builder's default store and node methods that exist before and after: - `hot_heads` / `hot_commits`: reads of a resident tree. - `write_resident`: one write into a resident tree of fixed size. - `cold_heads`: a read that hydrates from storage. - `contended_heads`: concurrent reads of one tree from many tasks. * collections: owned checkouts for BoundedShardedMap A minimized tree store needs to hand out a resident tree that the node can read and minimize in place. Its trait method returns a future, so the handle cannot borrow the map: a borrowed guard tied to `&self` cannot be `Send` for every lifetime the future form requires. Hold each shard in an `Arc` so it can be locked with an owned guard, and add: - `checkout`, which returns a `Checkout` holding the shard lock and derefs to the value, recording an access like the other readers. - `insert_if_absent`, which keeps a resident value rather than replacing it. `ShardedMap::shard_at` stops being `const`, since it now indexes an `Arc` array. The existing closure-based helpers stay until their callers move over. * subduction_core: add the MinimizedTreeStore trait Serving sync needs each tree's minimized form, which takes a full storage read and a minimization pass to build. The node keeps built trees in a process-local LRU. That is right for one node, but a deployment where several nodes share storage (for example on Cloudflare) needs the trees in a store those nodes share, or each node goes stale on the others' writes. Define where built trees live as a trait, so a deployment can choose: - `get` checks out a resident tree or reports a miss with the tree's current generation. - `populate` keeps a tree rebuilt after a miss, unless the generation moved since: a compare-and-set that stops a slow reader from hiding a concurrent write. - `merge` and `remove` keep a resident tree in step with storage, and always change the generation. `Generation` is not required to be `Clone`, so the node can carry each one only from its miss to the matching `populate`. A store used by one node can make it `()`. Two stores ship here: `MemoryMinimizedTreeStore`, the existing bounded LRU behind the trait, and `NoopMinimizedTreeStore`, which keeps nothing. The module docs state the contract, including the rules a store shared between nodes must enforce itself. Nothing uses the trait yet; the next commit makes it a node effect. * subduction_core: make the minimized tree store a node effect The node kept built trees in a concrete `BoundedShardedMap`, fixed by a `SHARDS` const generic on `Subduction`, `SyncHandler`, `StorageTasks` and the builder. Make the store the node's sixth effect instead, so a deployment can keep trees per process, in a store shared between nodes, or not at all. Effects and construction: - `HasMinimizedTreeStore` names the store; `Effects` requires it, and `SendableEffects` requires its error and generation to be `Send`. - `Config` gains a sixth slot, defaulting to `MemoryMinimizedTreeStore`. - The builder's `.minimized_tree_store(store)` replaces `.sedimentrees()` and `.max_resident_trees()`; bound the default with `MemoryMinimizedTreeStore::with_capacity`. - `SHARDS` moves to `MemoryMinimizedTreeStore<SHARDS>` and leaves every node type. - `Subduction::minimized_tree_store()` returns the store, replacing `resident_sedimentree_count()`. Coordination (`storage/state`, `cache.rs`, `ingest.rs`, `handler/sync.rs`): - Each tree has a store lock. Populating after a miss (revalidate, then `populate`) and maintenance after a write (`merge` or `remove`, then settle) both hold it, so they never interleave. Hits take no lock. - A miss carries the store's generation to `populate`. If the store reports `Stale`, another node wrote since the miss: the read is served but not stored, since retrying could rescan storage without bound under remote writes. - A populate that overlaps a local write retries instead of adopting the resident tree. - A store error never fails a node operation. A failed `get` reads storage, a failed `populate` is ignored, and a failed `merge` or `remove` marks the tree bypassed: reads skip the store for it until a later `remove` succeeds. - The sync handler looks the tree up on each attempt and serves either the resident tree or a fresh scan. Behaviour changes: `sedimentree_ids` returns an empty list on a storage error instead of falling back to the resident set, which may not cover storage. Every call site moves over (CLI, Wasm, tokio, websocket, ingest), and `store_failures.rs` covers the error paths with a store whose generations and failures tests can control. * Remove automatic poisoned cache handling * Fix regression * Update docs
PreviousNext