How a rollout snapshot now holds the data-plane barrier for less time

PR #5241 ยท stacked on #5139 ยท permalinks at head 96c48d50, removed code at base 68bd259c

Before
Under the barrier, a snapshot ran its checks, the recovery-state build and the TQ capture one after another. Gym's check and RL's check each listed the staging partition, with every key's tags.
This PR
Starts all four phases together, builds the recovery state in a worker thread, lists keys without their tags, and lists the staging partition once for both checks.
Status
Speedup measured: 15.21 s โ†’ 9.84 s hold (CPU, 131k rollouts). One error-handling bug in the new code is open in the review; see the second page.

Two pages on this PR. This one: why the hold got shorter.

Background. A rollout snapshot saves in-flight rollouts so a crashed run can resume them. While it captures state, it holds the data-plane barrier, so every rollout waits. The time spent under it is the hold. Staging keys are listed to check that every row the saved state points at still exists. A TQ capture copies TransferQueue's state into memory while the barrier is held, so the slow disk write can happen after rollouts resume. The copy (the "view") stays in the storage actors' memory until it is written and released. Dotted words have a short explanation: hover or tap them.

Why it should be faster. Three changes. (1) The ~9 s recovery-state build moves to a thread, so the listings and the capture happen while it runs. (2) The new nrl_list_keys returns keys only, not every key's tags: 4.84 s โ†’ 1.02 s at 2.6M keys. (3) Staging is listed once, and Gym's check reuses that listing.

What does not get faster. The build itself (still ~9 s, now the floor of the hold). The listings and the controller capture are calls on one TQ controller actor that runs one call at a time, so they still wait for each other there. The benchmark does not include Gym's check, so the third change is not in the numbers.

Under the barrier: one after another, then side by side

Before (#5139): one after another, on the controller event loop replay recovery-state build โ‰ˆ 9 s staging check, tags 4.84 s TQ capture one lane hold 15.21 s (+ Gym's own staging listing with tags, not in the benchmark) After (this PR): four phases start together worker thread recovery-state build โ‰ˆ 9 s TQ controller (one call at a time) replay keys ยท staging keys 1.02 s ยท controller capture storage units retain shard views event loop Gym's check, then RL's check, on the one staging listing hold 9.84 s โ‰ˆ the build build TQ work, before TQ work, after

Widths use 50 px per second where the PR measured a number (build, staging listing, totals). Small boxes are not to scale.

The change, as pseudocode

capture(), before

# controller event loop, barrier held
env.check_against_cut(cut)      # Gym lists staging itself, with tags
await check_replay()             # KV_LIST, with tags
state = build_recovery_state()  # ~9 s, on the loop
await check_staging()            # lists staging again, with tags
view = await tq_capture()       # retain a TQ view

capture(), after

# controller event loop, barrier held
env.check_against_cut(cut)
phases = {
  "replay_inventory":  check_replay(),              # keys only
  "recovery_state":    to_thread(build_recovery_state),  # maps copied first, on the loop
  "staging_inventory": check_staging(env),          # list once; Gym check, then RL check
  "tq_capture":        tq_capture(),
}
results = await run_capture_phases(phases)  # all start now; on failure, release the view

Real code: capture, _run_capture_phases, list_staging_keys, list_sample_ids.

So what. With the build in a thread, the hold is set by the slowest phase instead of the sum, so 15.2 s became 9.8 s. The next floor is the ~9 s build, which #5185 roughly halves. Once it does, the controller calls that still run one at a time decide the hold. Running phases side by side also means a failure in one can meet a failure in another; page 2 shows the one case the new error handling gets wrong.