Skip to content

fix(selene): fix local storage tier, input cache, sharding, and codec edge cases - #610

Merged
yatesdr merged 1 commit into
NVIDIA:mainfrom
yatesdr:fix/selene-local-tiers-and-sharding
Nov 29, 2026
Merged

yatesdr merged 1 commit into
NVIDIA:mainfrom
yatesdr:fix/selene-local-tiers-and-sharding

Conversation

@yatesdr

@yatesdr yatesdr commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Why this change is needed

An audit of Selene's local storage tiers, prepared-input cache, multi-host sharded disk transport, direct I/O worker, and KV-codec helpers surfaced several correctness, durability, and accounting defects (beyond the items already landed in #607):

  • DiskStore::new treated v4 packed files as readable even when receive_profiles was empty (e.g., restarting with --lossless-kv-compression off over a compressed disk directory), and Header::decode could panic on corrupt v4 headers with empty ranks and replication flags set.
  • Announce::hashing leaked DRAM pins or announced stale hashes across interleaved Ready/Gone/Ready transitions; CompositeStore::store allowed direct-to-disk writes under unwritten DRAM-parked ancestors; Inbound::used_disk misattributed NVMe bytes; Reclaim::unlinked leaked used accounting after Truncate-then-Unlink; and DiskStore::make_room_inner could self-evict in a loop.
  • InputStore could drop invalidations when the worker queue was saturated, conflate waiter generations, leave waiters blocked if the worker exited, or evict before checking retain().
  • Multi-host Sharded rank-0 disk limit negotiation only propagated two-rank limits instead of the global minimum across 3+ ranks, shard::agree retained page-only leaves after row intersection, Peer::shutdown leaked unconditionally even when drained, Peer::dispatch fell back to rank-0 truncation on corrupt v4 headers, and Sharded::close closed peers serially and marked itself closed on partial failure.
  • disk.rs did not retry EINTR in fallocate or io_uring, did not retry block-aligned short transfers, and called directory sync_all on Windows.
  • PooledStore::fetch did not reject duplicate in-flight keys and started rate tracking before accepted fetches; GpuPlan::decode_checked_cpu held a RefCell borrow across Rayon work; geometry.rs and codec_layout.rs lacked checked arithmetic / unknown-buffer checks.

Each fix resolves the defect locally inside its owning module without changing Selene's storage architecture or wire compatibility.

What changed

  • Local DRAM, composite, and pooled store tiers (selene/src/memory.rs, selene/src/composite.rs, selene/src/store.rs, selene/src/levels.rs, selene/src/pool/store.rs): Track HashingState { in_flight, notice, rehash } in Announce::hashing; fast-path allocate_slots(0, false); refuse direct-to-disk writes under unwritten DRAM-parked ancestors (triggering ancestor spill and Retry(Inflight)); fix Inbound::used_disk NVMe attribution; remove waiting_spills HOL cap; guard worth_transfer against NaN; fix Reclaim::unlinked accounting; reject duplicate in-flight keys in PooledStore::fetch, start Rate only after accepted paged fetches, and prefer faster equal-length local hits when a remote level is degraded.
  • Disk store, direct I/O, and v4 validation (selene/src/disk_store.rs, selene/src/disk.rs, selene/src/shared/record.rs): Require !receive_profiles.is_empty() for v4 packed files in DiskStore::new; stop self-eviction loops in DiskStore::make_room_inner; reject v4 empty ranks and replication flags before derive() in Header::decode; retry EINTR in fallocate/io_uring and retry block-aligned short transfers; handle Windows-safe Worker::publish and Unix post-rename directory-sync cleanup; update open_reads_header_and_checksums_in_one_transfer truncated-file chunk count (3 -> 4) to reflect EOF confirmation on block-aligned short reads.
  • Prepared-input cache (selene/src/input.rs): Use an unbounded invalidation channel, isolate waiters by generation epoch, release waiters via WaiterGuard on worker exit, pre-check retain() before eviction, and fix len() vs capacity().
  • Multi-host sharding (selene/src/shard.rs, selene/src/shard/tests.rs, selene/src/offload/sharded.rs): Return (drained, result) from Peer::shutdown so serve() only leaks when !drained; return with_record_read() on v4 mismatch and refuse rank-0 truncate fallback on corrupt v4 files; prune page-only leaves in shard::agree; poll all peers concurrently in Sharded::close and only set closed = true on success; filter unreadable v4 files across all ranks when KvCompression::Off; propagate the global minimum disk limit across 3+ ranks; canonicalize peer IPs.
  • Codec and geometry safety (selene/src/shared/gpu_codec.rs, selene/src/geometry.rs, selene/src/shared/codec_layout.rs): Use RefCell::take instead of holding a borrow across Rayon in GpuPlan::decode_checked_cpu; use checked arithmetic in geometry.rs; reject unknown buffer names in codec_layout.rs.
  • Unit tests: Added decode_rejects_v4_empty_ranks_and_replication_flags_without_panicking, invalidate_succeeds_even_when_job_queue_is_saturated, agree_prunes_page_only_leaves_after_row_intersection, and NaN worth_transfer tests.

Expected benefit and measured result

Local tiers, prepared-input caches, multi-host sharded ranks, direct I/O loops, and CPU/GPU codec paths no longer leak pins or disk accounting, desync disk limits across 3+ ranks, or panic on malformed v4 headers. Empirically verified on a 4-node GB10 TP4 cluster with heterogeneous per-rank disk limits (512M / 384M / 256M / 512M): baseline desynced to 0.2 / 0.4 / 0.2 / 0.5 GiB while patched converged all 4 ranks to the exact 0.2 GiB global minimum.

Supporting evidence

  • Standalone branch rebased onto post-#607 main (5df8edd3c):
    • RUSTFLAGS="-D warnings" cargo check --locked --manifest-path selene/Cargo.toml --all-targets --features codec,rdma and selene-manager --lib --bins: passed with 0 warnings.
    • cargo test --locked --release --manifest-path selene/Cargo.toml --features codec --lib: 542/542 passed.
  • Combined 4-PR validation & SM120/SM121 hardware qualification:
    • FLARE_RUN_CUDA_TESTS=1 SM120 4× RTX PRO 6000 (cn5, with kv_codec_gpu-sm_120a): 28/28 helios::offload:: CUDA tests passed.
    • Baseline vs Patched live flare run + selene-manager qualification across DeepSeek-V4.1-Flash-1017 TP4, GLM-5.3-Flash TP2 & TP4 (off, cpu + cpu -> off restart, gpu), Qwen3.8-Flash-Next TP1 & TP2 on SM120 (cn5), and 4-node GB10 TP4 (--roce-ring) on cn6–cn9: 0 panics, 0 quarantined bytes, bit-exact pos0 parity, and verified 4-rank global min disk limit convergence.
  • Material limitations: Windows Worker::publish path was checked structurally but not run on Windows; live hardware qualification ran against the combined 4-PR stack before rebasing onto #496/#497/#607, and CPU tests were re-run after rebasing onto 5df8edd3c.

Discord: D-Rock

@yatesdr
yatesdr force-pushed the fix/selene-local-tiers-and-sharding branch 2 times, most recently from 7081343 to 999094e Compare November 29, 2026 17:26
Local storage tiers, prepared-input caching, sharded disk ranks, direct
I/O loops, and KV-codec helpers had several correctness, durability, and
accounting bugs:

- Track `HashingState { in_flight, notice, rehash }` in `Announce::hashing`
  so interleaved `Ready`/`Gone`/`Ready` transitions neither leak DRAM
  pins nor announce stale hashes, and fast-path `allocate_slots(0, false)`
  (`selene/src/memory.rs`).
- Refuse direct-to-disk writes under unwritten DRAM-parked ancestors in
  `CompositeStore::store`, fix `Inbound::used_disk` NVMe attribution,
  and remove the `waiting_spills` head-of-line cap
  (`selene/src/composite.rs`).
- Require `!receive_profiles.is_empty()` for v4 packed files in
  `DiskStore::new`, prevent self-eviction loops in `make_room_inner`,
  fix `Reclaim::unlinked` `used` accounting after `Truncate`-then-`Unlink`,
  and reject v4 empty `ranks` and replication flags in `Header::decode`
  (`selene/src/disk_store.rs`, `selene/src/shared/record.rs`).
- Use an unbounded invalidation queue, generation epochs, `WaiterGuard`,
  pre-eviction `retain()` checks, and accurate `len()` vs `capacity()`
  in `InputStore` (`selene/src/input.rs`).
- Return `(drained, result)` from `Peer::shutdown`, return
  `with_record_read()` on v4 mismatch and refuse rank-0 truncate fallback
  on corrupt v4 files, prune page-only leaves in `shard::agree`, close
  peers concurrently in `Sharded::close`, filter unreadable v4 files when
  `KvCompression::Off`, propagate the global minimum disk limit across
  3+ ranks, and canonicalize peer IPs (`selene/src/shard.rs`,
  `selene/src/shard/tests.rs`, `selene/src/offload/sharded.rs`).
- Retry `EINTR` in `fallocate` and `io_uring`, retry block-aligned short
  transfers, and make `Worker::publish` directory sync Windows-safe
  (`selene/src/disk.rs`).
- Reject duplicate in-flight keys in `PooledStore::fetch`, start rate
  tracking only after accepted paged fetches, prefer faster equal-length
  local hits when a remote tier is degraded, guard `worth_transfer`
  against NaN, use `RefCell::take` across Rayon in `GpuPlan::decode_checked_cpu`,
  use checked arithmetic in `geometry.rs`, and reject unknown buffer
  names in `codec_layout.rs` (`selene/src/pool/store.rs`,
  `selene/src/levels.rs`, `selene/src/store.rs`,
  `selene/src/shared/gpu_codec.rs`, `selene/src/geometry.rs`,
  `selene/src/shared/codec_layout.rs`).

Local tiers, sharded disk ranks, prepared-input caches, and codec paths
no longer leak pins or disk accounting, desync disk limits across 3+
ranks, or panic on corrupt v4 headers.

Validated on Linux (rebased onto post-NVIDIA#607 main `5df8edd3c`), GB10, and
SM120 hardware across `selene`, `selene-manager`, and `helios offload::`.

Signed-off-by: yatesdr <6937857+yatesdr@users.noreply.github.com>
Design-Signed-Off-By: yatesdr; design-review=2e5b
@yatesdr
yatesdr force-pushed the fix/selene-local-tiers-and-sharding branch from 999094e to c4788c7 Compare November 29, 2026 17:27
@yatesdr
yatesdr merged commit a56333a into NVIDIA:main Nov 29, 2026
2 of 3 checks passed
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.

1 participant