Repository navigation
Do not assert scan-progress values decided by an async race in test_early_return_limit - #115693
Conversation
…arly_return_limit
test_storage_delta/test.py::test_early_return_limit pinned two quantities that a
producer/consumer interleaving decides, so both legal interleavings had to be
accepted but only one was.
The DeltaLake scan runs a producer thread that appends to a bounded deque and
logs the LIVE queue depth ("List batch size is {}/{}"). Consumers pop from the
same deque under the same mutex. With s3_list_object_keys_size = 1 the capacity
is one element, so the producer's last log legitimately reads 1/1 or 0/1
depending on which thread reaches the mutex first. The scanned-file counter is
incremented after both callback shutdown exits, so it is 2 or 3 for the same
reason. The master failure and the reproduction both show the drained ordering.
Two changes:
- Remove the assertion that counted "List batch size is 1/1, shutdown: true".
It is implied by the assertion three lines above it, which runs first: a
callback that observes shutdown returns false from the row callback, the
kernel turns that into Ok(()) and the FFI visitor discards it, so the producer
always reaches the batch log afterwards, and shutdown is a monotone latch.
So first_check_hits > 0 or queue_check_hits > 0 already covers it, records
which shutdown path fired, and is free of the race.
- Restore the scanned-files assertion to an upper bound. It was an upper bound
(< 10) when the test was written and was tightened to == 3 six days later;
the bound shape is what the async scan permits, so keep the tighter constant
as <= 3. The existing assert scanned_files > 0 is the lower bound.
Validated with a forced-interleaving probe in the scan callback: unpatched fails
with the CI signature, patched passes on the same drained ordering; deleting both
callback shutdown exits makes the patched test fail at "assert 997 <= 3", so the
retained bound still catches an early-return regression; 20 consecutive runs pass.
Internal second-model review (click to expand)An independent cold review plus a second-model pass ran over this diff before it was opened,
Also checked and found sound, so nothing was changed: the implication argument the first One residual is disclosed rather than acted on: the retained |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260820-221000 |
|
Workflow [PR], commit [651c898] Summary: ✅ AI ReviewSummaryThis PR removes one race-sensitive log assertion and relaxes the exact scanned-file count in Findings
Final VerdictChanges requested. |
|
cc @SmitaRKulkarni, could you review this? It is test-only: two assertions in test_early_return_limit pinned values that the DeltaLake scan's producer/consumer interleaving decides (the logged queue depth is read live, and DeltaLakeScannedFiles is incremented after both callback shutdown exits), so both legal orderings had to be accepted but only one was. |
| @@ -5358,24 +5358,16 @@ def test_early_return_limit(started_cluster, use_delta_kernel): | |||
|
|
|||
| assert first_check_hits > 0 or queue_check_hits > 0 | |||
There was a problem hiding this comment.
first_check_hits > 0 or queue_check_hits > 0 still assumes shutdown is observed inside scanCallbackImpl, but the current read path does not guarantee that. StorageObjectStorageSource::lazyInitialize creates the first reader and immediately starts reader_future, so TableSnapshot::Iterator::next can pop two files before the first row reaches LIMIT 1 (src/Storages/ObjectStorage/StorageObjectStorageSource.cpp:526-530, src/Storages/ObjectStorage/DataLakes/DeltaLake/TableSnapshot.cpp:397-401). With s3_list_object_keys_size = 1, the producer can then enqueue a third file and block in its own schedule_next_batch_cv.wait after the List batch size log (src/Storages/ObjectStorage/DataLakes/DeltaLake/TableSnapshot.cpp:293-304). If LIMIT cancels there, shutdown only wakes scanDataFunc; it never forces another callback invocation, so both counters remain zero even though early return worked correctly. That leaves this test flaky on a different legal interleaving. I think this log-based assertion needs to be removed as well, or replaced with an invariant that does not depend on which callback site sees shutdown.
There was a problem hiding this comment.
Mechanism confirmed, and the citations check out (lazyInitialize is at
StorageObjectStorageSource.cpp:521-533, one hop from your :526-530). Both counters are logged
inside scanCallbackImpl, the callback only runs from scan_metadata_next at
TableSnapshot.cpp:288, and the producer's park at :300-304 sits outside it, so on wake the
while (!shutdown.load()) guard at :285 exits without another callback invocation and neither
counter is incremented. The PR body now says this instead of claiming the retained assertion is
race-free.
Not removing it here, because the numbers point the other way. Over 90 days this test has 97538 OK
and 38 FAIL rows in the CI database: the assertion this PR deletes accounts for 5 of the 38, the one
you point at for 0. Trading a 5-hit oracle for a 0-hit one is the value of the change, and deleting
both would leave scanned_files <= 3 as the only check of the early-return path.
On a site-independent invariant, I do not have one I trust. Set finished is asserted nowhere and is
logged only when the iterator is exhausted, which a LIMIT 1 early return does not reach. Any
replacement also has to avoid reducing to something an earlier assertion already implies, which is
the defect being removed here. That needs a DeltaLake reviewer's view on what the scan guarantees,
so it is wider than this fix.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
| f"Early return should scan 3 files with LIMIT 1, but scanned {scanned_files}" | ||
| # At most 3: two async readers each consume one file, plus one the scan produces before | ||
| # it observes shutdown. Fewer is legal when shutdown lands earlier. | ||
| assert scanned_files <= 3, \ |
There was a problem hiding this comment.
@kssenii it looks like you modified this test last, can you take a quick look to make sure this change is OK? Feel free to assign yourself.
bbe1698
|
This fix never reached the live release branches, and on 2026-09-24 the race it removes reddened a The failing job: actions/runs/36069906831/job/107873053411, The two assertions deleted here are still present on Old versus new, over 90 days of CI history: on the branches that still carry the assertion, 1 failure in 3,706 runs of this test, or 1 in 1,177 counting only the The diff is one test file, and it applies to @PedroTadim would you add |
Backport #115693 to 26.7: Do not assert scan-progress values decided by an async race in test_early_return_limit
Backport #115693 to 26.8: Do not assert scan-progress values decided by an async race in test_early_return_limit
…s decided by an async race in test_early_return_limit
…s decided by an async race in test_early_return_limit
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Closes: #115661
test_storage_delta/test.py::test_early_return_limitpins two values an async interleavingdecides. 5 hits in 90 days across three job families, two on master, so not
parametrization-specific. Latest master failure:
Integration tests (arm_binary, distributed plan, 1/4)@ 0c80ff614e89Root cause: the scan producer appends to a bounded deque and logs the LIVE queue depth
(
List batch size is {}/{}); consumers pop under the same mutex. Withs3_list_object_keys_size = 1the capacity is one, so the last log legitimately reads1/1or
0/1depending on which thread reaches the mutex first.DeltaLakeScannedFilesisincremented after both callback shutdown exits, so the count is 2 or 3 for the same reason.
Both orderings are correct.
Two test-only changes:
List batch size is 1/1, shutdown: trueis removed, notrelaxed: even relaxed it is implied by
assert first_check_hits > 0 or queue_check_hits > 0three lines above, which runs first. A callback returning falsecannot stop the producer reaching that batch log.
assert scanned_files == 3becomes<= 3, restoring the bound the test was writtenwith:
a33799ba6fb63eeaddedscanned_files < 10;95e6f488a0917b("Make exactcomparison in test") tightened it to
== 3days later.scanned_files > 0bounds theother side.
Validated with a forced-interleaving probe in the scan callback: unpatched fails with the CI
signature on the drained ordering, patched passes on it. Deleting both callback shutdown exits
makes it fail at
assert 997 <= 3, so the bound still catches an early-return regression.20/20 runs pass.
The retained assertion is not race-proof either: both counters are logged inside the callback,
so a shutdown seen by the parked producer skips it. That ordering has 0 of 38 failures in 90
days over 97538 runs, against 5 for the one removed here.
Workflow [PR]
Sync PR [sync-upstream/pr/115693]
Version info
26.9.1.39-master(included in26.9and later)26.8.11.45,26.7.14.45