Skip to content

Backport #111103 to 26.5: Cache deduplication data hashes before the Alias hop - #112722

Merged
alexey-milovidov merged 2 commits into
26.5from
backport/26.5/111103
Aug 1, 2026
Merged

alexey-milovidov merged 2 commits into
26.5from
backport/26.5/111103

Conversation

@robot-clickhouse-ci-1

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #111103
Cherry-pick pull-request #112583

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 26.5.6.102

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default labels Jul 31, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [066e5c4]

Summary: ✅

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112722&sha=21ba2dbcf7a5d9e1a4f1e1357677f5429f121040&name_0=BackportPR&name_1=Integration%20tests%20%28amd_tsan%2C%203%2F6%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

The failure is unrelated to this backport (which only touches InsertDeduplication and StorageAlias). test_distributed_ddl/test.py::test_default_database[configs_secure] fails at cluster.shutdown with Sanitizer assert found for instance zoo3-1; the Keeper container's docker.log contains the known TSan report on NonblockingBoundedQueue<DB::KeeperResponseForSession>::tryPush vs tryPop:

WARNING: ThreadSanitizer: data race (pid=1)
  Read of size 8 ... DB::KeeperResponseForSession::operator=(DB::KeeperResponseForSession&&) src/Coordination/KeeperCommon.h:48
    NonblockingBoundedQueue<DB::KeeperResponseForSession>::tryPop(...) src/Common/NonblockingBoundedQueue.h:138
    DB::KeeperRequestDispatcher::responseThread() src/Coordination/KeeperRequestDispatcher.cpp:1095
  Previous write of size 8 ...
    NonblockingBoundedQueue<DB::KeeperResponseForSession>::tryPush(...) src/Common/NonblockingBoundedQueue.h:107
    DB::KeeperRequestDispatcher::onResponse(...) src/Coordination/KeeperRequestDispatcher.cpp:373

This is exactly what #112695 ("Fix the ineffective TSAN suppression in NonblockingBoundedQueue") fixed on master — the NO_SANITIZE_THREAD attribute added by #107083 never suppressed these reports, because the reported access happens in the element type's implicitly generated move assignment, which stays instrumented. That fix is not on 26.5, so every 26.5 backport pull request keeps hitting it in the TSan integration shards. Could you backport #112695 to 26.5 (and to the other affected release branches)? The change is a __tsan_default_suppressions entry plus the removal of the ineffective attributes, so it affects sanitizer builds only.

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

The fix on master is #112695 (merged 2026-07-31 16:57:30Z). No backport exists yet: it is labelled pr-ci with no *-must-backport label, so no robot backport was created, and there is no backport pull request or branch for it against any release branch. I will open them by hand.

The affected set is exactly 26.5, 26.6 and 26.7. The carrier needs src/Common/NonblockingBoundedQueue.h and src/Coordination/KeeperRequestDispatcher.cpp, and neither exists on 26.4 or older: the queue header arrives with 2bfce0838853d8 ("Add KeeperRequestDispatcher2, KeeperAppendStream, and NuRaft streaming"), which is on 26.5 and later only. So 26.4 and below are structurally immune. CIDB agrees: over 30 days of TSan integration runs, Sanitizer assert found for instance zoo* appears once on 26.5 (this pull request), once on 26.6, and zero times on 26.7, 26.4, 26.3 and 25.8. I read 26.7's zero as a sample-size artifact (58 builds) rather than immunity, since its carrier code is byte-identical to 26.6's.

One correction, and it makes the backport simpler than you described. #107083 is not on 26.5, 26.6 or 26.7 either: git merge-base --is-ancestor says no for all three, and NO_SANITIZE_THREAD in any spelling occurs 0 times in the queue header on each. The release branches have no suppression at all today, not an ineffective one, so the backport is purely additive, with no attributes to remove.

A straight cherry-pick does not apply. base/base/sanitizer_options.h does not exist on 26.5 (it lands on master with 097148c07a2bb0), so there the hook goes beside the existing __tsan_default_options in programs/main.cpp; 26.6 and 26.7 take the master shape. tryPush also takes T && on 26.5 against T & later, so the header comment adapts per branch. I checked that the patterns will bite: BUILD_STANDALONE_KEEPER is off in the TSan builds on all three, so clickhouse-keeper is the symlinked clickhouse binary, and the reported NonblockingBoundedQueue.h:107 and :138 land exactly on the two std::move payload lines in the 26.5 header.

Efficacy on master since the merge: 0 occurrences of that signature across 172 distinct TSan integration builds, against 15 in the 30 days before it.

I will open one pull request per branch for 26.5, 26.6 and 26.7 and link them here. Tell me if you would rather limit it to 26.5 and 26.6, where the signature is actually observed.

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

26.5 is open: #112899.

It is additive, as described above: the hook goes beside the existing __tsan_default_options in programs/main.cpp, because base/base/sanitizer_options.h does not exist on this branch, and nothing is removed. The suppression payload is byte-identical to master's.

What I verified before opening it, since the race itself is not reproducible on demand and the only end-to-end oracle is the TSan shards going quiet:

  • The binary carries exactly one strong __tsan_default_suppressions. Worth flagging for anyone repeating this: nm -C | grep -c reads 1 on the pristine branch too, because compiler-rt defines a weak fallback, so the discriminator is the symbol type letter, W before and a single T after.
  • The runtime really consumes the hook. Mangling the suppression category gives ThreadSanitizer: failed to parse suppressions and exit 134; reverting returns the Build ID to the verified value exactly.
  • Neither pattern is dead: each matches exactly one live tryPush symbol. 26.5 has just two instantiations of the queue, both in KeeperRequestDispatcher.
  • The hook reaches the zoo* process, which was the one way this could have been a silent no-op. BUILD_STANDALONE_KEEPER is off in the TSan build, so clickhouse-keeper is a symlink to the clickhouse binary built from main.cpp, and the integration harness takes a standalone binary only when it exists and is not a symlink.
  • Outside THREAD_SANITIZER the hook is preprocessed away: a non-sanitizer build of the same tree carries zero hook symbols and zero payload strings.

26.6 and 26.7 are still to come, one pull request each. Both take the master shape rather than 26.5's, since they do have base/base/sanitizer_options.h.

Your question about narrowing is still open and I have not assumed an answer. If you would rather stop at 26.5 and 26.6, say so and I will drop 26.7. My reason for including it is structural rather than statistical: its queue header is md5-identical to 26.6's, which does have an observed hit, and with 58 TSan integration builds against master's rate of roughly 0.191% per build, a zero there is about 90% likely even if the branch is fully susceptible. So I read 26.7's zero as sample size, not immunity.

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

26.6 is open: #112912.

On this branch the hook goes into base/base/sanitizer_options.h, next to the existing
__tsan_default_options - master's own placement, unlike the 26.5 sibling where that header
does not exist. Still purely additive: #107083 was never backported here either, so there is
no NO_SANITIZE_THREAD attribute to remove, and the suppression payload is byte-identical to
master's.

Two differences from the 26.5 pull request, both deliberate:

  • 26.6 has a second user of the queue, programs/keeper-bench/StorageRunner
    (NonblockingBoundedQueue<QueueItem>), and clickhouse-keeper-bench is a symlink to the same
    binary. So the anchored patterns are load-bearing here rather than merely tidy: an unqualified
    NonblockingBoundedQueue pattern would also match the queue header's own file name and silence
    those queues inside the same process image. A three-arm TSAN probe that takes the hook from the
    real header confirms both Keeper instantiations are suppressed while the QueueItem shape is
    still reported.
  • I dropped master's comment clause about "the unrelated asynchronous logging queue". It is not
    true on any release branch: git grep -c NonblockingBoundedQueue -- src/Loggers/ is 0 on 26.5,
    26.6, 26.7 and master alike. Revert "Revert "Use a lock-free queue for asynchronous logging"" #112803 would make it true on master only.

26.7 is next, and I will link it here.

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

26.7 is open: #112916. That completes the set I promised: 26.5 #112899, 26.6 #112912, 26.7 #112916.

26.7 is the one branch where the signature has never been observed, so the case for it is structural rather than statistical: both carrier files are present with both explicit instantiations, and its copy of the queue header is md5-identical to 26.6's, which did see the failure. Like 26.6 it takes master's placement in base/base/sanitizer_options.h; only 26.5 needed programs/main.cpp, because that header does not exist there.

One measurement worth passing on, since it changed my own numbers. Counting this failure by the harness line Sanitizer assert found for instance zoo% undercounts it: when the TSan banner lands first it overwrites the instance name, so the line reads Sanitizer assert found for instance ================== instead. Two of the four master occurrences in the last 45 days hide that way. Attributing each one needs the shard's logs.tar.gz and the Keeper container's docker.log, because the stack in the database row is truncated before the frame that names the queue.

26.4 and older lack the carrier files entirely, so nothing further is needed there.

@alexey-milovidov
alexey-milovidov merged commit 819620f into 26.5 Aug 1, 2026
35 checks passed
@alexey-milovidov
alexey-milovidov deleted the backport/26.5/111103 branch August 1, 2026 23:18
PedroTadim pushed a commit that referenced this pull request Sep 4, 2026
Backport of #112695 to 26.6, requested by alexey-milovidov on #112722.
26.6 still carries the defect and has no fix.

`Integration tests (amd_tsan, N/6)` fails in teardown with `Sanitizer assert
found for instance zoo<N>`, from a TSAN data race report between the
`slot.value` write in `NonblockingBoundedQueue::tryPush` and the read in
`tryPop`.

The report is a false positive. The release/acquire handoff on `slot.pos`
orders every access to a slot payload, and there is no non-protocol payload
access anywhere in the class, so the code is isomorphic to Vyukov's original
implementation. But `abort_on_error=1` in `__tsan_default_options` turns the
report into an aborted Keeper node, so healthy runs go red.

A `NO_SANITIZE_THREAD` attribute cannot suppress it. Neither
`KeeperRequestForSession` nor `KeeperResponseForSession` declares an
`operator=`, so the racing access happens in the implicitly generated move
assignment, a separate function that keeps `sanitize_thread`. The attribute
also prevents that un-attributed callee from being inlined into the attributed
caller, which is what creates the frame split that defeats it. A runtime
`__tsan_default_suppressions` entry is consulted for every frame of a report,
so one entry covers the whole nested move chain.

Register that hook with two anchored patterns for the two Keeper
instantiations. Only `tryPush` is listed: the `dequeue_pos` compare-exchange
gives one consumer sole ownership of a slot before the move-out in `tryPop`,
so a pop/pop payload race cannot occur at any consumer count, and each `race:`
entry also hides heap-use-after-free reports through the frame it names.

Anchoring is load-bearing. Patterns are matched against each frame's function,
file and module name, and `clickhouse-keeper-bench` is a symlink to the same
binary, so an unqualified pattern would also silence its three unrelated
`NonblockingBoundedQueue<QueueItem>` queues. Verified it does not.

This is purely additive, unlike the master commit: #107083, which added the
attributes master removes, was never backported to 26.6, so there is no
attribute to strip here. A straight cherry-pick does not apply (`git apply
--check` fails on both files); on 26.6 the hook goes in
`base/base/sanitizer_options.h`, which is master's own placement, whereas the
26.5 sibling #112899 had to use `programs/main.cpp` because that header does
not exist on 26.5.

Non-sanitizer builds are unaffected: the hook is inside `#ifdef
THREAD_SANITIZER` and the other change is a comment, so there is no codegen
change and no performance impact. A suppression only affects whether TSAN
prints or aborts on a report.

No test, matching #112695. The only oracle is a CI-side absence property over
many runs, which no functional test can assert.

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants