ClickHouse/tests/queries/0_stateless/01133_begin_commit_race.sh
2022-05-20 22:10:01 +02:00

59 lines
1.8 KiB
Bash
Executable File

#!/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()
{
$CLICKHOUSE_CLIENT --multiquery --query "
SET wait_changes_become_visible_after_commit_mode='wait';
BEGIN TRANSACTION;
COMMIT;" 2>&1| grep -Fa "Exception: " | grep -Fv UNKNOWN_STATUS_OF_TRANSACTION
}
function begin_rollback_readonly()
{
$CLICKHOUSE_CLIENT --wait_changes_become_visible_after_commit_mode=wait_unknown --multiquery --query "
BEGIN TRANSACTION;
SET TRANSACTION SNAPSHOT 42;
ROLLBACK;"
}
function begin_insert_commit()
{
$CLICKHOUSE_CLIENT --wait_changes_become_visible_after_commit_mode=async --multiquery --query "
BEGIN TRANSACTION;
INSERT INTO mt VALUES ($RANDOM);
COMMIT;" 2>&1| grep -Fa "Exception: " | grep -Fv UNKNOWN_STATUS_OF_TRANSACTION
}
function introspection()
{
$CLICKHOUSE_CLIENT -q "SELECT * FROM system.transactions FORMAT Null"
$CLICKHOUSE_CLIENT -q "SELECT transactionLatestSnapshot(), transactionOldestSnapshot() FORMAT Null"
}
export -f begin_commit_readonly
export -f begin_rollback_readonly
export -f begin_insert_commit
export -f introspection
TIMEOUT=20
clickhouse_client_loop_timeout $TIMEOUT begin_commit_readonly &
clickhouse_client_loop_timeout $TIMEOUT begin_rollback_readonly &
clickhouse_client_loop_timeout $TIMEOUT begin_insert_commit &
clickhouse_client_loop_timeout $TIMEOUT introspection &
wait
$CLICKHOUSE_CLIENT --query "DROP TABLE mt";