Skip to content

Commit b459b60

Browse files
Merge pull request ClickHouse#86979 from ClickHouse/backport/25.8/86845
Backport ClickHouse#86845 to 25.8: Fix TimeSeries engine table breaking creation of new replica in Replicated Database
2 parents d790e77 + 2cd5b6f commit b459b60

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/Databases/DatabaseReplicated.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,11 @@ ASTPtr DatabaseReplicated::tryGetCreateOrAttachTableQuery(const String & name, C
931931
{
932932
auto res = tryGetCreateTableQuery(name, local_context);
933933
auto & create = res->as<ASTCreateQuery &>();
934-
create.attach = create.is_materialized_view_with_inner_table();
934+
create.attach = false;
935+
if (create.is_materialized_view_with_inner_table())
936+
create.attach = true;
937+
if (create.storage && create.storage->engine && (create.storage->engine->name == "TimeSeries"))
938+
create.attach = true;
935939
return res;
936940
}
937941

@@ -1731,7 +1735,13 @@ ASTPtr DatabaseReplicated::parseQueryFromMetadata(const String & table_name, con
17311735

17321736
create.setDatabase(getDatabaseName());
17331737
create.setTable(table_name);
1734-
create.attach = create.is_materialized_view_with_inner_table();
1738+
create.attach = false;
1739+
1740+
/// In both cases we need to set attach = true to avoid creating inner table(s) twice.
1741+
if (create.is_materialized_view_with_inner_table())
1742+
create.attach = true;
1743+
if (create.storage && create.storage->engine && (create.storage->engine->name == "TimeSeries"))
1744+
create.attach = true;
17351745

17361746
return ast;
17371747
}

tests/integration/test_replicated_database/test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,3 +1727,35 @@ def test_implicit_index(started_cluster):
17271727
"CREATE DATABASE implicit_index ENGINE = Replicated('/clickhouse/databases/implicit_index', 'shard1', 'replica2');"
17281728
"SYSTEM SYNC DATABASE REPLICA implicit_index;"
17291729
)
1730+
1731+
1732+
def test_timeseries(started_cluster):
1733+
for node in [competing_node, main_node, dummy_node]:
1734+
node.query("DROP DATABASE IF EXISTS ts_db SYNC")
1735+
1736+
competing_node.query(
1737+
"CREATE DATABASE ts_db ENGINE = Replicated('/clickhouse/databases/ts_db', '{shard}', '{replica}');"
1738+
)
1739+
1740+
main_node.query(
1741+
"""
1742+
CREATE DATABASE ts_db ENGINE = Replicated('/clickhouse/databases/ts_db', '{shard}', '{replica}');
1743+
CREATE TABLE ts_db.table ENGINE = TimeSeries SETTINGS store_min_time_and_max_time = false
1744+
DATA ENGINE = ReplicatedMergeTree ORDER BY (id, timestamp)
1745+
TAGS ENGINE = ReplicatedAggregatingMergeTree PRIMARY KEY metric_name ORDER BY (metric_name, id)
1746+
METRICS ENGINE = ReplicatedReplacingMergeTree ORDER BY metric_family_name;
1747+
""",
1748+
settings={"allow_experimental_time_series_table": 1}
1749+
)
1750+
1751+
dummy_node.query(
1752+
"CREATE DATABASE ts_db ENGINE = Replicated('/clickhouse/databases/ts_db', '{shard}', '{replica}');"
1753+
)
1754+
1755+
for node in [competing_node, main_node, dummy_node]:
1756+
assert node.query(
1757+
"""
1758+
SYSTEM SYNC DATABASE REPLICA ts_db;
1759+
SELECT count() FROM system.tables WHERE database='ts_db';
1760+
""", timeout=10
1761+
) == "4\n", f"Node {node.name} failed"

0 commit comments

Comments
 (0)