Repository navigation
Fix StringValueFilter turning itself off when several threads update its statistics at once - #128277
Conversation
…atistics at once `updateStatsImpl` added a batch to `values_checked` and then to `values_replaced` with two independent relaxed `fetch_add`s and used the returned totals as a consistent pair. When two row-group decoders update at the same time, one can see the other's `checked` without its `replaced` (e.g. 7372 * 2 < 16384) and disable the filter for the rest of the query. That is what makes `05339_string_filters_parquet_delta_length_byte_array` report `StringValueFilterValuesChecked: 24576` or `26384` instead of `30000` (exact multiples of the 8192-value update batches) on ARM CI lanes. `updateStatsOfIndividualChecks` had the same race on the `values_checked_individually` / `bytes_skipped_individually` pair. Add the dependent counter first, the count with `acq_rel`, and re-read the dependent counter afterwards. All modifications of the count are RMWs, so an updater whose RMW includes a batch synchronizes with that batch's update and its later load of the dependent counter includes it. The dependent total can only run ahead of the count, which errs towards keeping the filter enabled until the next update. Query results are unaffected either way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the two-line ordering comment in updateStatsImpl to one invariant line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings; bounded: 1 full pass).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261030-182700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261030-180000 |
|
cc @alexey-milovidov @scanhex12, could you review this and add the |
|
Workflow [PR], commit [a162313] Summary: ✅
AI ReviewSummaryThis PR fixes concurrent statistics updates that could spuriously disable Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline. |
The merge queue fast-forwards master over up to 5 merges in one push and
MasterCI runs once, for the push head. For a push, praktika read the changed
files of the head commit only (`gh api commits/{sha}`), so a job affected
only by an earlier commit of the same push was filtered as "Not affected by
the changed files and not required", and functional/integration shards
skipped themselves as "Only test files changed". At master c189bd9 (ClickHouse#128277
in `src/` + ClickHouse#128142 tests only) this skipped 95 jobs, including both
`Build (*_release_performance_reference)`, so PR performance runs based on it
fell back to the official build (`long_primary_key` +16% on amd, ClickHouse#127846).
At f760cbb all 32 builds were skipped.
Now a push event records its `before` (`_Environment.PUSH_BEFORE_SHA`), and
`GH.get_changed_file_statuses` walks first parents from the head down to it,
reading all pages of each commit's file list (`gh api --paginate`), and
unions them (the newest commit's status wins). If the files cannot all be
known - an all-zero or malformed `before` (created branch), a failed or
malformed read, a commit at GitHub's 3000-file listing limit, a walk that
does not reach `before` within 50 commits - the result is `None` with a
warning, never a partial list, and it is not cached. `store_data.py` keeps
`None` for push events, so no job is filtered by it (`Job.is_affected_by`);
before, a failed read stored `[]`, which filtered every non-required job.
Without `before` (local runs, the native orchestrator) the head-only read
is unchanged; PR, merge queue, schedule and dispatch are unchanged.
Validated locally against the real GitHub API by replaying the 404 batched
master pushes of October: the result equals the union of every pushed
commit's files (re-parsed independently, commit lists from git) on 402, and
is unknown on the 2 that contain a 3000-file commit (ClickHouse#126194, and the docs
translation ClickHouse#124860); the job filter keeps 14,871 more job-runs on 131
pushes, plus 952 test shards that self-skipped now run in full, ~+7.8% of
October's 203,420 master job-runs, including both reference builds on 106
pushes. 100 single-commit pushes give identical statuses, with one request
for heads of up to 100 files.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
05339_string_filters_parquet_delta_length_byte_array(added in #124521) sometimes reportsStringValueFilterValuesChecked: 24576or26384instead of30000, while the query result stays correct: #127845, #111218.The filter object is shared by all readers of a column.
updateStatsImpladded a batch tovalues_checkedand then tovalues_replacedwith two independent relaxedfetch_adds, and used the two results as a consistent pair. When two row groups update at the same time, one thread can see the other'scheckedwithout itsreplaced(7372 * 2 < 16384), so it disables the filter for the rest of the query. The CI numbers are exact multiples of the 8192-value update batches.updateStatsOfIndividualCheckshad the same race on the bytes-skipped pair.Now the dependent counter is added first, the count with
acq_rel, and the dependent counter is re-read afterwards, so it always covers every batch included in the count. Only the moment the optimization switches off changes; results are unaffected.Validation: with a temporary 200 ms sleep inside the race window, the base build undercounts in 10/10 runs (9 with the exact CI numbers), and the fix gives
30000 / 27000in 90/90 runs with the sleep in each window of the new code. Without any sleep, 16 parallel loops on x86 undercount 4 times in 4163 base runs and 0 times in 4485 fixed runs. Thestring_filterstest family passes.Workflow [PR]
Sync PR [sync-upstream/pr/128277]
Version info
26.11.1.998-master(included in26.11and later)