mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Merge pull request #18789 from amosbird/onclusteraltersettings
Apply alter settings on cluster to all replicas
This commit is contained in:
commit
7e52b0c964
@ -847,6 +847,13 @@ bool DDLWorker::taskShouldBeExecutedOnLeader(const ASTPtr ast_ddl, const Storage
|
||||
if (!ast_ddl->as<ASTAlterQuery>() && !ast_ddl->as<ASTOptimizeQuery>() && !ast_ddl->as<ASTDropQuery>())
|
||||
return false;
|
||||
|
||||
if (auto * alter = ast_ddl->as<ASTAlterQuery>())
|
||||
{
|
||||
// Setting alters should be executed on all replicas
|
||||
if (alter->isSettingsAlter())
|
||||
return false;
|
||||
}
|
||||
|
||||
return storage->supportsReplication();
|
||||
}
|
||||
|
||||
|
@ -344,6 +344,22 @@ void ASTAlterCommand::formatImpl(
|
||||
throw Exception("Unexpected type of ALTER", ErrorCodes::UNEXPECTED_AST_STRUCTURE);
|
||||
}
|
||||
|
||||
bool ASTAlterQuery::isSettingsAlter() const
|
||||
{
|
||||
if (command_list)
|
||||
{
|
||||
if (command_list->children.empty())
|
||||
return false;
|
||||
for (const auto & child : command_list->children)
|
||||
{
|
||||
const auto & command = child->as<const ASTAlterCommand &>();
|
||||
if (command.type != ASTAlterCommand::MODIFY_SETTING)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Get the text that identifies this element. */
|
||||
String ASTAlterQuery::getID(char delim) const
|
||||
|
@ -187,6 +187,8 @@ public:
|
||||
|
||||
ASTExpressionList * command_list = nullptr;
|
||||
|
||||
bool isSettingsAlter() const;
|
||||
|
||||
String getID(char) const override;
|
||||
|
||||
ASTPtr clone() const override;
|
||||
|
@ -0,0 +1,17 @@
|
||||
<yandex>
|
||||
<remote_servers>
|
||||
<cluster>
|
||||
<shard>
|
||||
<internal_replication>true</internal_replication>
|
||||
<replica>
|
||||
<host>ch1</host>
|
||||
<port>9000</port>
|
||||
</replica>
|
||||
<replica>
|
||||
<host>ch2</host>
|
||||
<port>9000</port>
|
||||
</replica>
|
||||
</shard>
|
||||
</cluster>
|
||||
</remote_servers>
|
||||
</yandex>
|
@ -0,0 +1,5 @@
|
||||
<yandex>
|
||||
<distributed_ddl>
|
||||
<path>/clickhouse/task_queue/ddl</path>
|
||||
</distributed_ddl>
|
||||
</yandex>
|
54
tests/integration/test_alter_settings_on_cluster/test.py
Normal file
54
tests/integration/test_alter_settings_on_cluster/test.py
Normal file
@ -0,0 +1,54 @@
|
||||
import pytest
|
||||
from helpers.cluster import ClickHouseCluster
|
||||
|
||||
cluster = ClickHouseCluster(__file__)
|
||||
ch1 = cluster.add_instance(
|
||||
"ch1",
|
||||
main_configs=[
|
||||
"configs/config.d/clusters.xml",
|
||||
"configs/config.d/distributed_ddl.xml",
|
||||
],
|
||||
with_zookeeper=True,
|
||||
)
|
||||
ch2 = cluster.add_instance(
|
||||
"ch2",
|
||||
main_configs=[
|
||||
"configs/config.d/clusters.xml",
|
||||
"configs/config.d/distributed_ddl.xml",
|
||||
],
|
||||
with_zookeeper=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def started_cluster():
|
||||
try:
|
||||
cluster.start()
|
||||
ch1.query("CREATE DATABASE test_default_database ON CLUSTER 'cluster';")
|
||||
yield cluster
|
||||
|
||||
finally:
|
||||
cluster.shutdown()
|
||||
|
||||
|
||||
def test_default_database_on_cluster(started_cluster):
|
||||
ch1.query(
|
||||
database="test_default_database",
|
||||
sql="CREATE TABLE test_local_table (x UInt64) ENGINE=ReplicatedMergeTree('/clickhouse/tables/test_local_table', 'r1') ORDER BY tuple();",
|
||||
)
|
||||
|
||||
ch2.query(
|
||||
database="test_default_database",
|
||||
sql="CREATE TABLE test_local_table (x UInt64) ENGINE=ReplicatedMergeTree('/clickhouse/tables/test_local_table', 'r2') ORDER BY tuple();",
|
||||
)
|
||||
|
||||
ch1.query(
|
||||
database="test_default_database",
|
||||
sql="ALTER TABLE test_local_table ON CLUSTER 'cluster' MODIFY SETTING old_parts_lifetime = 100;",
|
||||
)
|
||||
|
||||
for node in [ch1, ch2]:
|
||||
assert node.query(
|
||||
database="test_default_database",
|
||||
sql="SHOW CREATE test_local_table FORMAT TSV",
|
||||
).endswith("old_parts_lifetime = 100\n")
|
Loading…
Reference in New Issue
Block a user