mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-21 01:00:48 +00:00
46 lines
1.8 KiB
Bash
Executable File
46 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# shellcheck source=./mergetree_mutations.lib
|
|
. "$CURDIR"/mergetree_mutations.lib
|
|
|
|
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()
|
|
{
|
|
# 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%"
|
|
|
|
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
|
|
)"
|
|
res=$?
|
|
if ! [ $res -eq 0 ]; then
|
|
echo "Replicas have diverged" | tee >(cat >&2)
|
|
$CLICKHOUSE_CLIENT -q "select _table, $2, arraySort(groupArrayDistinct(_part)) from merge(currentDatabase(), '$1') group by _table" | tee >(cat >&2)
|
|
$CLICKHOUSE_CLIENT -q "select * from system.replication_queue where database=currentDatabase() and table like '$1%'" | tee >(cat >&2)
|
|
$CLICKHOUSE_CLIENT -q "select * from system.mutations where database=currentDatabase() and table like '$1%'" | tee >(cat >&2)
|
|
$CLICKHOUSE_CLIENT -q "select * from system.parts where database=currentDatabase() and table like '$1%'" | tee >(cat >&2)
|
|
fi
|
|
|
|
}
|
|
|