@@ -23,6 +23,37 @@ def randomize_name(table_name, random_suffix_length=8):
2323 return f"{ table_name } _{ '' .join (random .choice (letters ) for _ in range (random_suffix_length ))} "
2424
2525
26+ s3 = """disk(
27+ name={},
28+ type='s3_plain_rewritable',
29+ endpoint='http://minio1:9001/root/data/node1',
30+ access_key_id='minio',
31+ secret_access_key='ClickHouse_Minio_P@ssw0rd')"""
32+
33+ cache = """disk(
34+ type='cache',
35+ disk={},
36+ path='disks/cache/',
37+ cache_on_write_operations=1,
38+ max_size='1Gi')""" .format (
39+ s3
40+ )
41+
42+ encrypted = """disk(
43+ type='encrypted',
44+ disk={},
45+ path='disks/encrypted/',
46+ key='1234567812345678')""" .format (
47+ cache
48+ )
49+
50+ disk_defs = {
51+ "s3_plain_rewritable" : s3 ,
52+ "cache" : cache ,
53+ "encrypted" : encrypted ,
54+ }
55+
56+
2657@pytest .fixture (scope = "module" , autouse = True )
2758def start_cluster ():
2859 cluster .add_instance (
@@ -51,7 +82,16 @@ def start_cluster():
5182 cluster .shutdown ()
5283
5384
54- def test_alter_partition_after_table_rotation ():
85+ @pytest .mark .parametrize (
86+ "storage_policy" ,
87+ [
88+ "s3_plain_rewritable" ,
89+ "cache" ,
90+ "encrypted" ,
91+ ],
92+ )
93+ @pytest .mark .parametrize ("partition_ops_on_same_disk" , [1 , 0 ])
94+ def test_alter_partition_after_table_rotation (start_cluster , storage_policy , partition_ops_on_same_disk ):
5595 node1 = cluster .instances ["node1" ]
5696
5797 def create_insert (node , table_name , insert_values ):
@@ -63,7 +103,7 @@ def create_insert(node, table_name, insert_values):
63103 ) ENGINE=MergeTree()
64104 ORDER BY id
65105 PARTITION BY id%10
66- SETTINGS storage_policy='s3_plain_rewritable '
106+ SETTINGS storage_policy='{ storage_policy } '
67107 """
68108 )
69109
@@ -80,44 +120,43 @@ def create_insert(node, table_name, insert_values):
80120
81121 node1 .query (f"DETACH TABLE { table1 } PERMANENTLY SYNC" )
82122
83- disk_name = randomize_name ("disk" )
84123 node2 = cluster .instances ["node2" ]
85124 table2 = randomize_name ("table2" )
86125 node2 .query (f"DROP TABLE IF EXISTS { table2 } SYNC" )
126+
127+ disk_name = randomize_name ("disk" )
128+ disk_def = disk_defs [storage_policy ].format (disk_name )
129+ policy_def = (
130+ f"disk={ disk_def } "
131+ if partition_ops_on_same_disk
132+ else f"storage_policy='{ storage_policy } '"
133+ )
134+
87135 node2 .query (
88136 f"""CREATE TABLE { table2 } (id Int64, data String)
89137 ENGINE=MergeTree()
90138 ORDER BY id
91139 PARTITION BY id%10
92- SETTINGS disk=disk(
93- name={ disk_name } ,
94- type='s3_plain_rewritable',
95- endpoint='http://minio1:9001/root/data/node1',
96- access_key_id='minio',
97- secret_access_key='ClickHouse_Minio_P@ssw0rd')
140+ SETTINGS { policy_def }
98141 """
99142 )
100143
101144 rotated_table = f"{ table1 } _rotated"
102145 node2 .query (f"""DROP TABLE IF EXISTS { rotated_table } SYNC""" )
146+
103147 node2 .query (
104148 f"""ATTACH TABLE { rotated_table } UUID '{ uuid1 } ' (id Int64, data String)
105149 ENGINE=MergeTree()
106150 ORDER BY id
107151 PARTITION BY id%10
108- SETTINGS disk=disk(
109- name={ disk_name } ,
110- type='s3_plain_rewritable',
111- endpoint='http://minio1:9001/root/data/node1',
112- access_key_id='minio',
113- secret_access_key='ClickHouse_Minio_P@ssw0rd')
152+ SETTINGS disk={ disk_def }
114153 """
115154 )
116155
117156 assert (
118157 int (
119158 node2 .query (
120- f"SELECT count(*) FROM { rotated_table } WHERE _partition_id = '0'"
159+ f"SELECT count(*) FROM { rotated_table } WHERE _partition_id= '0'"
121160 )
122161 )
123162 == 100
@@ -126,9 +165,10 @@ def create_insert(node, table_name, insert_values):
126165 assert int (node2 .query (f"SELECT count(*) FROM { rotated_table } " )) == 1000
127166
128167 node2 .query (f"""ALTER TABLE { rotated_table } MOVE PARTITION '0' TO TABLE { table2 } """ )
168+ node2 .query (f"""ALTER TABLE { table2 } REPLACE PARTITION '1' FROM { rotated_table } """ )
129169
130170 assert int (node2 .query (f"SELECT count(*) FROM { rotated_table } " )) == 900
131- assert int (node2 .query (f"SELECT count(*) FROM { table2 } " )) == 100
171+ assert int (node2 .query (f"SELECT count(*) FROM { table2 } " )) == 200
132172
133173 node2 .query (f"DROP TABLE { rotated_table } SYNC" )
134174 node2 .query (f"DROP TABLE { table2 } SYNC" )
0 commit comments