Commit 2f42265
fast_slow_store: has_with_results consults fast store and in-flight slow writes (#2343)
* fast_slow_store: make has_with_results aware of fast store and in-flight slow writes
`FastSlowStore::has_with_results` previously only consulted the slow store,
which caused two known bugs:
1. Fast-only writes (and the brief window between fast-store insert and
slow-store write start) were invisible — callers got NotFound for blobs
that were locally present, triggering redundant fetches.
2. Concurrent writers racing on the same digest could not see each other's
in-flight slow-store writes, so the second writer re-uploaded what the
first had nearly finished pushing.
The fix layers three consultations in order: slow store first (authoritative
for downstream consumers), then a `in_flight_slow_writes: Mutex<HashMap>`
tracking active slow writes, then fast store as a final fallback for
fast-only / pre-slow-write hits.
In-flight tracking uses a cancel-safe RAII guard (`InFlightSlowWriteGuard`)
registered at the start of each `update`/`update_with_whole_file` path that
writes to the slow store, so a cancelled write future correctly removes
itself from the map on Drop.
Tests cover all four reachable cases: slow-hit short-circuit, fast-only
hit, in-flight slow write visibility, and noop-slow-store fall-through.
Provenance: equivalent to upstream commits f69aaf8 and 2d770d9 from
TraceMachina/nativelink PR #2243, ported atomically to current main.
* fast_slow_store_test: add cancel-safety and mixed-key has_with_results tests
The previous commit added tests for the four reachable cases of the
fast/slow/in-flight has() lookup, but two correctness properties were
asserted only indirectly:
1. Cancel safety of `InFlightSlowWriteGuard`. The fix's central claim
is that aborting an in-progress update() removes the key from the
in_flight_slow_writes map via Drop. The previous in-flight test
only verified the happy-path (writer completes normally) and the
fast-store fallback masked any leak.
2. Per-key independence in batched has_with_results. With multiple
keys spanning different storage tiers, an off-by-one in the
missing_indices fallback or an over-broad in-flight match would
silently corrupt results without any existing test noticing.
New tests:
* dropping_update_future_cleans_up_in_flight_entry: uses a
gated-slow-store with NoopStore as fast (so the fast-store fallback
cannot mask a leak), spawns a writer, waits on a oneshot started
signal, aborts the writer mid-update, then asserts has() returns
None — proving the guard's Drop ran.
* has_with_results_handles_mixed_key_sources: builds a request with
four keys — slow-only, in-flight, fast-only, and missing — and
asserts each result independently matches its source. Catches
index-mapping regressions in the batched fallback path.
Both tests are deterministic (oneshot channels, no sleeps). Verified
that reverting the fix in fast_slow_store.rs causes both new tests
plus the existing has_sees_in_flight_slow_writes and
fast_store_only_value_is_reported_by_has to fail.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fmt: apply rustfmt to nativelink-store
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fast_slow_store_test: address clippy items_after_statements and cast_possible_truncation
Hoist the `MapBackedSlow` test helper (struct, StoreDriver impl, and
`default_health_status_indicator!` macro invocation) out of
`has_with_results_handles_mixed_key_sources` to module scope so that
items are declared before statements, satisfying
`clippy::items_after_statements`.
Replace `as usize` casts of the per-key `u64` sizes with
`usize::try_from(...).unwrap()` to satisfy
`clippy::cast_possible_truncation`, matching the existing conversion
pattern elsewhere in this test file.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* ci: retrigger after GitHub 502 fetching hermetic_cc_toolchain tarball
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Marcus Eagan <marcuseagan@gmail.com>1 parent 2410a08 commit 2f42265
2 files changed
Lines changed: 681 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
68 | 74 | | |
69 | 75 | | |
70 | 76 | | |
| |||
91 | 97 | | |
92 | 98 | | |
93 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
94 | 121 | | |
95 | 122 | | |
96 | 123 | | |
| |||
126 | 153 | | |
127 | 154 | | |
128 | 155 | | |
| 156 | + | |
129 | 157 | | |
130 | 158 | | |
131 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
132 | 190 | | |
133 | 191 | | |
134 | 192 | | |
| |||
365 | 423 | | |
366 | 424 | | |
367 | 425 | | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
373 | 475 | | |
374 | 476 | | |
375 | 477 | | |
| |||
405 | 507 | | |
406 | 508 | | |
407 | 509 | | |
| 510 | + | |
| 511 | + | |
408 | 512 | | |
409 | 513 | | |
410 | 514 | | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
411 | 518 | | |
412 | 519 | | |
413 | 520 | | |
| |||
549 | 656 | | |
550 | 657 | | |
551 | 658 | | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
552 | 663 | | |
553 | 664 | | |
554 | 665 | | |
| |||
598 | 709 | | |
599 | 710 | | |
600 | 711 | | |
| 712 | + | |
| 713 | + | |
601 | 714 | | |
602 | 715 | | |
603 | 716 | | |
| |||
0 commit comments