Skip to content

[Store] Add opt-in bounded local streaming SSD restore and per-client offload read pool - #5788

Open
MaskVulcan wants to merge 11 commits into
kvcache-ai:mainfrom
MaskVulcan:ssd/pr2-local-streaming-io
Open

MaskVulcan wants to merge 11 commits into
kvcache-ai:mainfrom
MaskVulcan:ssd/pr2-local-streaming-io

Conversation

@MaskVulcan

@MaskVulcan MaskVulcan commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Part 2 of 5 in the SSD Offload streaming & owner-push series tracked in RFC #5768.

Independent PR directly based on main (opt-in local streaming restore with zero Transfer Engine / TENT / Master protocol changes).

Summary

Adds an opt-in bounded local streaming restore path (MOONCAKE_OFFLOAD_LOCAL_STREAMING_READ=true, default false) for same-process BucketStorageBackend CPU reads, together with a per-RealClient offload read thread pool and RPC drain ordering hardening. Objects and ranges larger than the ClientBuffer staging arena can be restored directly into caller CPU slices using a fixed set of reusable staging slots.

  1. RPC drain ordering & per-client offload read pool (rpc_client_io_context.h, offload_read_executor_config.h, real_client.{h,cpp}):
    • Enforces std::memory_order_seq_cst in RpcDrainGuard so teardown never misses concurrent admissions.
    • Moves blocking legacy SSD restore RPC reads off the coro_rpc I/O loop onto a lazily initialized RealClient-owned asio::thread_pool (MOONCAKE_OFFLOAD_READ_IO_THREADS, default 64, range 1–128), drained and joined before FileStorage::Shutdown().
  2. Bounded streaming read planner & pipeline (ssd_read_pipeline.{h,cpp}, ssd_read_source.{h,cpp}, ssd_pipeline_io.{h,cpp}, ssd_streaming_config.h):
    • BuildReadPlan() splits reads into slot-sized chunks with bounded chunk/fragment limits.
    • OpenPosixReadSource() opens regular files non-blockingly (O_NONBLOCK cleared after S_ISREG / fstat validation) and pins backend lifetime tokens (BucketReadGuard) through the last in-flight read.
    • ReadPipeline, BoundedExecutor, and ThreadedPipelineDriver execute bounded multi-slot reads/copies with WaitSubmit backpressure and drain all accepted work on return or error.
    • StreamingReadConfig::Validate() accounts for OffsetAllocator 3-bit-mantissa bin rounding via OffsetAllocatorSlotBudget() (verified in lockstep against OffsetAllocator::normalizedAllocationSize()).
  3. Bucket-deduplicated source acquisition & FileStorage integration (storage_backend.{h,cpp}, file_storage.{h,cpp}):
    • BucketStorageBackend::AcquireReadSources() resolves a batch under one shared metadata lock, deduplicates open file descriptors and BucketReadGuards per bucket_id, and charges open-source credits against unique bucket count before calling open() — allowing large multi-key batches sharing a few buckets to stream cleanly.
    • FileStorage::ReadLocalStreaming() validates destinations before opening files, returns NOT_SUPPORTED on overlapping destinations so RealClient falls back to the sequential restore path, reaps expired remote staging leases on allocation pressure, and lazily initializes the pread fallback pool only when needed.
    • Supports whole and ranged CPU reads (including unregistered CPU user buffers in RealClient::execute_ranged_read() with safe fallback to partial_disk_read).
  4. Optional persistent io_uring read workers (Linux + liburing only) (ssd_uring_pipeline.{h,cpp}):
    • Enabled via MOONCAKE_OFFLOAD_STREAM_USE_URING=true alongside local streaming; compiled only on Linux when Mooncake::liburing is available.
    • Each worker owns one persistent io_uring ring, probes IORING_OP_READ and io_uring_enter (via NOP) during init, uses pure ClassifyUringReadResult() for short reads and bounded -EINTR/-EAGAIN retries, logs warnings on init/runtime failure, and falls back to ThreadedPipelineDriver (pread) on subsequent batches.
  5. Documentation (docs/source/design/store/ssd-offload.md):
    • Documents all opt-in environment variables, defaults, bounds, fallback rules, and drain semantics.

Series Overview (RFC #5768)

Part PR Scope Dependency
TE Fix (c) #5855 Compare tcp_proto_version in SegmentDesc::operator== Independent (main)
TE Fix (b) #5856 Serialize unpooled TCP initiation on socket executor & track shutdown Independent (main)
PR 1 #5773 Route-driven TransferEngine::submitReceiverVisibleWrite() & Status::ProtocolUnsupported (classic TCP v2 opt-in) Independent (main)
PR 2 #5788 (this PR) Bounded local SSD streaming read pipeline & optional io_uring workers Independent (main)
PR 3 #5789 TCP owner-push SSD read engine & FileStorage::ReadOwnerStreaming Depends on #5773 + #5788
PR 4 #5790 Hardened HMAC-SHA256 control RPC, peer directory, RealClient & Python _store Depends on #5789
PR 5 #5791 V6 object write generations, SSD task fencing & HA durable retirement Independent (main)

Local Validation

  • With liburing enabled: 8/8 targets passed (ssd_read_pipeline_test [incl. table-driven ClassifyUringReadResult tests], ssd_read_source_test, ssd_pipeline_io_test, ssd_uring_read_executor_contract_test [real kernel 1/2/4-worker reuse, isolation, drain, startup cleanup], file_storage_config_test [incl. OffsetAllocator bin-rounding lockstep test], offload_read_executor_config_test, file_storage_test --gtest_filter='*LocalStreaming*' 11/11 [incl. 80-key single-bucket deduplication & distinct-bucket cap], real_client_shutdown_test 7/7) + mooncake_client link check.
  • With liburing disabled (-- io_uring: Disabled): 7/7 non-uring targets + file_storage_test --gtest_filter='*LocalStreaming*' 11/11 + real_client_shutdown_test 7/7 + mooncake_client passed cleanly.
  • Formatting, spelling & DCO: clang-format 20.1.8 0 diff, typos 1.30.2 0 issues, DCO verified.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Add portable POSIX pread bounded streaming read pipeline (ReadSource,
ReadPipeline, ThreadedPipelineDriver, BoundedExecutor with WaitSubmit
backpressure) and wire FileStorage::ReadLocalStreaming into RealClient
whole and ranged local CPU restore paths under MOONCAKE_OFFLOAD_LOCAL_STREAMING_READ.

Includes ranged read fallback safety for unregistered CPU user buffers,
shared-mutex close drain, O_NONBLOCK clearing after regular-file validation,
aligned direct short-read continuation, unit/integration tests, and design docs.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Add optional io_uring streaming read executor and pipeline driver
(UringReadExecutor, UringPipelineDriver) with fixed-buffer support,
EBUSY/EINTR/EAGAIN retry handling, short-read continuation, liburing 2.1
user_data compatibility, atomic WaitForEvent ready/active check, ARM64
SYS_ppoll fallback in fault fixture, and CTest/ASan/UBSan coverage.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
@MaskVulcan

Copy link
Copy Markdown
Collaborator Author

@qoder please review this PR

@github-actions github-actions Bot added documentation Improvements or additions to documentation Store Common size/L 1001+ changed lines (additions + deletions) labels Nov 24, 2026
@MaskVulcan
MaskVulcan force-pushed the ssd/pr2-local-streaming-io branch 2 times, most recently from db4c7d3 to 50e95ed Compare November 24, 2026 17:51
Address adversarial review findings across local streaming restore and io_uring:
- Guard both can_use_pinned_restore_arena and local streaming under
  offload_rpc_drain_ in RealClient::execute_ranged_read, avoid holding
  offload_rpc_drain_ across outbound remote peer RPCs, null-guard
  file_storage_/client_ in offload RPC handlers, and skip redundant local
  streaming retries after fallback.
- Propagate sys_errno from PosixReadSource and io_uring read completions to
  NotifyDiskError/OnDiskError, respect disk_fenced_, validate backend type
  via dynamic_cast, reject overlapping destinations before source
  acquisition or max_chunks checks, merge multi-object batches into a
  single multi-source ReadPlan/driver with graceful slot degradation and
  expired-lease reaping on slot miss, check Start/Drain returns
  defensively, and map plan limits to NO_AVAILABLE_HANDLE for clean
  fallback.
- Probe IORING_OP_READ/IORING_OP_READ_FIXED via io_uring_get_probe_ring so
  pre-5.6 kernels cleanly fall back to POSIX pread, expose
  UringReadExecutor::healthy(), make UringReadExecutor::Impl::Fail()
  idempotent, flush retries inline in both UringReadExecutor and
  UringPipelineDriver, keep shutdown drain retrying short reads/EINTR,
  retry io_uring_unregister_buffers on EINTR, validate O_DIRECT alignment
  on local-ring reads, clamp Wait() deadlines against signed overflow in
  both drivers, return kInvalidArgument for null sources, cap read lengths
  at INT_MAX with saturating object-end arithmetic, and gate
  UringPipelineDriver::Create cleanly.
- Fix uint64_t/size_t deduction on 32-bit/macOS in file_storage_config.cpp,
  keep the deterministic fault test liburing fixture independent of distro
  <linux/io_uring.h> versions, and link
  ssd_uring_read_executor_contract_test standalone for BUILD_SHARED_LIBS=ON.
- Harden io_uring and config/storage tests with opcode/RLIMIT_MEMLOCK/
  O_DIRECT probes, safe RAII teardown ordering, WaitAccepted
  synchronization, default config assertions, and regression coverage for
  unhealthy/unsupported-opcode executors, disk fencing, plan limits,
  overlap precedence, multi-object uring/degraded-slot batches, and lease GC.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
@MaskVulcan
MaskVulcan force-pushed the ssd/pr2-local-streaming-io branch from 50e95ed to 1a86b58 Compare November 24, 2026 19:37
@MaskVulcan
MaskVulcan marked this pull request as ready for review November 25, 2026 03:13
Replace the process-global coro_io::io_context_pool used by offload
restore RPC reads with a RealClient-owned asio::thread_pool that is
initialized lazily on first use and stopped and joined during teardown
after in-flight offload RPCs drain.

Lazily initialize FileStorage::streaming_reads_ only when the portable
pread driver is needed so io_uring-backed local streaming restores do
not spawn idle fallback read workers, and align the SSD offload design
doc with per-batch fixed-buffer rings and fallback semantics.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Trim unused zero-caller abstractions and heavy test fixtures from the
local streaming restore path while fixing four correctness/usability
issues:
- Remove unused O_DIRECT, fixed_buffers per-batch io_uring engine,
  RebindSource, Cancel/attempt_id/region_id fields, and TrySubmit
  overloads; compile ssd_uring_pipeline.cpp only on Linux with liburing.
- Account for OffsetAllocator 3-bit-mantissa bin rounding in
  StreamingReadConfig::Validate() via OffsetAllocatorSlotBudget() with a
  lockstep test against OffsetAllocator::normalizedAllocationSize().
- Deduplicate bucket file descriptors and BucketReadGuards per bucket in
  BucketStorageBackend::AcquireReadSources() so large multi-key batches
  sharing a few buckets do not hit the open-source limit.
- Return NOT_SUPPORTED on overlapping destinations so RealClient falls
  back to the legacy sequential restore path instead of failing.
- Extract pure ClassifyUringReadResult() with table-driven unit tests,
  probe io_uring_enter via NOP during worker init, log warnings on
  io_uring init/runtime failure and pread fallback, and remove the fake
  liburing.h / libc-interposition fault test targets.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
@MaskVulcan MaskVulcan changed the title [Store] Add bounded local SSD streaming read pipeline and optional io_uring workers [Store] Add opt-in bounded local streaming SSD restore and per-client offload read pool Nov 25, 2026
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
… contracts

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
EL8 wheel-builder containers ship liburing 1.0.7, which provides
io_uring_get_probe_ring() and io_uring_opcode_supported() but predates
io_uring_free_probe() (introduced in liburing 2.0). Fall back to
std::free(probe) when IO_URING_VERSION_MAJOR < 2 (or undefined),
matching uring_file.cpp's version guard.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Common documentation Improvements or additions to documentation run-ci size/L 1001+ changed lines (additions + deletions) Store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant