mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 00:52:02 +00:00
Merge pull request #22427 from ClickHouse/protocol-break-oom
Better exception message in client in case of exception while writing blocks
This commit is contained in:
commit
28c7980fba
@ -1409,22 +1409,49 @@ void TCPHandler::sendData(const Block & block)
|
||||
{
|
||||
initBlockOutput(block);
|
||||
|
||||
writeVarUInt(Protocol::Server::Data, *out);
|
||||
/// Send external table name (empty name is the main table)
|
||||
writeStringBinary("", *out);
|
||||
auto prev_bytes_written_out = out->count();
|
||||
auto prev_bytes_written_compressed_out = state.maybe_compressed_out->count();
|
||||
|
||||
/// For testing hedged requests
|
||||
const Settings & settings = query_context->getSettingsRef();
|
||||
if (block.rows() > 0 && settings.sleep_in_send_data_ms.totalMilliseconds())
|
||||
try
|
||||
{
|
||||
out->next();
|
||||
std::chrono::milliseconds ms(settings.sleep_in_send_data_ms.totalMilliseconds());
|
||||
std::this_thread::sleep_for(ms);
|
||||
}
|
||||
writeVarUInt(Protocol::Server::Data, *out);
|
||||
/// Send external table name (empty name is the main table)
|
||||
writeStringBinary("", *out);
|
||||
|
||||
state.block_out->write(block);
|
||||
state.maybe_compressed_out->next();
|
||||
out->next();
|
||||
/// For testing hedged requests
|
||||
const Settings & settings = query_context->getSettingsRef();
|
||||
if (block.rows() > 0 && settings.sleep_in_send_data_ms.totalMilliseconds())
|
||||
{
|
||||
out->next();
|
||||
std::chrono::milliseconds ms(settings.sleep_in_send_data_ms.totalMilliseconds());
|
||||
std::this_thread::sleep_for(ms);
|
||||
}
|
||||
|
||||
state.block_out->write(block);
|
||||
state.maybe_compressed_out->next();
|
||||
out->next();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
/// In case of unsuccessful write, if the buffer with written data was not flushed,
|
||||
/// we will rollback write to avoid breaking the protocol.
|
||||
/// (otherwise the client will not be able to receive exception after unfinished data
|
||||
/// as it will expect the continuation of the data).
|
||||
/// It looks like hangs on client side or a message like "Data compressed with different methods".
|
||||
|
||||
if (state.compression == Protocol::Compression::Enable)
|
||||
{
|
||||
auto extra_bytes_written_compressed = state.maybe_compressed_out->count() - prev_bytes_written_compressed_out;
|
||||
if (state.maybe_compressed_out->offset() >= extra_bytes_written_compressed)
|
||||
state.maybe_compressed_out->position() -= extra_bytes_written_compressed;
|
||||
}
|
||||
|
||||
auto extra_bytes_written_out = out->count() - prev_bytes_written_out;
|
||||
if (out->offset() >= extra_bytes_written_out)
|
||||
out->position() -= extra_bytes_written_out;
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,2 @@
|
||||
SET max_memory_usage = '1G';
|
||||
SELECT range(65535) FROM system.one ARRAY JOIN range(65536) AS number; -- { serverError 241 }
|
@ -0,0 +1,2 @@
|
||||
Code: 241
|
||||
Code: 241
|
8
tests/queries/0_stateless/01785_parallel_formatting_memory.sh
Executable file
8
tests/queries/0_stateless/01785_parallel_formatting_memory.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
# shellcheck source=../shell_config.sh
|
||||
. "$CUR_DIR"/../shell_config.sh
|
||||
|
||||
$CLICKHOUSE_CLIENT --compress 0 --max_memory_usage 1G --query "SELECT range(65535) FROM system.one ARRAY JOIN range(65536) AS number" 2>&1 | grep -oF 'Code: 241' | head -n1
|
||||
$CLICKHOUSE_CLIENT --compress 1 --max_memory_usage 1G --query "SELECT range(65535) FROM system.one ARRAY JOIN range(65536) AS number" 2>&1 | grep -oF 'Code: 241' | head -n1
|
Loading…
Reference in New Issue
Block a user