Skip to content

Fix flaky test test_dictionaries_postgresql::test_invalidate_query - #109390

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-test-invalidate-query-postgresql
Jul 5, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-test-invalidate-query-postgresql

Conversation

@groeneai

@groeneai groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Related: #109367

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

Fixes flaky test_dictionaries_postgresql/test.py::test_invalidate_query, reported by @serxa on PR #109367.

Where it was seen: the failure is not caused by #109367 (Scheduler-only change). It reproduces across 8 unrelated PRs in 30 days, 0 times on master, almost always on slow builds (amd_asan_ubsan, db disk, old analyzer and amd_msan). Example failing run: Integration tests (amd_asan_ubsan, db disk, old analyzer, 1/6) on #109367. Assertion: test.py:385 AssertionError: assert '2\n' == '1\n'.

Root cause. dict0 is a config-based PostgreSQL dictionary with LIFETIME(1) and an invalidate_query. SYSTEM RELOAD DICTIONARY does a forced full reload but does not run the invalidate query, so the stored invalidate response is left empty. The first periodic check after the forced reload therefore always sees a "modified" source (empty stored response vs the real value) and reloads once more. If that follow-up reload lands after the test has changed the other rows (value * 2 WHERE id != 0), the dictionary picks up value = 2 for id = 1 and the "no update should happen" assertion fails. The periodic check runs every 5s, so on slow sanitizer / old-analyzer builds it lines up with the fixed sleep(5) window often enough to fail.

This is a test timing issue, not a product bug: a forced reload must fully reload, and invalidate_query is a best-effort optimization (an extra reload returns fresher data, never wrong data).

Fix. After each reload, wait for the invalidate baseline to settle (last_successful_update_time stops advancing across a full check period), which drains the guaranteed post-forced-reload reload before the assertion. The "no update should happen" case is then verified directly by asserting last_successful_update_time does not advance. The original intent is preserved: a change to the invalidate row (id = 0) still triggers a reload, and a change to other rows still does not.

Verified locally on a debug build: reproduced the spurious reload deterministically without the settle step and confirmed it disappears with it; test_invalidate_query then passed 25/25 runs and the full test_dictionaries_postgresql/test.py suite passed with no regressions.

The test drives dict0, a config-based PostgreSQL dictionary with
LIFETIME(1) and an invalidate_query, and asserts that changing a row
other than the invalidate row (id != 0) does not reload the dictionary.

SYSTEM RELOAD DICTIONARY performs a forced full reload but does not run
the invalidate query, so the stored invalidate response is left empty.
The first periodic check after the forced reload therefore always sees a
"modified" source and reloads once more. If that follow-up reload lands
after the test has changed the other rows (value * 2 WHERE id != 0), the
dictionary picks up value 2 for id = 1 and the "no update should happen"
assertion fails with '2' == '1'. On slow sanitizer / old-analyzer runs
the periodic check (every 5s) lines up with the fixed sleep(5) window
often enough to fail intermittently. It never fails on master.

Wait for the invalidate baseline to settle (last_successful_update_time
stops advancing across a full check period) after each reload, and verify
the "no update" case directly by asserting last_successful_update_time
does not advance. This drains the guaranteed post-forced-reload reload
before the assertion and keeps the original intent: a change to the
invalidate row triggers a reload, a change to other rows does not.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Immediately after SYSTEM RELOAD DICTIONARY dict0, commit value*2 WHERE id!=0 and poll system.dictionaries.last_successful_update_time: it advances (a reload fires) and dictGet(value,1) becomes 2 within ~5s, despite the invalidate value at id=0 being unchanged. Reproduced on demand.
b Root cause explained? SYSTEM RELOAD is a forced reload (previous_version=nullptr -> createObject), which does a full loadAll but never calls doInvalidateQuery, so invalidate_query_response stays empty. The first periodic isModified after it compares empty stored vs the real invalidate value -> reports modified -> one extra reload. If that reload lands after value*2 WHERE id!=0 is committed, it picks up value 2 for id=1. check_period_sec=5 lines this up with the test's fixed sleep(5).
c Fix matches root cause? Yes. Wait for the invalidate baseline to settle (last_successful_update_time stops advancing across a full check period) after each reload, which drains that guaranteed post-forced-reload reload before the "no update" assertion.
d Test intent preserved / new tests added? Yes. Still verifies both directions: a change to the invalidate row (id=0) triggers a reload; a change to other rows does not. The "no update" case is now checked directly via last_successful_update_time not advancing (stronger than the previous value-only check).
e Both directions demonstrated? Yes. Without the settle step: last_successful_update_time advances (:26 -> :31) and value(1)=2 (bug). With the settle step: it stays (:36 -> :36) and value(1)=1 (fixed).
f Fix is general across code paths? N/A (test-only fix, not a code bug).
g Fix generalizes across inputs? N/A (test-only fix, not a code bug).
h Backward compatible? N/A (test-only fix, not a code bug).
i Invariants and contracts preserved? N/A (test-only fix, not a code bug).

Verification: reproduced deterministically both directions; test_invalidate_query then passed 25/25 runs on a debug build and the full test_dictionaries_postgresql/test.py suite passed with no regressions.

Session id: cron:clickhouse-worker-slot-4:20260704-032300

@groeneai

groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @vdimir - could you review? Small test-only fix for the flaky test_dictionaries_postgresql::test_invalidate_query: after SYSTEM RELOAD (which does not run the invalidate query) the first periodic check always reloads once more, and on slow builds that reload lands inside the test's fixed sleep window and picks up an unrelated row change. The fix waits for the invalidate baseline to settle before the "no update" assertion.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [01abbd0]

Summary: ✅


AI Review

Summary

This PR makes test_dictionaries_postgresql::test_invalidate_query wait for the post-SYSTEM RELOAD DICTIONARY invalidate baseline to settle before asserting the negative case. I did not find a correctness issue in the current diff: the new synchronization matches ExternalLoader's 5-second periodic updater and the PostgreSQL dictionary source behavior described in the PR.

Missing context / blind spots
  • ⚠️ The current Praktika report for PR #109390 was still empty, so I could not confirm the timing behavior against fresh CI logs. A passing integration run for test_dictionaries_postgresql::test_invalidate_query would close this gap.
Final Verdict

✅ No blockers found in the current diff.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.92% 85.96% +0.05%
Functions 91.48% 91.48% +0.00%
Branches 78.47% 78.52% +0.05%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 326 line(s), 27 function(s) across 16 file(s) · Details

Top files
  • src/Databases/DataLake/PaimonRestCatalog.cpp: 234 line(s), 17 function(s)
  • src/Databases/DataLake/DatabaseDataLake.cpp: 30 line(s)
  • src/Common/ZooKeeper/ZooKeeperImpl.cpp: 15 line(s)
  • src/Storages/ObjectStorage/DataLakes/Paimon/PaimonMetadata.cpp: 11 line(s)
  • src/Databases/DataLake/PaimonRestCatalog.h: 8 line(s), 5 function(s)

Full report

@groeneai

groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 01abbd0

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
(none) CI fully finished, 0 FAIL/ERROR test rows all 44 executed checks pass; heavy matrix skipped by design (test-only integration change)

No failed checks on this commit. CH Inc sync = pass. This PR is the test-only fix for the flaky test_dictionaries_postgresql::test_invalidate_query (@serxa directive on #109367).

Session id: cron:our-pr-ci-monitor:20260704-193000

@alexey-milovidov alexey-milovidov self-assigned this Jul 5, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 5, 2026
Merged via the queue into ClickHouse:master with commit 1417799 Jul 5, 2026
175 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 5, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-test-invalidate-query-postgresql

Fix flaky test test_dictionaries_postgresql::test_invalidate_query
@groeneai

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov could you apply v26.6-must-backport to this PR? 26.6 still runs the pre-fix version of this test and hit the same assertion today.

Failing run: Integration tests (amd_asan_ubsan, db disk, 3/6) on 26.6 at 40676b3adce1d211241574c55a190b373395d43d, 2026-09-14 05:15 UTC, test.py:385 AssertionError: assert '2\n' == '1\n', which is the # no update should happen block this PR deletes. Report

Why the pick is trivial:

  • 26.6's tests/integration/test_dictionaries_postgresql/test.py is blob 0fdf534d9bed, byte-identical to this PR's pre-image, both at the branch tip and at the failing sha. A three-way merge of this PR onto it is conflict-free and the result is byte-identical to master's 44b669006efb.
  • assert_eq_with_retry, the only import this PR adds, is already in tests/integration/helpers/test_tools.py on 26.6, same blob as master.
  • master's blob still equals this PR's post-image, so nothing has to ride along.

Where the fix is present there are no failures in 90 days: master 0/12924 runs, 26.7 0/867, 26.8 0/481. Where it is absent: 26.6 1/1194, and 26.5 had 2 before it retired.

One label is enough. 26.7 and 26.8 already contain the merge commit, so pre_check skips them. 26.3 also lacks the fix, but it never runs the flavours that have produced this failure (amd_asan_ubsan, amd_msan); it only runs amd_asan and amd_tsan for this test, 453 runs in 30 days, 0 failures. So I am not asking for 26.3.

This is test-only CI noise, so it is low priority. If you would rather leave 26.6 as it is, that is fine, just say so and I will close it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants