2018-06-05 17:43:10 +00:00
|
|
|
#!/usr/bin/env bash
|
2017-10-06 11:29:58 +00:00
|
|
|
#set -e
|
|
|
|
|
2017-11-02 14:14:16 +00:00
|
|
|
[[ -n "$1" ]] && host="$1" || host="localhost"
|
2018-02-21 17:06:29 +00:00
|
|
|
[[ -n "$2" ]] && min_timestamp="$2" || min_timestamp=$(( $(date +%s) - 60 ))
|
|
|
|
[[ -n "$3" ]] && max_timestamp="$3" || max_timestamp=$(( $(date +%s) + 60 ))
|
2018-09-07 11:51:51 +00:00
|
|
|
[[ -n "$4" ]] && client="$4" || client="clickhouse-client"
|
2017-10-06 11:29:58 +00:00
|
|
|
|
|
|
|
timestamps=`seq $min_timestamp $max_timestamp`
|
|
|
|
|
|
|
|
function reliable_insert {
|
|
|
|
local ts="$1"
|
|
|
|
num_tries=0
|
|
|
|
while true; do
|
|
|
|
if (( $num_tries > 20 )); then
|
|
|
|
echo "Too many retries" 1>&2
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#echo clickhouse-client --host $host -q "INSERT INTO simple VALUES (0, $ts, '$ts')"
|
2018-09-07 11:51:51 +00:00
|
|
|
res=`$client --host $host -q "INSERT INTO simple VALUES (0, $ts, '$ts')" 2>&1`
|
2017-10-06 11:29:58 +00:00
|
|
|
rt=$?
|
|
|
|
num_tries=$(($num_tries+1))
|
|
|
|
|
|
|
|
if (( $rt == 0 )); then break; fi
|
|
|
|
if [[ $res == *"Code: 319. "*"Unknown status, client must retry"* || $res == *"Code: 999. "* ]]; then
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
echo FAIL "$res" 1>&2
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
done;
|
|
|
|
}
|
|
|
|
|
|
|
|
for i in $timestamps; do
|
|
|
|
|
|
|
|
cur_timestamp=$(date +%s)
|
|
|
|
while (( $cur_timestamp < $i )); do
|
|
|
|
ts=`shuf -i $min_timestamp-$cur_timestamp -n 1`
|
|
|
|
reliable_insert "$ts"
|
|
|
|
cur_timestamp=$(date +%s)
|
|
|
|
done
|
|
|
|
|
|
|
|
reliable_insert "$i"
|
2017-11-20 19:33:12 +00:00
|
|
|
done
|
|
|
|
sleep 1
|