This commit is contained in:
Alexander Tokmakov 2022-06-14 16:11:16 +02:00
parent 86c8d0ad4d
commit b39bd3c4e0
6 changed files with 28 additions and 1 deletions

View File

@ -80,6 +80,16 @@ BlockIO InterpreterTransactionControlQuery::executeCommit(ContextMutablePtr sess
/// It's useful for testing. It allows to enable fault injection (after commit) without breaking tests.
txn->waitStateChange(Tx::CommittingCSN);
CSN csn_changed_state = txn->getCSN();
if (csn_changed_state == Tx::UnknownCSN)
{
/// CommittingCSN -> UnknownCSN -> RolledBackCSN
/// It's posible if connection was lost before commit
/// (maybe we should get rid of intermediate UnknownCSN in this transition)
txn->waitStateChange(Tx::UnknownCSN);
chassert(txn->getCSN() == Tx::RolledBackCSN);
}
if (txn->getState() == MergeTreeTransaction::ROLLED_BACK)
throw Exception(ErrorCodes::INVALID_TRANSACTION, "Transaction {} was rolled back", txn->tid);
if (txn->getState() != MergeTreeTransaction::COMMITTED)

View File

@ -121,6 +121,7 @@ wait $PID_3 && wait $PID_4
kill -TERM $PID_1
kill -TERM $PID_2
wait
wait_for_queries_to_finish
$CLICKHOUSE_CLIENT -q "SELECT type, count(n) = countDistinct(n) FROM merge(currentDatabase(), '') GROUP BY type ORDER BY type"
$CLICKHOUSE_CLIENT -q "SELECT DISTINCT arraySort(groupArrayIf(n, type=1)) = arraySort(groupArrayIf(n, type=2)) FROM merge(currentDatabase(), '') GROUP BY _table ORDER BY _table"

View File

@ -140,6 +140,7 @@ kill -TERM $PID_6
kill -TERM $PID_7
kill -TERM $PID_8
wait
wait_for_queries_to_finish
$CLICKHOUSE_CLIENT --multiquery --query "
BEGIN TRANSACTION;

View File

@ -55,6 +55,7 @@ thread_select & PID_4=$!
wait $PID_1 && wait $PID_2 && wait $PID_3
kill -TERM $PID_4
wait
wait_for_queries_to_finish
$CLICKHOUSE_CLIENT --multiquery --query "
BEGIN TRANSACTION;

View File

@ -44,7 +44,7 @@ function check_replication_consistency()
num_tries=0
while [[ $($CLICKHOUSE_CLIENT -q "SELECT count() FROM system.processes WHERE current_database=currentDatabase() AND query LIKE '%$table_name_prefix%'") -ne 1 ]]; do
sleep 0.5;
num_tries=$((num_tries-1))
num_tries=$((num_tries+1))
if [ $num_tries -eq 100 ]; then
$CLICKHOUSE_CLIENT -q "SELECT count() FROM system.processes WHERE current_database=currentDatabase() AND query LIKE '%$table_name_prefix%' FORMAT Vertical"
break

View File

@ -129,3 +129,17 @@ function clickhouse_client_removed_host_parameter()
# bash regex magic is arcane, but version dependant and weak; sed or awk are not really portable.
$(echo "$CLICKHOUSE_CLIENT" | python3 -c "import sys, re; print(re.sub('--host(\s+|=)[^\s]+', '', sys.stdin.read()))") "$@"
}
function wait_for_queries_to_finish()
{
# Wait for all queries to finish (query may still be running if thread is killed by timeout)
num_tries=0
while [[ $($CLICKHOUSE_CLIENT -q "SELECT count() FROM system.processes WHERE current_database=currentDatabase() AND query NOT LIKE '%system.processes%'") -ne 0 ]]; do
sleep 0.5;
num_tries=$((num_tries+1))
if [ $num_tries -eq 20 ]; then
$CLICKHOUSE_CLIENT -q "SELECT count() FROM system.processes WHERE current_database=currentDatabase() AND query NOT LIKE '%system.processes%' FORMAT Vertical"
break
fi
done
}