Repository navigation
Implement applySettingsChanges for DatabaseReplicated - #117544
kirillshokhin wants to merge 17 commits into
Conversation
This commit allows updating `DatabaseReplicated` settings via `ALTER
DATABASE ... MODIFY SETTING ...` query.
1. Split settings into mutable and immutable:
a. `default_replica_path`, `default_replica_shard_name` and
`default_replica_name` are immutable because they're consulted only on
the database creation.
b. `internal_replication` is immutable since changing it in realtime
may result in inconsistent query results.
2. `logs_to_keep` is updated in Keeper. May be updated even if the
metadata on disk update fails. The Keeper is the source of truth for
this setting and there's no obvious way to guarantee atomicity of
publishing the settings, so if the metadata on disk update fails, the
corresponding message is attached to the root cause exception. A new
failpoint is added to verify behavior in this exact case.
3. Worker fetches `logs_to_keep` on every entry cleanup request along
with the `max_log_ptr` so the number of requests to Keeper does not
change.
4. `db_settings` is stored in the `MultiVersion` container to
synchronize concurrent readers and a writer.
5. `metadata_mutex` is used to synchronize writers.
6. If the `collection_name` setting changed, the cached cluster objects
are invalidated and rebuilt on the next request. `mutex` is used to
synchronize access to the cluster objects.
7. `logs_to_keep` column added to the `system.database_replicas` table,
sourced from the Keeper node to provide the real value of the
setting.
8. Old settings values are not compared to the new ones - any new value
is considered a change. This allows setting the already used named
collection's name to reload the collection's contents and update
cluster credentials.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [24d4b3f] Summary: ❌
AI ReviewSummaryReviewed #117544 at Findings
Tests
Missing context / blind spots
Final VerdictStatus: |
It should contain newly added `logs_to_keep` column.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes12 object files changed (+68.30 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units34 translation units recompiled, 317 s compile time in total, 34 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
Two findings from a review. The first is rig-verified both ways on this PR's CI binary (26.9.1.1, 1. The new upper-bound check blesses values that invert the setting's semantics through The validation added in
With Rig on the PR-head binary, single replica, embedded Keeper, pure defaults: create Control arm ( Fault arm ( — a replica that is provably byte-identical to the Keeper state (equal pointers, equal digests) is declared lost and recovered, and this repeats on every subsequent restart. The wrapping comparisons pre-date this PR (a CREATE-time 2. Minor: a new data race on Before this PR, |
1. Clamp when `logs_to_keep` is read on cleanup. 2. Clamp when `logs_to_keep` is read for the status response.
|
|
||
| cluster_auth_info->moveCredsFrom(std::move(*new_cluster_auth_info)); | ||
|
|
||
| setClusterLocked(nullptr, false); |
There was a problem hiding this comment.
[Major] Refresh existing Distributed background-insert pools on credential changes
Clearing these two cluster pointers leaves another credential cache intact: StorageDistributed::getDirectoryQueue caches a DistributedAsyncInsertDirectoryQueue and its connection pool. It rebuilds them only when Context::getClustersVersion advances and the addresses change; this ALTER does not advance that version. Queue names contain only shard/replica indexes, so subsequent inserts reuse the same queue with the old credentials.
Reproduced with this head's Fast test binary: create a queue using a collection with an incorrect password, stop background sends and enqueue a row, then switch collection_name to a collection with the correct password. The ALTER succeeds and clusterAllReplicas connects successfully, but SYSTEM FLUSH DISTRIBUTED still returns AUTHENTICATION_FAILED. Inserting another row and flushing fails again; the target remains empty. Thus ordinary asynchronous inserts cannot pick up corrected or rotated credentials without rebuilding the table's queue.
Please propagate credential invalidation to existing queue pools, including pending work, and add a stateless regression that creates the queue before the ALTER. Include cluster_secret in the invalidation identity: merely bumping the global version still misses secret-only rotations because Cluster::Address::tuple excludes it.
This commit allows updating
DatabaseReplicatedsettings viaALTER DATABASE ... MODIFY SETTING ...query.default_replica_path,default_replica_shard_nameanddefault_replica_nameare immutable because they're consulted only on the database creation. b.internal_replicationis immutable since changing it in realtime may result in inconsistent query results.logs_to_keepis an immutable setting. It's a cluster-wide setting and modifying it is not safe without additional coordination. Specifically increasinglogs_to_keepmay result in the following scenario: 1. While replica B is offline, replica A trims the log to the old, smallerlogs_to_keepvalue. 2.logs_to_keepis updated to a greater value. 3. Replica B starts, loads new, greaterlogs_to_keepvalue and skips recovery, thus skipping the trimmed entries.db_settingsis stored in theMultiVersioncontainer to synchronize concurrent readers and a writer.metadata_mutexis used to synchronize writers.collection_namesetting changed, the cached cluster objects are invalidated and rebuilt on the next request.mutexis used to synchronize access to the cluster objects.logs_to_keepcolumn added to thesystem.database_replicastable, sourced from the Keeper node to provide the real value of the setting.Closes: #74915
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
You can now change the settings of a
Replicateddatabase withALTER DATABASE ... MODIFY SETTING.Only replica-local settings are mutable, and the change applies only to the replica the query runs on.
Settings that only describe how the database was created (
default_replica_path,default_replica_shard_nameanddefault_replica_name),internal_replication, which must match on every replica, andlogs_to_keep, which all replicas share through ClickHouse Keeper, are rejected.Changing
collection_namerequires theNAMED COLLECTIONgrant on the new collection, and a collection with acluster_secure_connectionvalue different from the current one is rejected.The new
logs_to_keepcolumn insystem.database_replicasreports the value actually in effect,which
SHOW CREATE DATABASEcannot always show.Workflow [PR]
Sync PR [sync-upstream/pr/117544]