2019-08-05 03:24:59 +00:00
|
|
|
import time
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
import pytest
|
2019-08-05 03:24:59 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
instance_test_mutations = cluster.add_instance(
|
|
|
|
"test_mutations_with_merge_tree",
|
|
|
|
main_configs=["configs/config.xml"],
|
|
|
|
user_configs=["configs/users.xml"],
|
|
|
|
)
|
2019-08-05 03:24:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
2020-09-16 04:26:10 +00:00
|
|
|
instance_test_mutations.query(
|
2022-06-23 08:37:52 +00:00
|
|
|
"""CREATE TABLE test_mutations_with_ast_elements(date Date, a UInt64, b String) ENGINE = MergeTree PARTITION BY toYYYYMM(date) ORDER BY (a, date)"""
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
instance_test_mutations.query(
|
2022-03-22 16:39:58 +00:00
|
|
|
"""INSERT INTO test_mutations_with_ast_elements SELECT '2019-07-29' AS date, 1, toString(number) FROM numbers(1) SETTINGS force_index_by_date = 0, force_primary_key = 0"""
|
|
|
|
)
|
2019-08-05 08:36:41 +00:00
|
|
|
yield cluster
|
2019-08-05 03:24:59 +00:00
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_mutations_with_merge_background_task(started_cluster):
|
2022-03-22 16:39:58 +00:00
|
|
|
instance_test_mutations.query(
|
|
|
|
"""SYSTEM STOP MERGES test_mutations_with_ast_elements"""
|
|
|
|
)
|
2019-08-05 03:24:59 +00:00
|
|
|
|
|
|
|
## The number of asts per query is 15
|
2019-08-05 08:36:41 +00:00
|
|
|
for execution_times_for_mutation in range(100):
|
2020-09-16 04:26:10 +00:00
|
|
|
instance_test_mutations.query(
|
2022-03-22 16:39:58 +00:00
|
|
|
"""ALTER TABLE test_mutations_with_ast_elements DELETE WHERE 1 = 1 AND toUInt32(b) IN (1)"""
|
|
|
|
)
|
2019-08-05 03:24:59 +00:00
|
|
|
|
|
|
|
all_done = False
|
2020-09-16 04:26:10 +00:00
|
|
|
for wait_times_for_mutation in range(100): # wait for replication 80 seconds max
|
2019-08-05 03:24:59 +00:00
|
|
|
time.sleep(0.8)
|
|
|
|
|
|
|
|
def get_done_mutations(instance):
|
2022-03-22 16:39:58 +00:00
|
|
|
instance_test_mutations.query(
|
|
|
|
"""DETACH TABLE test_mutations_with_ast_elements"""
|
|
|
|
)
|
|
|
|
instance_test_mutations.query(
|
|
|
|
"""ATTACH TABLE test_mutations_with_ast_elements"""
|
|
|
|
)
|
|
|
|
return int(
|
|
|
|
instance.query(
|
|
|
|
"SELECT sum(is_done) FROM system.mutations WHERE table = 'test_mutations_with_ast_elements' SETTINGS force_index_by_date = 0, force_primary_key = 0"
|
|
|
|
).rstrip()
|
|
|
|
)
|
2019-08-05 03:24:59 +00:00
|
|
|
|
|
|
|
if get_done_mutations(instance_test_mutations) == 100:
|
|
|
|
all_done = True
|
|
|
|
break
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
print(
|
|
|
|
instance_test_mutations.query(
|
|
|
|
"SELECT mutation_id, command, parts_to_do, is_done FROM system.mutations WHERE table = 'test_mutations_with_ast_elements' SETTINGS force_index_by_date = 0, force_primary_key = 0 FORMAT TSVWithNames"
|
|
|
|
)
|
|
|
|
)
|
2019-08-05 03:24:59 +00:00
|
|
|
assert all_done
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2019-08-05 03:24:59 +00:00
|
|
|
def test_mutations_with_truncate_table(started_cluster):
|
2022-03-22 16:39:58 +00:00
|
|
|
instance_test_mutations.query(
|
|
|
|
"""SYSTEM STOP MERGES test_mutations_with_ast_elements"""
|
|
|
|
)
|
2019-08-05 03:24:59 +00:00
|
|
|
|
|
|
|
## The number of asts per query is 15
|
|
|
|
for execute_number in range(100):
|
2020-09-16 04:26:10 +00:00
|
|
|
instance_test_mutations.query(
|
2022-03-22 16:39:58 +00:00
|
|
|
"""ALTER TABLE test_mutations_with_ast_elements DELETE WHERE 1 = 1 AND toUInt32(b) IN (1)"""
|
|
|
|
)
|
2019-08-05 03:24:59 +00:00
|
|
|
|
|
|
|
instance_test_mutations.query("TRUNCATE TABLE test_mutations_with_ast_elements")
|
2022-03-22 16:39:58 +00:00
|
|
|
assert (
|
|
|
|
instance_test_mutations.query(
|
|
|
|
"SELECT COUNT() FROM system.mutations WHERE table = 'test_mutations_with_ast_elements SETTINGS force_index_by_date = 0, force_primary_key = 0'"
|
|
|
|
).rstrip()
|
|
|
|
== "0"
|
|
|
|
)
|