From c92e1f5a0692b34bfe55df80a5eee2f57480d1af Mon Sep 17 00:00:00 2001 From: Jayme Bird Date: Mon, 8 Jan 2024 10:03:28 +0000 Subject: [PATCH] add test --- ...eplica_lightweight_from_modifier.reference | 2 + ..._sync_replica_lightweight_from_modifier.sh | 78 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tests/queries/0_stateless/02962_system_sync_replica_lightweight_from_modifier.reference create mode 100755 tests/queries/0_stateless/02962_system_sync_replica_lightweight_from_modifier.sh diff --git a/tests/queries/0_stateless/02962_system_sync_replica_lightweight_from_modifier.reference b/tests/queries/0_stateless/02962_system_sync_replica_lightweight_from_modifier.reference new file mode 100644 index 00000000000..722ebcdc661 --- /dev/null +++ b/tests/queries/0_stateless/02962_system_sync_replica_lightweight_from_modifier.reference @@ -0,0 +1,2 @@ +Test completed +Data consistency check passed diff --git a/tests/queries/0_stateless/02962_system_sync_replica_lightweight_from_modifier.sh b/tests/queries/0_stateless/02962_system_sync_replica_lightweight_from_modifier.sh new file mode 100755 index 00000000000..39f82d9ef2d --- /dev/null +++ b/tests/queries/0_stateless/02962_system_sync_replica_lightweight_from_modifier.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +# Tags: zookeeper, no-parallel, no-fasttest + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CURDIR"/../shell_config.sh +# shellcheck source=./replication.lib +. "$CURDIR"/replication.lib + +TOTAL_REPLICAS=10 +REPLICAS_TO_DROP=7 + +for i in $(seq $TOTAL_REPLICAS); do + $CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS test_table_$i" + $CLICKHOUSE_CLIENT --query "CREATE TABLE test_table_$i (key UInt64, value UInt8) ENGINE = ReplicatedMergeTree('/clickhouse/tables/$CLICKHOUSE_TEST_ZOOKEEPER_PREFIX/test_table', '$i') ORDER BY key" +done + +function insert_thread() { + while true; do + REPLICA=$(($RANDOM % $TOTAL_REPLICAS + 1)) + $CLICKHOUSE_CLIENT --query "INSERT INTO test_table_$REPLICA VALUES ($RANDOM, $RANDOM % 255)" + sleep 0.$RANDOM + done +} + +function sync_and_drop_replicas() { + for i in $(seq $REPLICAS_TO_DROP); do + $CLICKHOUSE_CLIENT --query "SYSTEM SYNC REPLICA LIGHTWEIGHT test_table_$i FROM '$i'" + $CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS test_table_$i" + done +} + +function optimize_thread() { + while true; do + REPLICA=$(($RANDOM % $TOTAL_REPLICAS + 1)) + $CLICKHOUSE_CLIENT --query "OPTIMIZE TABLE test_table_$REPLICA FINAL" + sleep 0.$RANDOM + done +} + +function mutations_thread() { + while true; do + REPLICA=$(($RANDOM % $TOTAL_REPLICAS + 1)) + CONDITION="key % 2 = 0" + $CLICKHOUSE_CLIENT --query "ALTER TABLE test_table_$REPLICA DELETE WHERE $CONDITION" + sleep 0.$RANDOM + done +} + +export -f insert_thread +export -f sync_and_drop_replicas +export -f optimize_thread +export -f mutations_thread + +TIMEOUT=30 + +timeout $TIMEOUT bash -c insert_thread 2> /dev/null & +timeout $TIMEOUT bash -c sync_and_drop_replicas 2> /dev/null & +timeout $TIMEOUT bash -c optimize_thread 2> /dev/null & +timeout $TIMEOUT bash -c mutations_thread 2> /dev/null & + +wait + +echo "Test completed" + +lost_parts_count=$($CLICKHOUSE_CLIENT --query "SELECT SUM(lost_part_count) FROM system.replicas WHERE database=currentDatabase()") +if [ "$lost_parts_count" -ne 0 ]; then + echo "Data consistency check failed: lost parts count is not zero" + exit 1 +fi + +echo "Data consistency check passed" + +for i in $(seq $TOTAL_REPLICAS); do + if [ $i -gt $REPLICAS_TO_DROP ]; then + $CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS test_table_$i" + fi +done