2021-11-17 18:14:14 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-12-20 18:53:05 +00:00
|
|
|
# Useful to run
|
2021-11-17 18:14:14 +00:00
|
|
|
function tx()
|
|
|
|
{
|
|
|
|
tx_num=$1
|
|
|
|
query=$2
|
|
|
|
|
2021-12-20 18:53:05 +00:00
|
|
|
session="${CLICKHOUSE_TEST_ZOOKEEPER_PREFIX}_tx$tx_num"
|
|
|
|
query_id="${session}_${RANDOM}"
|
2021-11-17 18:14:14 +00:00
|
|
|
url_without_session="https://${CLICKHOUSE_HOST}:${CLICKHOUSE_PORT_HTTPS}/?"
|
2021-12-20 18:53:05 +00:00
|
|
|
url="${url_without_session}session_id=$session&query_id=$query_id&database=$CLICKHOUSE_DATABASE"
|
2021-11-17 18:14:14 +00:00
|
|
|
|
2021-12-20 18:53:05 +00:00
|
|
|
${CLICKHOUSE_CURL} -m 60 -sSk "$url" --data "$query" | sed "s/^/tx$tx_num\t/"
|
2021-11-17 18:14:14 +00:00
|
|
|
}
|
|
|
|
|
2021-12-20 18:53:05 +00:00
|
|
|
function tx_wait() {
|
|
|
|
tx_num=$1
|
|
|
|
|
|
|
|
session="${CLICKHOUSE_TEST_ZOOKEEPER_PREFIX}_tx$tx_num"
|
|
|
|
|
|
|
|
# wait for previous query in transaction
|
|
|
|
count=0
|
|
|
|
while [[ $($CLICKHOUSE_CLIENT -q "SELECT count() FROM system.processes WHERE query_id LIKE '$session%'") -gt 0 ]]; do
|
|
|
|
sleep 0.5
|
|
|
|
count=$((count+1))
|
|
|
|
if [ "$count" -gt 120 ]; then
|
|
|
|
echo "timeout while waiting for $tx_num"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done;
|
|
|
|
}
|
|
|
|
|
|
|
|
function tx_async()
|
|
|
|
{
|
|
|
|
tx_num=$1
|
|
|
|
query=$2
|
|
|
|
|
|
|
|
tx_wait $tx_num
|
|
|
|
|
|
|
|
session="${CLICKHOUSE_TEST_ZOOKEEPER_PREFIX}_tx$tx_num"
|
|
|
|
query_id="${session}_${RANDOM}"
|
|
|
|
url_without_session="https://${CLICKHOUSE_HOST}:${CLICKHOUSE_PORT_HTTPS}/?"
|
|
|
|
url="${url_without_session}session_id=$session&query_id=$query_id&database=$CLICKHOUSE_DATABASE"
|
|
|
|
|
|
|
|
# run query asynchronously
|
|
|
|
${CLICKHOUSE_CURL} -m 60 -sSk "$url" --data "$query" | sed "s/^/tx$tx_num\t/" &
|
|
|
|
}
|