Fix shellcheck issues in durability-test.sh

This commit is contained in:
Mikhail f. Shiryaev 2024-03-14 13:56:43 +01:00
parent a5331ea544
commit 070f7bee9b
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4

View File

@ -15,7 +15,6 @@ Usage:
URL=http://cloud-images.ubuntu.com/bionic/current URL=http://cloud-images.ubuntu.com/bionic/current
IMAGE=bionic-server-cloudimg-amd64.img IMAGE=bionic-server-cloudimg-amd64.img
SSH_PORT=11022 SSH_PORT=11022
CLICKHOUSE_PORT=9090
PASSWORD=root PASSWORD=root
TABLE_NAME=$1 TABLE_NAME=$1
@ -34,19 +33,18 @@ function run()
function copy() function copy()
{ {
sshpass -p $PASSWORD scp -r -P $SSH_PORT $1 root@localhost:$2 2>/dev/null sshpass -p $PASSWORD scp -r -P $SSH_PORT "$1" "root@localhost:$2" 2>/dev/null
} }
function wait_vm_for_start() function wait_vm_for_start()
{ {
echo "Waiting until VM started..." echo "Waiting until VM started..."
started=0 started=0
for i in {0..100}; do for _ in {0..100}; do
run "exit" if run "exit"; then
if [ $? -eq 0 ]; then
started=1 started=1
break break
fi fi
sleep 1s sleep 1s
done done
@ -62,9 +60,8 @@ function wait_clickhouse_for_start()
{ {
echo "Waiting until ClickHouse started..." echo "Waiting until ClickHouse started..."
started=0 started=0
for i in {0..30}; do for _ in {0..30}; do
run "clickhouse client --query 'select 1'" > /dev/null if run "clickhouse client --query 'select 1'" > /dev/null; then
if [ $? -eq 0 ]; then
started=1 started=1
break break
fi fi
@ -105,11 +102,11 @@ if [[ -z $CLICKHOUSE_CONFIG_DIR ]]; then
CLICKHOUSE_CONFIG_DIR=/etc/clickhouse-server CLICKHOUSE_CONFIG_DIR=/etc/clickhouse-server
fi fi
echo "Using ClickHouse binary:" $CLICKHOUSE_BINARY echo "Using ClickHouse binary: $CLICKHOUSE_BINARY"
echo "Using ClickHouse config from:" $CLICKHOUSE_CONFIG_DIR echo "Using ClickHouse config from: $CLICKHOUSE_CONFIG_DIR"
copy $CLICKHOUSE_BINARY /usr/bin copy "$CLICKHOUSE_BINARY" /usr/bin
copy $CLICKHOUSE_CONFIG_DIR /etc copy "$CLICKHOUSE_CONFIG_DIR" /etc
run "mv /etc/$CLICKHOUSE_CONFIG_DIR /etc/clickhouse-server" run "mv /etc/$CLICKHOUSE_CONFIG_DIR /etc/clickhouse-server"
echo "Prepared VM" echo "Prepared VM"
@ -118,23 +115,23 @@ echo "Starting ClickHouse"
run "clickhouse server --config-file=/etc/clickhouse-server/config.xml > clickhouse-server.log 2>&1" & run "clickhouse server --config-file=/etc/clickhouse-server/config.xml > clickhouse-server.log 2>&1" &
wait_clickhouse_for_start wait_clickhouse_for_start
query=`cat $CREATE_QUERY` query=$(cat "$CREATE_QUERY")
echo "Executing query:" $query echo "Executing query: $query"
run "clickhouse client --query '$query'" run "clickhouse client --query '$query'"
query=`cat $INSERT_QUERY` query=$(cat "$INSERT_QUERY")
echo "Will run in a loop query: " $query echo "Will run in a loop query: $query"
run "clickhouse benchmark <<< '$query' -c 8" & run "clickhouse benchmark <<< '$query' -c 8" &
echo "Running queries" echo "Running queries"
pid=`pidof qemu-system-x86_64` pid=$(pidof qemu-system-x86_64)
sec=$(( (RANDOM % 5) + 25 )) sec=$(( (RANDOM % 5) + 25 ))
ms=$(( RANDOM % 1000 )) ms=$(( RANDOM % 1000 ))
echo "Will kill VM in $sec.$ms sec" echo "Will kill VM in $sec.$ms sec"
sleep $sec.$ms sleep $sec.$ms
kill -9 $pid kill -9 "$pid"
echo "Restarting" echo "Restarting"
@ -147,22 +144,22 @@ run "rm -r *data/system"
run "clickhouse server --config-file=/etc/clickhouse-server/config.xml > clickhouse-server.log 2>&1" & run "clickhouse server --config-file=/etc/clickhouse-server/config.xml > clickhouse-server.log 2>&1" &
wait_clickhouse_for_start wait_clickhouse_for_start
pid=`pidof qemu-system-x86_64` pid=$(pidof qemu-system-x86_64)
result=`run "grep $TABLE_NAME clickhouse-server.log | grep 'Caught exception while loading metadata'"` result=$(run "grep $TABLE_NAME clickhouse-server.log | grep 'Caught exception while loading metadata'")
if [[ -n $result ]]; then if [[ -n $result ]]; then
echo "FAIL. Can't attach table:" echo "FAIL. Can't attach table:"
echo $result echo "$result"
kill -9 $pid kill -9 "$pid"
exit 1 exit 1
fi fi
result=`run "grep $TABLE_NAME clickhouse-server.log | grep 'Considering to remove broken part'"` result=$(run "grep $TABLE_NAME clickhouse-server.log | grep 'Considering to remove broken part'")
if [[ -n $result ]]; then if [[ -n $result ]]; then
echo "FAIL. Have broken parts:" echo "FAIL. Have broken parts:"
echo $result echo "$result"
kill -9 $pid kill -9 "$pid"
exit 1 exit 1
fi fi
kill -9 $pid kill -9 "$pid"
echo OK echo OK