From 33e3d831f842bbf7233aeb6dbb0bfee4b86bf6f5 Mon Sep 17 00:00:00 2001 From: Nikita Fomichev Date: Mon, 25 Mar 2024 18:40:57 +0100 Subject: [PATCH] integration tests: add test `test_replicated_database_compare_parts` --- .../test_backup_restore_on_cluster/test.py | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/integration/test_backup_restore_on_cluster/test.py b/tests/integration/test_backup_restore_on_cluster/test.py index b9528007b8a..2c60b096428 100644 --- a/tests/integration/test_backup_restore_on_cluster/test.py +++ b/tests/integration/test_backup_restore_on_cluster/test.py @@ -189,6 +189,60 @@ def test_replicated_database(): assert node2.query("SELECT * FROM mydb.tbl ORDER BY x") == expect +def test_replicated_database_compare_parts(): + """ + stop merges and fetches then write data to two nodes and + compare that parts are restored from single node (second) after backup + replica is selected by settings replica_num=2, replica_num_in_backup=2 + """ + node1.query( + "CREATE DATABASE mydb ON CLUSTER 'cluster' ENGINE=Replicated('/clickhouse/path/','{shard}','{replica}')" + ) + + node1.query( + "CREATE TABLE mydb.tbl(x UInt8, y String) ENGINE=ReplicatedMergeTree ORDER BY x" + ) + + node2.query("SYSTEM SYNC DATABASE REPLICA mydb") + + node1.query("SYSTEM STOP MERGES mydb.tbl") + node2.query("SYSTEM STOP MERGES mydb.tbl") + + node1.query("SYSTEM STOP FETCHES mydb.tbl") + node2.query("SYSTEM STOP FETCHES mydb.tbl") + + node1.query("INSERT INTO mydb.tbl VALUES (1, 'a')") + node1.query("INSERT INTO mydb.tbl VALUES (2, 'b')") + + node2.query("INSERT INTO mydb.tbl VALUES (3, 'x')") + node2.query("INSERT INTO mydb.tbl VALUES (4, 'y')") + + p2 = node2.query("SELECT * FROM mydb.tbl ORDER BY x") + + # Make backup. + backup_name = new_backup_name() + node1.query( + f"BACKUP DATABASE mydb ON CLUSTER 'cluster' TO {backup_name} SETTINGS replica_num=2" + ) + + # Drop table on both nodes. + node1.query("DROP DATABASE mydb ON CLUSTER 'cluster' SYNC") + + # Restore from backup on node2. + node1.query( + f"RESTORE DATABASE mydb ON CLUSTER 'cluster' FROM {backup_name} SETTINGS replica_num_in_backup=2" + ) + node1.query("SYSTEM SYNC REPLICA ON CLUSTER 'cluster' mydb.tbl") + + # compare parts + p1_ = node1.query("SELECT _part, * FROM mydb.tbl ORDER BY x") + p2_ = node2.query("SELECT _part, * FROM mydb.tbl ORDER BY x") + assert p1_ == p2_ + + # compare data + assert p2 == node2.query("SELECT * FROM mydb.tbl ORDER BY x") + + def test_different_tables_on_nodes(): node1.query( "CREATE TABLE tbl (`x` UInt8, `y` String) ENGINE = MergeTree ORDER BY x"