fix deadlock in async inserts via native protocol

This commit is contained in:
Anton Popov 2024-03-07 17:42:50 +00:00
parent 820916b925
commit b9d6f4b3ed
3 changed files with 16 additions and 1 deletions

View File

@ -936,6 +936,8 @@ void TCPHandler::processInsertQuery()
auto result = processAsyncInsertQuery(*insert_queue);
if (result.status == AsynchronousInsertQueue::PushResult::OK)
{
/// Reset pipeline because it may hold write lock for some storages.
state.io.pipeline.reset();
if (settings.wait_for_async_insert)
{
size_t timeout_ms = settings.wait_for_async_insert_timeout.totalMilliseconds();
@ -968,7 +970,7 @@ void TCPHandler::processInsertQuery()
else
{
PushingPipelineExecutor executor(state.io.pipeline);
run_executor(executor, processed_block);
run_executor(executor, std::move(processed_block));
}
sendInsertProfileEvents();

View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
$CLICKHOUSE_CLIENT --query "CREATE TABLE t_async_insert_deadlock (a UInt64) ENGINE = Log"
echo '{"a": 1}' | $CLICKHOUSE_CLIENT --async_insert 1 --wait_for_async_insert 1 --query "INSERT INTO t_async_insert_deadlock FORMAT JSONEachRow"
$CLICKHOUSE_CLIENT --query "SELECT * FROM t_async_insert_deadlock ORDER BY a"
$CLICKHOUSE_CLIENT --query "DROP TABLE t_async_insert_deadlock"