mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-12 17:32:32 +00:00
70d1adfe4b
* save format string for NetException * format exceptions * format exceptions 2 * format exceptions 3 * format exceptions 4 * format exceptions 5 * format exceptions 6 * fix * format exceptions 7 * format exceptions 8 * Update MergeTreeIndexGin.cpp * Update AggregateFunctionMap.cpp * Update AggregateFunctionMap.cpp * fix
81 lines
2.3 KiB
C++
81 lines
2.3 KiB
C++
#include <IO/MySQLBinlogEventReadBuffer.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int LOGICAL_ERROR;
|
|
}
|
|
|
|
MySQLBinlogEventReadBuffer::MySQLBinlogEventReadBuffer(ReadBuffer & in_, size_t checksum_signature_length_)
|
|
: ReadBuffer(nullptr, 0, 0), in(in_), checksum_signature_length(checksum_signature_length_)
|
|
{
|
|
if (checksum_signature_length > MAX_CHECKSUM_SIGNATURE_LENGTH)
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
|
"LOGICAL ERROR: checksum_signature_length must be less than MAX_CHECKSUM_SIGNATURE_LENGTH. "
|
|
"It is a bug.");
|
|
|
|
nextIfAtEnd();
|
|
}
|
|
|
|
bool MySQLBinlogEventReadBuffer::nextImpl()
|
|
{
|
|
if (hasPendingData())
|
|
return true;
|
|
|
|
if (in.eof())
|
|
return false;
|
|
|
|
if (checksum_buff_size == checksum_buff_limit)
|
|
{
|
|
if (likely(in.available() > checksum_signature_length))
|
|
{
|
|
working_buffer = ReadBuffer::Buffer(in.position(), in.buffer().end() - checksum_signature_length);
|
|
in.ignore(working_buffer.size());
|
|
return true;
|
|
}
|
|
|
|
in.readStrict(checksum_buf, checksum_signature_length);
|
|
checksum_buff_size = checksum_buff_limit = checksum_signature_length;
|
|
}
|
|
else
|
|
{
|
|
for (size_t index = 0; index < checksum_buff_size - checksum_buff_limit; ++index)
|
|
checksum_buf[index] = checksum_buf[checksum_buff_limit + index];
|
|
|
|
checksum_buff_size -= checksum_buff_limit;
|
|
size_t read_bytes = checksum_signature_length - checksum_buff_size;
|
|
in.readStrict(checksum_buf + checksum_buff_size, read_bytes); /// Minimum checksum_signature_length bytes
|
|
checksum_buff_size = checksum_buff_limit = checksum_signature_length;
|
|
}
|
|
|
|
if (in.eof())
|
|
return false;
|
|
|
|
if (in.available() < checksum_signature_length)
|
|
{
|
|
size_t left_move_size = checksum_signature_length - in.available();
|
|
checksum_buff_limit = checksum_buff_size - left_move_size;
|
|
}
|
|
|
|
working_buffer = ReadBuffer::Buffer(checksum_buf, checksum_buf + checksum_buff_limit);
|
|
return true;
|
|
}
|
|
|
|
MySQLBinlogEventReadBuffer::~MySQLBinlogEventReadBuffer()
|
|
{
|
|
try
|
|
{
|
|
/// ignore last checksum_signature_length bytes
|
|
nextIfAtEnd();
|
|
}
|
|
catch (...)
|
|
{
|
|
tryLogCurrentException(__PRETTY_FUNCTION__);
|
|
}
|
|
}
|
|
|
|
}
|