Repository navigation
Fix uneven shard distribution in StorageCache::shardIndex - #99384
Conversation
|
Workflow [PR], commit [534e1e5] Summary: ❌
AI ReviewSummaryThis PR correctly fixes Final Verdict
|
`& (NumShards - 1)` is only a correct modulo when `NumShards` is a power of two. With `NumShards == 6`, the bitmask is `5 == 0b101`, so only bits 0 and 2 can be set in the result. The possible shard indices are 0, 1, 4, 5 — shards 2 and 3 are never selected, making 2 out of 6 shards permanently empty and concentrating all load onto the other four. Fix by using `% NumShards` instead. Follow-up to #97411. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
54a9d27 to
a173407
Compare
|
cc @scanhex12 |
|
@groeneai, check the failed CI tests; they seem to be unrelated. Do we need to fix them in a separate pull request, or are they already fixed, and we just need to merge the master branch? |
|
@serxa — checked. Both failing checks are 100% chronic infrastructure flake unrelated to your one-line Failing checks on
|
| # | Check | Test | Pattern |
|---|---|---|---|
| 1 | Unit tests (asan_ubsan, function_prop_fuzzer) |
FunctionsStress.stress |
1 threads got stuck |
| 2 | Unit tests (tsan, function_prop_fuzzer) |
FunctionsStress.stress |
1 threads got stuck |
Both fail at src/Functions/tests/gtest_functions_stress.cpp:2270 with failure_details.empty() — Actual: false / Expected: true. Confirmed via CIDB on this exact head SHA.
Root cause (new chronic regression, not your PR)
- 2026-05-11 14:55:17 UTC — PR #103982 merges, converting the
prev.thread_id == curr.thread_idchassert inRUsageCountersto a gtest check that surfaces stuck-worker failures. - 2026-05-11 15:18:32 UTC — first
FunctionsStress.stress / threads got stuckfailure ever recorded. - Your CI run hits at 17:59–18:04 UTC — squarely inside the regression window.
- Underlying culprit: pathological-loop behavior in
isProbablePrime(PR #104234). Worker threads hit Miller-Rabin with adversarial inputs and don't return; previously masked by the chassert path, now caught by the threads-stuck detection.
CIDB evidence (30 days, signature FunctionsStress.stress + "threads got stuck")
| master | PR | unique PRs | first seen | last seen | |
|---|---|---|---|---|---|
| All sanitizers | 7 | 79 | 50 | 2026-05-11 15:18 | 2026-05-12 09:09 |
Spread across 50 unrelated PRs across all 3 sanitizer variants (asan_ubsan / tsan / msan) — unambiguous chronic infrastructure flake.
Fix in flight (no action needed from you)
- PR #104633 by @alexey-milovidov — "Make
isProbablePrimecancellable and caproundsto 256" — targeted fix for the pathological-loop trigger. - PR #104639 — companion re-introduction of
isPrime/isProbablePrimeafter PR MakeisProbablePrimecancellable and caproundsto 256 #104633 lands.
Recommendation
Merge master once #104633 lands, then re-run the two unit-test checks. Your diff (one-line & (NumShards - 1) → % NumShards in StorageCache::shardIndex) has zero interaction with FunctionsStress / Functions/isPrime.cpp / RUsageCounters. The PR is otherwise green and approved.
If you'd prefer not to wait, re-running the two checks alone should also work — the failure rate is high but not deterministic (each individual re-run has a chance of passing).
LLVM Coverage Report
Changed lines: 100.00% (1/1) · Uncovered code |
Fixes incorrect shard selection introduced in #97411.
StorageCache::shardIndexused& (NumShards - 1)to map a hash to a shard. This is only a correct modulo whenNumShardsis a power of two. WithNumShards == 6, the bitmask is5 == 0b101, so only bits 0 and 2 can be set in the result. The only possible shard indices are 0, 1, 4, 5 — shards 2 and 3 are never selected, making 2 out of 6 shards permanently empty and concentrating all lock contention onto the other four.Fixed by using
% NumShardsinstead, which is correct for any value ofNumShards.Changelog category (leave one):
Note
Low Risk
Low risk, localized change that replaces an incorrect bitmask with modulo to ensure shard indices stay within the
shardsarray bounds.Overview
Fixes a potential out-of-bounds access in
ContextData::StorageCache::shardIndexby switching from a bitmask (& (NumShards - 1)) to% NumShards, which correctly maps hashes to valid shard indices even whenNumShardsis not a power of two.Written by Cursor Bugbot for commit a173407. This will update automatically on new commits. Configure here.