2020-10-15 16:17:16 +00:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
|
|
|
|
node1 = cluster.add_instance(
|
|
|
|
"node1",
|
2020-11-02 22:36:32 +00:00
|
|
|
main_configs=["configs/remote_servers.xml", "configs/merge_tree_uuids.xml"],
|
2020-10-15 16:17:16 +00:00
|
|
|
with_zookeeper=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
node2 = cluster.add_instance(
|
|
|
|
"node2",
|
2020-11-02 22:36:32 +00:00
|
|
|
main_configs=[
|
|
|
|
"configs/remote_servers.xml",
|
|
|
|
"configs/merge_tree_uuids.xml",
|
|
|
|
"configs/merge_tree_in_memory.xml",
|
|
|
|
],
|
2020-10-15 16:17:16 +00:00
|
|
|
with_zookeeper=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_part_uuid(started_cluster):
|
2020-11-02 14:38:18 +00:00
|
|
|
uuid_zero = uuid.UUID(bytes=b"\x00" * 16)
|
2020-10-15 16:17:16 +00:00
|
|
|
|
|
|
|
for ix, n in enumerate([node1, node2]):
|
|
|
|
n.query(
|
|
|
|
"""
|
|
|
|
CREATE TABLE t(key UInt64, value UInt64)
|
|
|
|
ENGINE ReplicatedMergeTree('/clickhouse/tables/t', '{}')
|
|
|
|
ORDER BY tuple()
|
|
|
|
""".format(
|
|
|
|
ix
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-10-15 16:17:16 +00:00
|
|
|
|
2020-11-02 14:38:18 +00:00
|
|
|
# Test insert assigns uuid to part.
|
2020-10-15 16:17:16 +00:00
|
|
|
node1.query("INSERT INTO t VALUES (1, 1)")
|
|
|
|
|
2020-11-02 14:38:18 +00:00
|
|
|
uuids = set()
|
|
|
|
for node in [node1, node2]:
|
|
|
|
node.query("SYSTEM SYNC REPLICA t")
|
|
|
|
part_initial_uuid = uuid.UUID(
|
|
|
|
node.query(
|
|
|
|
"SELECT uuid FROM system.parts WHERE table = 't' AND active ORDER BY name"
|
|
|
|
).strip()
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-11-02 14:38:18 +00:00
|
|
|
uuids.add(part_initial_uuid)
|
|
|
|
assert uuid_zero != part_initial_uuid
|
|
|
|
assert len(uuids) == 1, "expect the same uuid on all the replicas"
|
2020-10-15 16:17:16 +00:00
|
|
|
|
2020-11-02 14:38:18 +00:00
|
|
|
# Test detach / attach.
|
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE t DETACH PARTITION tuple(); ALTER TABLE t ATTACH PARTITION tuple()"
|
|
|
|
)
|
|
|
|
|
|
|
|
for node in [node1, node2]:
|
|
|
|
node.query("SYSTEM SYNC REPLICA t")
|
|
|
|
part_reattach_uuid = uuid.UUID(
|
|
|
|
node.query(
|
|
|
|
"SELECT uuid FROM system.parts WHERE table = 't' AND active ORDER BY name"
|
|
|
|
).strip()
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-11-02 14:38:18 +00:00
|
|
|
assert part_initial_uuid == part_reattach_uuid
|
|
|
|
|
|
|
|
# Test mutation assigns new non-zero uuids.
|
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE t UPDATE value = 1 WHERE key = 1 SETTINGS mutations_sync = 2"
|
|
|
|
)
|
|
|
|
part_mutate_uuid = uuid.UUID(
|
|
|
|
node1.query(
|
|
|
|
"SELECT uuid FROM system.parts WHERE table = 't' AND active ORDER BY name"
|
|
|
|
).strip()
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-11-02 14:38:18 +00:00
|
|
|
assert part_mutate_uuid not in [uuid_zero, part_initial_uuid]
|
2020-10-15 16:17:16 +00:00
|
|
|
|
|
|
|
node2.query("SYSTEM SYNC REPLICA t")
|
2020-11-02 14:38:18 +00:00
|
|
|
assert part_mutate_uuid == uuid.UUID(
|
|
|
|
node2.query(
|
|
|
|
"SELECT uuid FROM system.parts WHERE table = 't' AND active ORDER BY name"
|
|
|
|
).strip()
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-11-02 14:38:18 +00:00
|
|
|
|
|
|
|
# Test merge assigns new non-zero uuids.
|
|
|
|
node2.query("INSERT INTO t VALUES (1, 1)")
|
|
|
|
node2.query("OPTIMIZE TABLE t FINAL")
|
|
|
|
|
|
|
|
uuids = set()
|
|
|
|
for node in [node1, node2]:
|
|
|
|
node.query("SYSTEM SYNC REPLICA t")
|
|
|
|
part_merge_uuid = uuid.UUID(
|
|
|
|
node.query(
|
|
|
|
"SELECT uuid FROM system.parts WHERE table = 't' AND active ORDER BY name"
|
|
|
|
).strip()
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2020-11-02 14:38:18 +00:00
|
|
|
uuids.add(part_merge_uuid)
|
|
|
|
assert part_mutate_uuid not in [uuid_zero, part_merge_uuid]
|
|
|
|
assert len(uuids) == 1, "expect the same uuid on all the replicas"
|