2021-12-14 20:06:34 +00:00
#!/usr/bin/env bash
# Tags: no-fasttest, no-replicated-database
# Looks like server does not listen https port in fasttest
# FIXME Replicated database executes ALTERs in separate context, so transaction info is lost
CURDIR = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
# shellcheck source=../shell_config.sh
. " $CURDIR " /../shell_config.sh
# shellcheck source=./transactions.lib
. " $CURDIR " /transactions.lib
$CLICKHOUSE_CLIENT -q "drop table if exists mt"
$CLICKHOUSE_CLIENT -q "create table mt (n int) engine=MergeTree order by tuple()"
$CLICKHOUSE_CLIENT -q "insert into mt values (1)"
tx 1 "begin transaction"
tx 2 "begin transaction"
tx 1 "insert into mt values (2)"
tx 2 "insert into mt values (3)"
2021-12-20 18:53:05 +00:00
tx 2 "alter table mt update n=n*10 where 1"
2021-12-14 20:06:34 +00:00
tx 2 "select 1, n, _part from mt order by n"
tx 1 "select 2, n, _part from mt order by n"
2021-12-20 18:53:05 +00:00
tx 1 "alter table mt update n=n+1 where 1" | grep -Eo "Serialization error" | uniq
2021-12-14 20:06:34 +00:00
tx 1 "commit" | grep -Eo "INVALID_TRANSACTION" | uniq
tx 2 "rollback"
tx 3 "begin transaction"
tx 3 "select 3, n, _part from mt order by n"
tx 4 "begin transaction"
tx 3 "insert into mt values (2)"
tx 4 "insert into mt values (3)"
tx 4 "alter table mt update n=n*2 where 1"
2021-12-20 18:53:05 +00:00
tx 3 "alter table mt update n=n+42 where 1" | grep -Eo "Serialization error" | uniq
tx 3 "insert into mt values (4)" | grep -Eo "INVALID_TRANSACTION" | uniq
2021-12-14 20:06:34 +00:00
tx 4 "insert into mt values (5)"
2021-12-20 18:53:05 +00:00
tx 3 "commit" | grep -Eo "INVALID_TRANSACTION" | uniq
2021-12-14 20:06:34 +00:00
tx 4 "commit"
tx 5 "begin transaction"
tx 5 "select 4, n, _part from mt order by n"
tx 6 "begin transaction"
2021-12-20 18:53:05 +00:00
tx 6 "alter table mt delete where n%2=1"
2021-12-23 19:02:27 +00:00
tx 6 "alter table mt drop part 'all_10_10_0_11'"
2021-12-14 20:06:34 +00:00
tx 5 "select 5, n, _part from mt order by n"
tx 5 "alter table mt drop partition id 'all'" | grep -Eo "SERIALIZATION_ERROR" | uniq
tx 6 "select 6, n, _part from mt order by n"
tx 5 "rollback"
tx 6 "insert into mt values (8)"
tx 6 "alter table mt update n=n*10 where 1"
2021-12-15 21:49:06 +00:00
tx 6 "insert into mt values (40)"
2021-12-14 20:06:34 +00:00
tx 6 "commit"
2021-12-15 21:49:06 +00:00
tx 7 "begin transaction"
tx 7 "select 7, n, _part from mt order by n"
tx 8 "begin transaction"
2021-12-24 13:14:17 +00:00
tx_async 8 "alter table mt update n = 0 where 1" >/dev/null
2022-03-31 16:31:58 +00:00
$CLICKHOUSE_CLIENT -q "kill mutation where database=currentDatabase() and mutation_id='mutation_15.txt' format Null" 2>& 1| grep -Fv "probably it finished"
2021-12-28 11:23:35 +00:00
tx_sync 8 "rollback"
2021-12-24 13:14:17 +00:00
tx 7 "optimize table mt final"
2021-12-15 21:49:06 +00:00
tx 7 "select 8, n, _part from mt order by n"
tx 10 "begin transaction"
2021-12-20 18:53:05 +00:00
tx 10 "alter table mt update n = 0 where 1" | grep -Eo "Serialization error" | uniq
2021-12-15 21:49:06 +00:00
tx 7 "alter table mt update n=n+1 where 1"
tx 10 "commit" | grep -Eo "INVALID_TRANSACTION" | uniq
tx 10 "rollback"
tx 7 "commit"
2021-12-20 18:53:05 +00:00
tx_async 11 "begin transaction"
tx_async 11 "select 9, n, _part from mt order by n"
tx_async 12 "begin transaction"
2022-03-16 19:16:26 +00:00
tx_async 11 "alter table mt update n=n+1 where 1" >/dev/null
2021-12-20 18:53:05 +00:00
tx_async 12 "alter table mt update n=n+1 where 1" >/dev/null
tx_async 11 "commit" >/dev/null
tx_async 12 "commit" >/dev/null
tx_wait 11
tx_wait 12
2021-12-15 21:49:06 +00:00
2022-03-10 21:29:58 +00:00
tx 13 "begin transaction"
tid_to_kill = $( tx 13 "select transactionID()" | grep -Po "\(.*" )
$CLICKHOUSE_CLIENT -q " select count(), any(is_readonly), any(state) from system.transactions where tid= $tid_to_kill "
tx_async 13 "alter table mt update n = 0 where 1" >/dev/null
$CLICKHOUSE_CLIENT -q " kill transaction where tid= $tid_to_kill format Null "
tx_sync 13 "rollback"
tx 14 "begin transaction"
tx 14 "select 10, n, _part from mt order by n"
2021-12-14 20:06:34 +00:00
$CLICKHOUSE_CLIENT --database_atomic_wait_for_drop_and_detach_synchronously= 0 -q "drop table mt"