Merge pull request #72848 from ClickHouse/backport/24.9/72685

Backport #72685 to 24.9: Fix flatten_nested when recovering a Replicated database
This commit is contained in:
robot-clickhouse-ci-2 2024-12-05 18:15:42 +01:00 committed by GitHub
commit 9c76c68f50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 3 deletions

View File

@ -1206,6 +1206,13 @@ void DatabaseReplicated::recoverLostReplica(const ZooKeeperPtr & current_zookeep
query_context->setSetting("database_replicated_allow_explicit_uuid", 3);
query_context->setSetting("database_replicated_allow_replicated_engine_arguments", 3);
/// We apply the flatten_nested setting after writing the CREATE query to the DDL log,
/// but before writing metadata to ZooKeeper. So we have to apply the setting on secondary replicas, but not in recovery mode.
/// Set it to false, so it will do nothing on recovery. The metadata in ZooKeeper should be used as is.
/// Same for data_type_default_nullable.
query_context->setSetting("flatten_nested", false);
query_context->setSetting("data_type_default_nullable", false);
auto txn = std::make_shared<ZooKeeperMetadataTransaction>(current_zookeeper, zookeeper_path, false, "");
query_context->initZooKeeperMetadataTransaction(txn);
return query_context;

View File

@ -103,11 +103,27 @@ def test_flatten_nested(started_cluster):
"CREATE MATERIALIZED VIEW create_replicated_table.mv ENGINE=ReplicatedMergeTree ORDER BY tuple() AS select d, cast([(k, toString(i32))] as Nested(a UInt64, b String)) from create_replicated_table.replicated_table"
)
assert main_node.query(
"show create create_replicated_table.mv"
) == dummy_node.query("show create create_replicated_table.mv")
main_node.query(
"CREATE TABLE create_replicated_table.no_flatten (n Nested(a UInt64, b String)) ENGINE=ReplicatedMergeTree ORDER BY tuple();",
settings={"flatten_nested": 0},
)
snapshot_recovering_node.query(
"CREATE DATABASE create_replicated_table ENGINE = Replicated('/test/create_replicated_table', 'shard1', 'replica3');"
)
snapshot_recovering_node.query(
"SYSTEM SYNC DATABASE REPLICA create_replicated_table"
)
for node in [dummy_node, snapshot_recovering_node]:
for table in ["replicated_table", "mv", "no_flatten"]:
assert main_node.query(
f"show create create_replicated_table.{table}"
) == node.query(f"show create create_replicated_table.{table}")
main_node.query("DROP DATABASE create_replicated_table SYNC")
dummy_node.query("DROP DATABASE create_replicated_table SYNC")
snapshot_recovering_node.query("DROP DATABASE create_replicated_table SYNC")
def test_create_replicated_table(started_cluster):