Repository navigation
Fix flaky UniqueKeyIndexCache.InsertLookupAndHitMissCounters - #106839
Merged
azat merged 1 commit intoJun 9, 2026
Merged
Conversation
The test read hit/miss deltas from `ProfileEvents::global_counters`, but `ProfileEvents::increment` (called inside `UniqueKeyIndexCache::Lookup`) routes through `CurrentThread::getProfileEvents`, which returns `global_counters` only when no `ThreadStatus` is attached to the current thread. All gtests in `unit_tests_dbms` run on one main thread, and some tests attach a `ThreadStatus` to it that persists for the rest of the binary (e.g. `gtest_filecache` sets `current_thread = MainThreadStatus::get()`). Once that has happened, the increments land in that thread's `current_performance_counters` subtree, which does not propagate to `global_counters`, so the deltas read 0 instead of 1. Whether it happens depends on gtest execution order, and CI runs with `--gtest_shuffle`, hence the flakiness. Read the deltas from `CurrentThread::getProfileEvents` instead - the exact `Counters` object the increment targets - so the assertion is correct whether or not a `ThreadStatus` is attached. This also makes the previous `WITH_COVERAGE` special case unnecessary, so it is removed. Co-Authored-By: Claude <[email protected]>
1 task
Contributor
|
Workflow [PR], commit [6e944d4] Summary: ✅
AI ReviewSummaryThis PR fixes the flaky Final VerdictStatus: ✅ Approve |
kssenii
approved these changes
Jun 9, 2026
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 12/12 (100.00%) | Lost baseline coverage: none · Uncovered code Newly covered by added/modified tests: 412 line(s), 43 function(s) across 118 file(s) · Details Top files
|
1 task
pull Bot
pushed a commit
to CrazyForks/ClickHouse
that referenced
this pull request
Jun 11, 2026
ConnectionPoolTest::SetUp and ResolvePoolTest::SetUp called CurrentThread::getProfileEvents().reset(), which does setParent(nullptr) — once any earlier test attaches a ThreadStatus to the gtest main thread, this permanently unlinks the thread's counters from ProfileEvents::global_counters. Use resetCounters instead, which zeroes values but keeps the parent chain intact. Related: ClickHouse#106839 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Caused by: #104282
Fixes the flaky test
UniqueKeyIndexCache.InsertLookupAndHitMissCounters.Root cause
The test reads hit/miss deltas from
ProfileEvents::global_counters, butProfileEvents::increment(called insideUniqueKeyIndexCache::Lookup) routes throughCurrentThread::getProfileEvents:return current_thread ? *current_thread->current_performance_counters : ProfileEvents::global_counters;The increment reaches
global_countersonly when noThreadStatusis attached to the current thread.All gtests in
unit_tests_dbmsrun on a single main thread, and some tests attach aThreadStatusto it that persists for the rest of the binary - for examplegtest_filecachesetscurrent_thread = MainThreadStatus::get()and never clears it. Once that has happened, theUniqueKeyIndexCacheincrements land in that thread'scurrent_performance_counterssubtree, which does not propagate toglobal_counters, so the deltas the test reads are0instead of1and the assertions fail.Whether this happens depends purely on gtest execution order, and CI runs with
--gtest_shuffle, which is why the failure is flaky. The pre-existingWITH_COVERAGEguard in the test was a partial workaround for the same underlying issue (coverage builds always set up a thread-local subtree).Fix
Read the deltas from
CurrentThread::getProfileEvents- the exactCountersobject the increment targets - so the assertion is correct whether or not aThreadStatusis attached to the main thread. This also makes theWITH_COVERAGEspecial case unnecessary, so it is removed.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
Version info
26.6.1.573