ClickHouse/tests/integration/test_consistant_parts_after_move_partition/test.py

59 lines
2.5 KiB
Python
Raw Normal View History

2019-10-22 11:45:11 +00:00
import os
import pytest
from helpers.cluster import ClickHouseCluster
from helpers.network import PartitionManager
from helpers.test_tools import assert_eq_with_retry
2019-10-23 07:36:11 +00:00
CLICKHOUSE_DATABASE = 'test'
2019-10-22 11:45:11 +00:00
def initialize_database(nodes, shard):
for node in nodes:
2019-10-23 06:14:38 +00:00
node.query('''
2019-10-24 06:23:28 +00:00
CREATE DATABASE {database};
2019-11-14 11:50:21 +00:00
CREATE TABLE `{database}`.src (p UInt64, d UInt64)
2019-11-14 07:07:17 +00:00
ENGINE = ReplicatedMergeTree('/clickhouse/{database}/tables/test_consistent_shard1{shard}/replicated', '{replica}')
2019-10-25 04:15:25 +00:00
ORDER BY d PARTITION BY p
2019-10-23 06:14:38 +00:00
SETTINGS min_replicated_logs_to_keep=3, max_replicated_logs_to_keep=5, cleanup_delay_period=0, cleanup_delay_period_random_add=0;
2019-11-14 11:50:21 +00:00
CREATE TABLE `{database}`.dest (p UInt64, d UInt64)
2019-11-14 07:07:17 +00:00
ENGINE = ReplicatedMergeTree('/clickhouse/{database}/tables/test_consistent_shard2{shard}/replicated', '{replica}')
2019-10-25 04:15:25 +00:00
ORDER BY d PARTITION BY p
2019-10-23 06:14:38 +00:00
SETTINGS min_replicated_logs_to_keep=3, max_replicated_logs_to_keep=5, cleanup_delay_period=0, cleanup_delay_period_random_add=0;
'''.format(shard=shard, replica=node.name, database=CLICKHOUSE_DATABASE))
2019-10-22 11:45:11 +00:00
cluster = ClickHouseCluster(__file__)
node1 = cluster.add_instance('node1', main_configs=['configs/remote_servers.xml'], with_zookeeper=True)
node2 = cluster.add_instance('node2', main_configs=['configs/remote_servers.xml'], with_zookeeper=True)
@pytest.fixture(scope="module")
2019-11-12 03:34:34 +00:00
def start_cluster():
2019-10-22 11:45:11 +00:00
try:
cluster.start()
initialize_database([node1, node2], 1)
yield cluster
except Exception as ex:
print ex
finally:
cluster.shutdown()
def test_consistent_part_after_move_partition(start_cluster):
# insert into all replicas
for i in range(100):
2019-11-18 03:43:39 +00:00
node1.query('INSERT INTO `{database}`.src VALUES ({value} % 2, {value})'.format(database=CLICKHOUSE_DATABASE,
2019-10-25 04:15:25 +00:00
value=i))
2019-10-23 06:14:38 +00:00
query_source = 'SELECT COUNT(*) FROM `{database}`.src'.format(database=CLICKHOUSE_DATABASE)
query_dest = 'SELECT COUNT(*) FROM `{database}`.dest'.format(database=CLICKHOUSE_DATABASE)
2019-10-22 11:45:11 +00:00
assert_eq_with_retry(node2, query_source, node1.query(query_source))
assert_eq_with_retry(node2, query_dest, node1.query(query_dest))
2019-10-23 06:14:38 +00:00
node1.query('ALTER TABLE `{database}`.src MOVE PARTITION 1 TO TABLE `{database}`.dest'.format(database=CLICKHOUSE_DATABASE))
2019-10-22 11:45:11 +00:00
assert_eq_with_retry(node2, query_source, node1.query(query_source))
assert_eq_with_retry(node2, query_dest, node1.query(query_dest))