Skip to content

Commit 976a559

Browse files
committed
Reuse cluster_conf in backup_restore_on_cluster
1 parent dcdda50 commit 976a559

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tests/integration/test_backup_restore_on_cluster/concurrency_helper.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
11
from pathlib import Path
2-
from typing import Callable, List
2+
from typing import List
33

44
from helpers.cluster import ClickHouseCluster, ClickHouseInstance
55

66

77
def generate_cluster_def(file: str, num_nodes: int) -> str:
8+
# For multiple workers, it has race and sometimes errors out,
9+
# so we generate it once and reuse
810
path = (
911
Path(__file__).parent / f"_gen/cluster_{Path(file).stem}_{num_nodes}_nodes.xml"
1012
)
11-
path.parent.mkdir(parents=True, exist_ok=True)
1213
replicas = "\n".join(
1314
f""" <replica>
1415
<host>node{i}</host>
1516
<port>9000</port>
1617
</replica>"""
1718
for i in range(num_nodes)
1819
)
19-
path.write_text(
20-
encoding="utf-8",
21-
data=f"""<clickhouse>
20+
config = f"""<clickhouse>
2221
<remote_servers>
2322
<cluster>
2423
<shard>
2524
{replicas}
2625
</shard>
2726
</cluster>
2827
</remote_servers>
29-
</clickhouse>""",
28+
</clickhouse>"""
29+
if path.is_file():
30+
existing = path.read_text(encoding="utf-8")
31+
if existing == config:
32+
return str(path.absolute())
33+
path.parent.mkdir(parents=True, exist_ok=True)
34+
path.write_text(
35+
encoding="utf-8",
36+
data=config,
3037
)
3138
return str(path.absolute())
3239

0 commit comments

Comments
 (0)