ClickHouse/tests/queries/0_stateless/replication.lib

46 lines
1.8 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
# shellcheck source=./mergetree_mutations.lib
. "$CURDIR"/mergetree_mutations.lib
2021-08-11 15:24:47 +00:00
function try_sync_replicas()
{
readarray -t tables_arr < <(${CLICKHOUSE_CLIENT} --query="SELECT name FROM system.tables WHERE database=currentDatabase() AND name like '$1%' AND engine like '%Replicated%'")
for t in "${tables_arr[@]}"
do
# The size of log may be big, so increase timeout.
$CLICKHOUSE_CLIENT --receive_timeout 300 -q "SYSTEM SYNC REPLICA $t" &
done
wait
echo "Replication did not hang: synced all replicas of $1"
}
function check_replication_consistency()
{
2021-08-11 15:24:47 +00:00
# Forcefully cancel mutations to avoid waiting for them to finish
${CLICKHOUSE_CLIENT} --query="KILL MUTATION WHERE database=currentDatabase() AND table like '$1%'" > /dev/null
# SYNC REPLICA is not enough if some MUTATE_PARTs are not assigned yet
wait_for_all_mutations "$1%"
2021-08-11 15:24:47 +00:00
try_sync_replicas "$1"
$CLICKHOUSE_CLIENT -q \
"SELECT
throwIf((countDistinct(data) AS c) != 1, 'Replicas have diverged'), c
FROM
(
SELECT _table, ($2) AS data
FROM merge(currentDatabase(), '$1') GROUP BY _table
2021-08-11 15:24:47 +00:00
)"
res=$?
if ! [ $res -eq 0 ]; then
echo "Replicas have diverged" | tee /dev/stderr
$CLICKHOUSE_CLIENT -q "select _table, $2, arraySort(groupArrayDistinct(_part)) from merge(currentDatabase(), '$1') group by _table" | tee /dev/stderr
$CLICKHOUSE_CLIENT -q "select * from system.replication_queue where database=currentDatabase() and table like '$1%'" | tee /dev/stderr
$CLICKHOUSE_CLIENT -q "select * from system.mutations where database=currentDatabase() and table like '$1%'" | tee /dev/stderr
$CLICKHOUSE_CLIENT -q "select * from system.parts where database=currentDatabase() and table like '$1%'" | tee /dev/stderr
fi
}