2021-04-08 17:20:45 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-07-15 13:36:01 +00:00
|
|
|
# Tags: long, no-ordinary-database
|
2021-04-08 17:20:45 +00:00
|
|
|
|
2021-11-08 18:56:09 +00:00
|
|
|
# shellcheck disable=SC2015
|
2023-03-01 15:41:51 +00:00
|
|
|
# shellcheck disable=SC2119
|
2021-11-08 18:56:09 +00:00
|
|
|
|
2021-04-08 17:20:45 +00:00
|
|
|
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";
|
2021-06-11 12:14:38 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query "CREATE TABLE mt (n Int8, m Int8) ENGINE=MergeTree ORDER BY n PARTITION BY 0 < n SETTINGS old_parts_lifetime=0";
|
2021-04-08 17:20:45 +00:00
|
|
|
|
|
|
|
function thread_insert_commit()
|
|
|
|
{
|
|
|
|
for i in {1..50}; do
|
|
|
|
$CLICKHOUSE_CLIENT --multiquery --query "
|
|
|
|
BEGIN TRANSACTION;
|
2022-03-16 19:16:26 +00:00
|
|
|
INSERT INTO mt VALUES /* ($i, $1) */ ($i, $1);
|
|
|
|
INSERT INTO mt VALUES /* (-$i, $1) */ (-$i, $1);
|
2021-04-08 17:20:45 +00:00
|
|
|
COMMIT;";
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function thread_insert_rollback()
|
|
|
|
{
|
|
|
|
for _ in {1..50}; do
|
|
|
|
$CLICKHOUSE_CLIENT --multiquery --query "
|
|
|
|
BEGIN TRANSACTION;
|
2022-03-16 19:16:26 +00:00
|
|
|
INSERT INTO mt VALUES /* (42, $1) */ (42, $1);
|
2021-04-08 17:20:45 +00:00
|
|
|
ROLLBACK;";
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function thread_select()
|
|
|
|
{
|
2022-06-03 10:29:25 +00:00
|
|
|
while true; do
|
2022-07-18 15:47:35 +00:00
|
|
|
# The first and the last queries must get the same result
|
2021-04-08 17:20:45 +00:00
|
|
|
$CLICKHOUSE_CLIENT --multiquery --query "
|
|
|
|
BEGIN TRANSACTION;
|
2022-07-18 15:31:36 +00:00
|
|
|
SET throw_on_unsupported_query_inside_transaction=0;
|
|
|
|
CREATE TEMPORARY TABLE tmp AS SELECT arraySort(groupArray(n)), arraySort(groupArray(m)), arraySort(groupArray(_part)) FROM mt FORMAT Null;
|
2021-04-08 17:20:45 +00:00
|
|
|
SELECT throwIf((SELECT sum(n) FROM mt) != 0) FORMAT Null;
|
|
|
|
SELECT throwIf((SELECT count() FROM mt) % 2 != 0) FORMAT Null;
|
2022-07-18 15:31:36 +00:00
|
|
|
select throwIf((SELECT * FROM tmp) != (SELECT arraySort(groupArray(n)), arraySort(groupArray(m)), arraySort(groupArray(_part)) FROM mt)) FORMAT Null;
|
|
|
|
COMMIT;"
|
2021-04-08 17:20:45 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
thread_insert_commit 1 & PID_1=$!
|
|
|
|
thread_insert_commit 2 & PID_2=$!
|
|
|
|
thread_insert_rollback 3 & PID_3=$!
|
|
|
|
thread_select & PID_4=$!
|
|
|
|
wait $PID_1 && wait $PID_2 && wait $PID_3
|
2022-06-03 10:49:16 +00:00
|
|
|
kill -TERM $PID_4
|
2021-04-08 17:20:45 +00:00
|
|
|
wait
|
2023-06-30 13:47:31 +00:00
|
|
|
wait_for_queries_to_finish 40
|
2021-04-08 17:20:45 +00:00
|
|
|
|
|
|
|
$CLICKHOUSE_CLIENT --multiquery --query "
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
SELECT count(), sum(n), sum(m=1), sum(m=2), sum(m=3) FROM mt;";
|
|
|
|
|
2021-06-04 09:26:47 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query "SELECT count(), sum(n), sum(m=1), sum(m=2), sum(m=3) FROM mt;"
|
|
|
|
|
2021-05-18 17:07:29 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query "DROP TABLE mt";
|