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()
|
|
|
|
{
|
|
|
|
$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-20 10:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function begin_rollback_readonly()
|
|
|
|
{
|
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-20 10:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function begin_insert_commit()
|
|
|
|
{
|
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-20 10:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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";
|