2020-07-14 23:00:45 +00:00
#!/usr/bin/env bash
CURDIR = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
. $CURDIR /../shell_config.sh
2020-07-17 06:21:51 +00:00
# Check that if we have one inactive replica and a huge number of INSERTs to active replicas,
2020-07-14 23:00:45 +00:00
# the number of nodes in ZooKeeper does not grow unbounded.
$CLICKHOUSE_CLIENT -n --query "
DROP TABLE IF EXISTS r1;
DROP TABLE IF EXISTS r2;
2020-07-17 06:21:51 +00:00
CREATE TABLE r1 ( x UInt64) ENGINE = ReplicatedMergeTree( '/clickhouse/tables/r' , '1' ) ORDER BY x SETTINGS old_parts_lifetime = 1, cleanup_delay_period = 0, cleanup_delay_period_random_add = 1, parts_to_throw_insert = 100000, max_replicated_logs_to_keep = 10;
CREATE TABLE r2 ( x UInt64) ENGINE = ReplicatedMergeTree( '/clickhouse/tables/r' , '2' ) ORDER BY x SETTINGS old_parts_lifetime = 1, cleanup_delay_period = 0, cleanup_delay_period_random_add = 1, parts_to_throw_insert = 100000, max_replicated_logs_to_keep = 10;
2020-07-14 23:00:45 +00:00
DETACH TABLE r2;
"
$CLICKHOUSE_CLIENT --max_block_size 1 --min_insert_block_size_rows 1 --min_insert_block_size_bytes 1 --max_insert_threads 16 --query "INSERT INTO r1 SELECT * FROM numbers_mt(10000)"
2020-07-17 06:21:51 +00:00
# Now wait for cleanup thread
2020-08-08 23:22:56 +00:00
for _ in { 1..60} ; do
2020-07-17 06:21:51 +00:00
$CLICKHOUSE_CLIENT --query "SYSTEM FLUSH LOGS"
2020-07-31 20:58:08 +00:00
[ [ $( $CLICKHOUSE_CLIENT --query "SELECT sum(toUInt32(extract(message, 'Removed (\d+) old log entries'))) FROM system.text_log WHERE event_date >= yesterday() AND logger_name LIKE '%' || currentDatabase() || '%r1%(ReplicatedMergeTreeCleanupThread)%' AND message LIKE '%Removed % old log entries%'" ) -gt 9900 ] ] && break;
2020-07-17 06:21:51 +00:00
sleep 1
done
2020-07-31 20:58:08 +00:00
$CLICKHOUSE_CLIENT --query "SELECT numChildren < 2500 FROM system.zookeeper WHERE path = '/clickhouse/tables/r' AND name = 'log'" ;
2020-07-14 23:00:45 +00:00
echo -e '\n---\n' ;
2020-07-30 20:53:17 +00:00
$CLICKHOUSE_CLIENT --query "SELECT value FROM system.zookeeper WHERE path = '/clickhouse/tables/r/replicas/1' AND name = 'is_lost'" ;
$CLICKHOUSE_CLIENT --query "SELECT value FROM system.zookeeper WHERE path = '/clickhouse/tables/r/replicas/2' AND name = 'is_lost'" ;
2020-07-14 23:00:45 +00:00
echo -e '\n---\n' ;
$CLICKHOUSE_CLIENT --query "ATTACH TABLE r2"
2020-07-31 11:17:02 +00:00
$CLICKHOUSE_CLIENT --receive_timeout 600 --query "SYSTEM SYNC REPLICA r2" # Need to increase timeout, otherwise it timed out in debug build
2020-07-14 23:00:45 +00:00
2020-07-30 20:53:17 +00:00
$CLICKHOUSE_CLIENT --query "SELECT value FROM system.zookeeper WHERE path = '/clickhouse/tables/r/replicas/2' AND name = 'is_lost'" ;
2020-07-14 23:00:45 +00:00
$CLICKHOUSE_CLIENT -n --query "
DROP TABLE IF EXISTS r1;
DROP TABLE IF EXISTS r2;
"