Repository navigation
Conversation
|
Workflow [PR], commit [4e3ccfd] Summary: ❌
AI ReviewSummaryThis PR adds a per-replica Findings
Final VerdictStatus: |
621aba1 to
4cdffc1
Compare
Add a per-replica `skip_distributed_ddl` option to cluster replica configuration. A replica with `skip_distributed_ddl` set stays available for `Distributed` table routing and reads/writes, but is excluded from `ON CLUSTER` DDL dispatch. This is useful when several replicas in a cluster point at the same physical host (e.g. `localhost`) and would otherwise each execute the same DDL task. - `Cluster` parses the option, and `executeDDLQueryOnCluster` builds the effective (non-skipped) address list once, reusing it for the task host list and for default-database / access-rights derivation. It throws `BAD_ARGUMENTS` if every selected replica is skipped. - `DDLWorker` no longer registers skipped replicas as local hosts, so they do not claim ON CLUSTER tasks. - `BACKUP` / `RESTORE ON CLUSTER` reuse the same dispatch path, so their coordination host set is kept consistent. `cluster_host_ids` is a positional shard/replica map, so skipped replicas are marked with a `kSkippedHost` sentinel rather than dropped: this preserves shard/replica numbering while `filterHostIDs` excludes them from the coordination wait-set. The `RESTORE` access precheck skips them as well. Adds documentation and integration tests.
dd90ff0 to
1d3e919
Compare
getAllHostIDsFromClusters only excluded skip_distributed_ddl replicas from the config-derived host set, which feeds createReplicaDirs. But markReplicasActive decides which replicas this server owns by iterating the existing znodes under replicas_dir and reclaiming any that resolve to self, without checking the allowed host set. So a replica registered before skip_distributed_ddl was enabled kept its /replicas/<host_id>/active entry after SYSTEM RELOAD CONFIG or restart, meaning the feature did not take effect on existing deployments. Gate the self-host claim on getAllHostIDsFromClusters: a self-host that is no longer allowed is not re-marked active, and on reload its active node is released so the replica stops claiming the host. Add an integration test that enables skip_distributed_ddl on an already registered replica and verifies it is no longer claimed as active after a restart, while the still-allowed replica keeps its registration.
Covers the skip_distributed_ddl backup/restore path: a shard with one normal replica and one replica excluded via skip_distributed_ddl. It checks that BACKUP and RESTORE ON CLUSTER complete (the skipped replica is kept out of the coordination host set instead of being waited on) and that the skipped replica is not part of the ON CLUSTER DDL, exercising getClusterHostIDsForCoordination and the skipped-replica branch of BackupsWorker::doRestore.
executeDDLQueryOnCluster already throws BAD_ARGUMENTS when every selected replica has skip_distributed_ddl, but only when the internal query is dispatched - after the initiator created coordination and opened the backup/restore engine. An unrelated storage error could therefore mask the configuration error, and BACKUP could touch the destination (leaving partial files behind with backups.remove_backup_files_after_failure = 0). Validate the effective (non-skipped) host set up front in the backup and restore initiators, before coordination and engine open, reusing filterHostIDs so the check matches the dispatch/coordination host set and honors shard_num/replica_num. Extend the integration test to cover an all-skipped selection (via replica_num) and assert the failure is reported before any backup artifact is created and before the restore source is opened.
| void throwIfAllReplicasSkipped( | ||
| const std::vector<Strings> & cluster_host_ids, size_t shard_num, size_t replica_num, std::string_view operation) | ||
| { | ||
| if (BackupSettings::Util::filterHostIDs(cluster_host_ids, shard_num, replica_num).empty()) |
There was a problem hiding this comment.
filterHostIDs() is only a selection helper; it does not preserve the cluster's shard/replica range validation. Using empty() here therefore conflates “all selected replicas are skipped” with “the requested shard/replica does not exist”.
Concrete repros:
- On a two-replica cluster,
BACKUP ... SETTINGS replica_num=3now throws the newBAD_ARGUMENTS/skip_distributed_ddlerror instead of the existingNO_SUCH_REPLICAfromCluster::filterAddressesByShardOrReplica(). - On a heterogeneous cluster,
replica_num=2can even pass this precheck because one shard has replica 2, so coordination/storage are initialized, and only then doesexecuteDDLQueryOnCluster()fail when another shard lacks replica 2.
Please validate the shard/replica selection with the same path as dispatch (or teach filterHostIDs() to throw INVALID_SHARD_ID / NO_SUCH_REPLICA) before interpreting an empty result as “all skipped”.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 79/81 (97.53%) · Uncovered code |
When multiple replicas in a cluster share the same host (e.g.
localhost), the DDL worker on that host claims and executesON CLUSTERDDL tasks for every one of them, causing duplicate execution. This adds a per-replica<skip_distributed_ddl>config tag (defaultfalse) that excludes a replica fromON CLUSTERDDL dispatch while keeping it fully available forDistributedtable query routing and reads/writes.The change covers the whole dispatch path:
executeDDLQueryOnClusterbuilds the effective (non-skipped) replica set once and reuses it for both the task host list and default-database / access-rights derivation; it throwsBAD_ARGUMENTSif every selected replica is skipped.DDLWorkerno longer registers skipped replicas as local hosts, so they do not claim tasks.BACKUP/RESTORE ON CLUSTERshare the same dispatch path, so their coordination host set is kept consistent: skipped replicas are excluded from the coordination wait-set and theRESTOREaccess precheck, while shard/replica numbering is preserved.Closes: #95316
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added a per-replica
skip_distributed_ddlcluster config option. A replica with this option set is excluded fromON CLUSTERDDL queries (andBACKUP/RESTORE ON CLUSTER) while remaining available forDistributedtable routing. This avoids duplicate DDL execution when several replicas share the same physical host.Documentation entry for user-facing changes