ClickHouse/tests/queries/0_stateless/01133_begin_commit_race.sh

67 lines
1.8 KiB
Bash
Raw Normal View History

2022-05-20 10:41:44 +00:00
#!/usr/bin/env bash
# Tags: long
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
set -e
$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS mt";
$CLICKHOUSE_CLIENT --query "CREATE TABLE mt (n Int64) ENGINE=MergeTree ORDER BY n SETTINGS old_parts_lifetime=0";
function begin_commit_readonly()
{
2022-05-28 17:40:26 +00:00
while true; do
2022-05-20 10:41:44 +00:00
$CLICKHOUSE_CLIENT --multiquery --query "
2022-05-20 20:08:46 +00:00
SET wait_changes_become_visible_after_commit_mode='wait';
2022-05-20 10:41:44 +00:00
BEGIN TRANSACTION;
2022-05-20 20:08:46 +00:00
COMMIT;" 2>&1| grep -Fa "Exception: " | grep -Fv UNKNOWN_STATUS_OF_TRANSACTION
2022-05-28 17:40:26 +00:00
done
2022-05-20 10:41:44 +00:00
}
function begin_rollback_readonly()
{
2022-05-28 17:40:26 +00:00
while true; do
2022-05-20 20:08:46 +00:00
$CLICKHOUSE_CLIENT --wait_changes_become_visible_after_commit_mode=wait_unknown --multiquery --query "
2022-05-20 10:41:44 +00:00
BEGIN TRANSACTION;
2022-05-20 20:08:46 +00:00
SET TRANSACTION SNAPSHOT 42;
ROLLBACK;"
2022-05-28 17:40:26 +00:00
done
2022-05-20 10:41:44 +00:00
}
function begin_insert_commit()
{
2022-05-28 17:40:26 +00:00
while true; do
2022-05-20 20:08:46 +00:00
$CLICKHOUSE_CLIENT --wait_changes_become_visible_after_commit_mode=async --multiquery --query "
2022-05-20 10:41:44 +00:00
BEGIN TRANSACTION;
INSERT INTO mt VALUES ($RANDOM);
2022-05-20 20:08:46 +00:00
COMMIT;" 2>&1| grep -Fa "Exception: " | grep -Fv UNKNOWN_STATUS_OF_TRANSACTION
2022-05-28 17:40:26 +00:00
done
2022-05-20 10:41:44 +00:00
}
function introspection()
{
2022-05-28 17:40:26 +00:00
while true; do
2022-05-20 10:41:44 +00:00
$CLICKHOUSE_CLIENT -q "SELECT * FROM system.transactions FORMAT Null"
$CLICKHOUSE_CLIENT -q "SELECT transactionLatestSnapshot(), transactionOldestSnapshot() FORMAT Null"
2022-05-28 17:40:26 +00:00
done
2022-05-20 10:41:44 +00:00
}
export -f begin_commit_readonly
export -f begin_rollback_readonly
export -f begin_insert_commit
export -f introspection
TIMEOUT=20
2022-05-28 17:40:26 +00:00
timeout $TIMEOUT bash -c begin_commit_readonly &
timeout $TIMEOUT bash -c begin_rollback_readonly &
timeout $TIMEOUT bash -c begin_insert_commit &
timeout $TIMEOUT bash -c introspection &
2022-05-20 10:41:44 +00:00
wait
$CLICKHOUSE_CLIENT --query "DROP TABLE mt";