Skip to content

Simplify access-change notifications: replace two-tier notifications - #108414

Merged
vitlibar merged 6 commits into
ClickHouse:masterfrom
vitlibar:simplify-access-changes-notifier-batched
Jul 2, 2026
Merged

vitlibar merged 6 commits into
ClickHouse:masterfrom
vitlibar:simplify-access-changes-notifier-batched

Conversation

@vitlibar

@vitlibar vitlibar commented Jun 24, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Simplify access-change notifications: replace two-tier notifications.

PRs #107672, #108124 fixed the issue with performance but introduced a complicated system of two-tier access-change notifications. Here I simplified that system back to one tier. So instead of two tiers subscribeForChanges & subscribeForBatchFinished now we have only subscribeForChanges again.

Performance is unchanged: one rebuild per batch, not one per changed entity. The throw-retry behavior is preserved: by-type handlers fire even on an empty batch, so a rebuild that threw is retried on the next sendNotifications (including a no-diff SYSTEM RELOAD USERS).

Version info

  • Merged into: 26.7.1.409 (included in 26.7 and later)
  • Backported to: 26.6.5.35

@vitlibar
vitlibar requested a review from Copilot June 24, 2026 20:00
@clickhouse-gh

clickhouse-gh Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [19d5eac]

Summary: ✅


AI Review

Summary

This PR replaces the old two-tier access-change notifications with batched subscribeForChanges callbacks and updates the access caches and tests accordingly. The notifier/caches look consistent after the follow-up fixes, but the new integration coverage still has two race windows: one test can log in before the replicated user exists, and the other can build its RoleCache baseline before the replicated grants/default roles arrive, which weakens the evidence for the role-reread invariant.

Findings
  • ⚠️ Majors
    • [tests/integration/test_access_cache_recompute_coalescing/test.py:62] test_recompute_coalesced_on_reread waits for row policies to replicate and then logs in as u with a plain query. The user and the policies are separate replicated access entities, so u can still be missing on node2 at this point and make the test flaky. Suggested fix: use query_with_retry("SELECT 1", user="u") or wait explicitly for system.users to contain u before logging in.
    • [tests/integration/test_access_cache_recompute_coalescing/test.py:132] test_role_recompute_coalesced_on_reread now waits for u2 to exist, but it still does not wait for GRANT r* TO u2 / ALTER USER u2 DEFAULT ROLE ALL to reach node2. If login succeeds against an early version of u2, the cached EnabledRoles set can be empty or partial, so the later delta can come from the delayed user update instead of the role reread path under test, or miss some role changes entirely. Suggested fix: wait on the replicated grants/default-role state itself before taking baseline, for example via system.role_grants (including granted_role_is_default) or an equivalent SHOW CREATE USER / SHOW GRANTS check.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: harden the two new integration tests so they deterministically build the intended live caches before measuring recomputation behavior.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 24, 2026
Comment thread src/Access/AccessChangesNotifier.cpp Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request simplifies access-change notifications by removing the separate “batch finished” notification tier and instead delivering access-entity changes in per-batch vectors to existing subscribeForChanges handlers (by-type and by-id). It updates the access caches to coalesce expensive recomputations once per drained notification batch, while preserving retry-on-next-send behavior after exceptions.

Changes:

  • Replace per-entity callbacks + subscribeForBatchFinished with batched subscribeForChanges callbacks that receive std::vector<AccessChangesNotifier::Change>.
  • Update RowPolicyCache, SettingsProfilesCache, QuotaCache, and RoleCache to apply per-entity bookkeeping over the batch and run a single coalesced rebuild per batch.
  • Extend tests (gtest + integration) to validate batching semantics, retry-after-throw, and role-cache recomputation coalescing.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/integration/test_access_cache_recompute_coalescing/test.py Adds an integration test to assert role-cache recomputation is coalesced to ~1 per batch on reread.
src/Access/tests/gtest_access_changes_notifier.cpp Updates/extends unit tests to validate batched delivery semantics, retry-after-throw, and by-id targeting.
src/Access/SettingsProfilesCache.h Removes batch-subscription member and annotates internal mutators as mutex-required.
src/Access/SettingsProfilesCache.cpp Switches settings profile updates to batched notifications and runs coalesced merge per batch.
src/Access/RowPolicyCache.h Removes batch-subscription member and annotates internal mutators as mutex-required.
src/Access/RowPolicyCache.cpp Switches row policy updates to batched notifications and runs coalesced filter mixing per batch.
src/Access/RoleCache.h Refactors role cache to a single by-type subscription and introduces referenced-role tracking.
src/Access/RoleCache.cpp Implements batched role-change handling and coalesced enabled-role recomputation.
src/Access/QuotaCache.h Removes batch-subscription member and annotates internal mutators as mutex-required.
src/Access/QuotaCache.cpp Switches quota updates to batched notifications and runs coalesced quota selection per batch.
src/Access/LDAPAccessStorage.cpp Adapts role-change subscription to batched change vectors.
src/Access/ContextAccess.cpp Adapts per-user subscriptions to the new batched by-id handler signature.
src/Access/AccessControl.h Drops subscribeForBatchFinished from AccessControl and reuses notifier handler type.
src/Access/AccessControl.cpp Removes subscribeForBatchFinished forwarding implementation.
src/Access/AccessChangesNotifier.h Redefines handler API to deliver std::vector<Change> and removes batch-finished API.
src/Access/AccessChangesNotifier.cpp Implements single-pass batch draining and delivery, grouped by type and by subscribed ids.

Comment thread src/Access/RoleCache.cpp Resolved

@azat azat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, indeed better!

Comment thread src/Access/QuotaCache.cpp Resolved
Comment thread src/Access/RowPolicyCache.cpp Outdated
else
rowPolicyRemoved(change.id);
}
if (need_mix_filters)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, do we need the flag? (and in all other places)
Or we can simply check for changes.empty()) ?

Comment thread src/Access/RoleCache.cpp Outdated
else
roleRemoved(change.id);
}
if (need_collect_enabled_roles)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess here we need the flag indeed

Comment thread src/Access/SettingsProfilesCache.cpp Outdated
else
profileRemoved(change.id);
}
if (need_merge_settings_and_constraints)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about here?

Comment thread src/Access/AccessChangesNotifier.h Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Comment thread src/Access/AccessChangesNotifier.cpp Resolved
Comment thread src/Access/AccessChangesNotifier.cpp Resolved
Comment thread src/Access/AccessChangesNotifier.h Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Comment thread src/Access/RoleCache.cpp Resolved
@vitlibar
vitlibar requested a review from Copilot July 1, 2026 21:29
@vitlibar
vitlibar force-pushed the simplify-access-changes-notifier-batched branch from d7a3206 to 2a48b86 Compare July 1, 2026 21:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.

@vitlibar
vitlibar enabled auto-merge July 1, 2026 21:39
Comment thread src/Access/RowPolicyCache.cpp Resolved
@vitlibar
vitlibar force-pushed the simplify-access-changes-notifier-batched branch from 2a48b86 to 19d5eac Compare July 1, 2026 22:21
@vitlibar
vitlibar requested a review from Copilot July 1, 2026 22:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.50% +0.10%
Functions 92.60% 92.70% +0.10%
Branches 77.60% 77.70% +0.10%

Changed lines: Changed C/C++ lines covered: 283/294 (96.26%) · Uncovered code

Full report · Diff report

@vitlibar
vitlibar added this pull request to the merge queue Jul 2, 2026
Merged via the queue into ClickHouse:master with commit 556b07b Jul 2, 2026
176 checks passed
@vitlibar
vitlibar deleted the simplify-access-changes-notifier-batched branch July 2, 2026 06:11
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 2, 2026
azat added a commit to azat/ClickHouse that referenced this pull request Jul 3, 2026
Rebuilding filters with many policies takes seconds under the mutex that every
login takes, stalling logins. Snapshot under a brief lock, rebuild and publish
atomically off-lock; sendNotifications keeps a single writer per enabled set.

Refs: https://pastila.nl/?000a9f0d/098eb7d78de026b75c13a2b4e16daf0c#qHx0nBBrcjF0T5OXSsDnjQ==GCM

v2: add concurrent row policy CREATE/DROP rebuild test
v3: fix dangling string_view key in published filters
v4: scope test row policies to a dedicated user instead of TO ALL
v5: rebase on top of ClickHouse#108414

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
azat added a commit to azat/ClickHouse that referenced this pull request Jul 3, 2026
Rebuilding filters with many policies takes seconds under the mutex that every
login takes, stalling logins. Snapshot under a brief lock, rebuild and publish
atomically off-lock; sendNotifications keeps a single writer per enabled set.

Refs: https://pastila.nl/?000a9f0d/098eb7d78de026b75c13a2b4e16daf0c#qHx0nBBrcjF0T5OXSsDnjQ==GCM

v2: add concurrent row policy CREATE/DROP rebuild test
v3: fix dangling string_view key in published filters
v4: scope test row policies to a dedicated user instead of TO ALL
v5: rebase on top of ClickHouse#108414

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
@al13n321 al13n321 added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 2, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 2, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 3, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 3, 2026
Backport #108414 to 26.6: Simplify access-change notifications: replace two-tier notifications
@azat

azat commented Sep 4, 2026

Copy link
Copy Markdown
Member

@al13n321 are you sure we need this backport? this looks like just a refactoring, or maybe we need it to backport some patch on top?

zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…anges-notifier-batched

Simplify access-change notifications: replace two-tier notifications
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Rebuilding filters with many policies takes seconds under the mutex that every
login takes, stalling logins. Snapshot under a brief lock, rebuild and publish
atomically off-lock; sendNotifications keeps a single writer per enabled set.

Refs: https://pastila.nl/?000a9f0d/098eb7d78de026b75c13a2b4e16daf0c#qHx0nBBrcjF0T5OXSsDnjQ==GCM

v2: add concurrent row policy CREATE/DROP rebuild test
v3: fix dangling string_view key in published filters
v4: scope test row policies to a dedicated user instead of TO ALL
v5: rebase on top of ClickHouse#108414

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 12, 2026
@al13n321

Copy link
Copy Markdown
Contributor

(It was a dependency for another backport, but then that backport was conflict-resolved anyway.)

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

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-not-for-changelog This PR should not be mentioned in the changelog 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.

6 participants