Skip to content

[Store] Add TCP owner-push SSD read engine and FileStorage streaming reader - #5789

Draft
MaskVulcan wants to merge 24 commits into
kvcache-ai:mainfrom
MaskVulcan:ssd/pr3-owner-push-engine
Draft

MaskVulcan wants to merge 24 commits into
kvcache-ai:mainfrom
MaskVulcan:ssd/pr3-owner-push-engine

Conversation

@MaskVulcan

@MaskVulcan MaskVulcan commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

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

Stacked Draft PR: Depends on #5773 (PR 1: route-driven submitReceiverVisibleWrite()) and #5788 (PR 2: local SSD streaming I/O). Because cross-fork PRs target main, GitHub's Files changed view currently includes PR 1 and PR 2 commits; review only this PR's incremental changes here: Incremental diff (6b2c68b38...29ec5ac7d).

Summary

Implements the complete in-process Owner-Push data and control engine without opening network listeners or modifying RealClient / Python APIs:

  1. Destination isolation & bounded control ledger (DestinationRegistry, SsdOwnerRequestLedger, SsdDirectReadOwner, SsdFixedL2Requester, ssd_control_wire.*, random.h):
    • Authorizes registered CPU destination spans per attempt (requester, boot_epoch, request_id), rejects overlapping or out-of-bounds spans, and pins pending destination ranges until drain is proven.
    • Replaces scalar replay floors with exact retired-ID interval maps (RetiredRanges, bounded by max_records) and oldest-completion-time eviction (completed_at), tolerating out-of-order concurrent requests.
    • ReadWithRecovery enforces a bounded recovery budget; Close() rejects new reads while still serving kRecoverReadInto and waking duplicate waiters promptly.
    • Zeroizes stack entropy in secureRandomBytes (Linux + macOS <sys/random.h>).
  2. Classic TCP v2 receiver-visible write target (ssd_transfer_target.*):
    • Uses PR 1's TransferEngine::submitReceiverVisibleWrite() with zero TransferRequest ABI, TENT, or RDMA changes.
    • Coalesces adjacent fragments within a single registered remote BufferDesc, submits in bounded waves across fixed TCP lanes, drains every submitted batch before releasing staging slots, null-checks metadata, handles negative SegmentHandle errors safely, and skips zero-length fragments.
  3. FileStorage owner streaming reader (file_storage.*, ssd_file_storage_owner_reader.*):
    • Adds FileStorage::ReadOwnerStreaming() and MakeFileStorageOwnerReader().
    • Supports bounded whole-value bulk batching within staging budget, single-value in-flight staging reuse (LoadBatchShared), automatic streaming fallback under staging fragmentation or contended >=256 KiB reads, and Shutdown() draining active owner reads before rejecting new ones.

Series Overview (RFC #5768)

| PR 3 | #5789 (this PR) | 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

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
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>
Address review findings for submitAcknowledgedTcpWrite:
- Enforce v2 framing and WRITE opcode before the zero-length fast path in
  TcpTransport::startTransfer, log rejected requests, and document local
  no-op semantics for zero-length acknowledged writes.
- Validate classic TCP availability before selectTransports, pre-check
  v2 framing (MC_TCP_PROTO / peer tcp_proto_version) before mutating the
  batch so mixed v2/v1 batches cannot partially dispatch, and require an
  explicit require_ack argument on startTransferSequence.
- Include tcp_proto_version in TransferMetadata::SegmentDesc::operator==
  so protocol-only metadata updates are installed by syncSegmentCache.
- Dispatch unpooled one-shot ClientSession::initiate() onto
  socket->get_executor() in TcpTransport::startTransferWithSocket to avoid
  cross-thread progress timer races, and track one-shot sessions in
  ConnectionLaneState so shutdownConnectionLanes() cancels and fails
  in-flight unpooled work cleanly.
- Encapsulate TcpTransport acknowledged-write helpers behind friend class
  MultiTransport.
- Expand unit tests for zero-length legacy writes, legacy peer metadata,
  mixed batches, ungrouped and grouped mid-sequence metadata downgrades,
  grouped writes, unpooled connections, and unpooled shutdown while
  awaiting a receiver ACK.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
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>
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>
Clarify submitAcknowledgedTcpWrite as a fail-closed v2 downgrade guard
on top of TCP v2's existing receiver-ACK write semantics, tighten
internal boundaries, and streamline tests:
- Replace friend class MultiTransport with public validation/submit
  helpers on TcpTransport and hide OneShotSession in
  tcp_transport_lane_impl.h.
- Query getSegmentDescByID instead of getCachedSegmentDescByID during
  acknowledged-write preflight to eliminate a stale-cache race window.
- Rate-limit dispatch-time rejection logs, drop the redundant opcode
  check, and assert transport identity in MultiTransport.
- Consolidate tests into five focused cases covering pooled, grouped,
  and unpooled acknowledged writes, legacy/downgrade rejections,
  unpooled shutdown via submitTransfer, and SegmentDesc equality.

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>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
@MaskVulcan
MaskVulcan force-pushed the ssd/pr3-owner-push-engine branch from a9470f7 to bae08eb Compare November 25, 2026 17:40
…nd harden unpooled shutdown

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

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
@MaskVulcan
MaskVulcan force-pushed the ssd/pr3-owner-push-engine branch from bae08eb to d509a8d Compare November 25, 2026 21:14
…e and split out TCP bugfixes

Address review feedback on kvcache-ai#5773:
- Split out unpooled TCP initiation/shutdown tracking and SegmentDesc::operator== tcp_proto_version comparison into standalone independent bugfix PRs, restoring TcpTransport::supportsParallelBatchSubmit() == true.
- Rename submitAcknowledgedTcpWrite to guarantee-oriented submitReceiverVisibleWrite and move route validation/submission onto Transport virtual hooks (validateReceiverVisibleWrites / submitReceiverVisibleWriteTasks) so each transport decides whether it can satisfy receiver-visible write completion without MultiTransport special-casing TCP.
- Share the completion-latch arming, seal/unseal, and pinned tail release lifecycle between submitTransfer and submitReceiverVisibleWrite via MultiTransport::submitTransferImpl.
- Add Status::Code::kProtocolUnsupported (Status::ProtocolUnsupported / IsProtocolUnsupported) so legacy peer / MC_TCP_PROTO=1 rejections are machine-distinguishable from TENT NotImplemented and unsupported-transport NotSupportedTransport.
- Simplify TcpTransport::validateReceiverVisibleWrites to a plain std::unordered_set<SegmentID> when metacache is enabled and document the deliberate per-stage descriptor refreshes when metacache is disabled.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Add owner-push control primitives (DestinationRegistry, SsdReadProtocol,
SsdOwnerRequestLedger with bounded retired-ID intervals and completion-time
eviction, SsdControlWire codec, SsdDirectReadOwner, SsdFixedL2Requester with
bounded ReadWithRecovery, and portable secureRandomBytes).

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Add classic host TCP v2 SourceDrainedWriteTarget adapter built on
TransferEngine::submitAcknowledgedTcpWrite without TransferRequest ABI,
submitScatter, RDMA/TENT, or global drain changes.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Add FileStorage::ReadOwnerStreaming and MakeFileStorageOwnerReader
connecting FileStorage's bounded staging pipeline (POSIX and io_uring) to
SsdDirectReadOwner::Reader.

- Holds streaming_mutex_ shared lock so FileStorage::Shutdown drains active
  owner reads before releasing staging memory.
- Guards BuildColdReadFlightKey optional before dereference.
- Falls back cleanly to ThreadedPipelineDriver when io_uring is unavailable.
- Adds FileStorage owner streaming unit tests and an end-to-end TCP v2
  owner-push restore test across two TransferEngines.

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

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>
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 Transfer Engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant