~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/zlay

atproto relay in zig · mirror of https://tangled.org/zat.dev/zlay

0
0
81 lines · 4.4 KB Raw History
# Pending SST writes in the isolated pilot

`owner-async-prepared` is an opt-in index-load mode that keeps durable commit
acknowledgement, reader refresh and the existing bounded request queue, while
letting the owner process requests during an SST write. Only the data-plane
write runs on a worker; merge, validation, metadata ownership, publication and
garbage-collection decisions stay on the owner.

The core dependency is the isolated `codex/pending-compaction-io` branch. No
production pin or default background-write setting changes.

## Ownership and scheduling

The writer Db borrows an `AsyncStore` with independently mutable foreground and
background DirStore contexts in the same directory. The worker receives an
immutable finished SST buffer. The core retains it and the input version until
the write completes, and publication still requires durable success. Ordinary
`compactStep` and `compact` remain blocking compatibility paths.

The maintenance callback distinguishes idle, progress and waiting. While waiting,
the owner serves queued requests. If idle, it waits on its existing condition.
The completion callback only wakes that condition; a generation counter prevents
losing a notification delivered between the readiness check and wait. Close
drains accepted work and scheduled maintenance. Failure shutdown additionally
cancels/joins any remaining worker before destroying its notification context or
database buffers.

The same allocator policy and dedicated writer Io used by the pilot remain in
place. Core KV allocation stays on the owner. This does not introduce worker
allocation into zeldi's default store path.

## Verification completed

- Core Debug and ReleaseSafe tests cover real gated file writes, interleaved
  commit/flush/collection, cancellation, close, backend failure, concurrency
  exhaustion without inline fallback, and exactly-once write resumption.
- The actual zeldi `a6e94f8` full test/smoke suite passes with an isolated core
  dependency redirect. Default-size zeldi performance remains a separate gate.
- Pilot tests force a notification before the wait, serve requests while
  maintenance is waiting, drain background work while idle, verify read-after-ack
  and reopening, and refuse later writes after background concurrency fails.
  Reopening recovers every acknowledged pair and excludes rejected pairs.
- `zig build test` passes. The complete ReleaseSafe zio build passes.
- The native zio harness checks `stepped-prepared`, `owner-stepped-prepared` and
  `owner-async-prepared`. Each verifies all 384 expected pairs after drain/reopen.
  The background mode also requires observed background writes and pending polls.
  These are small functional checks, not comparative performance results.

```sh
zig build index-load -Dbackend=zio -Doptimize=ReleaseSafe
uv run --no-project python scripts/zkv/check_owner_maintenance.py zig-out/bin/index-load
```

## Measurement accounting

The harness reports `background_puts`, `background_put_ns` and
`maintenance_pending_polls`, in addition to foreground flush/compaction/collection
and explicit final-drain time. The background time covers the complete dedicated
DirStore put, including durability work. It overlaps foreground work and must
not be added to foreground elapsed time as if execution were serial. Worker
counters are read only after the owner has drained/joined its tasks; error exits
cancel/join before inspecting worker-owned state.

`background_writes` is zero for the blocking controls and one for the new mode.
The comparison should use one binary for owner-stepped versus owner-async, plus
the durable RocksDB application-path control. Keep logical traces, batching,
preparation, reader semantics and final debt visible.

## Remaining gates

No relay-scale latency improvement has been measured for this mode yet. Flush,
publication and collection still contain whole operations. Asynchronous writes
can still compete with WAL I/O and exhaust storage bandwidth; the queue bound
does not bound maintenance debt. The current deterministic simulation harness
does not generate pending-worker completion histories, so ordinary DST results
must not be presented as coverage of that new boundary.

Next are a calibrated pending-I/O fault campaign, matched remote latency and
debt measurements, compile/binary/heap overhead, the actual default-size zeldi
performance gate, sustained capacity through level turnovers, and a full relay
pilot when those results justify it.