ClickHouse/src/Storages/MergeTree/RequestResponse.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

130 lines
3.5 KiB
C++
Raw Normal View History

2023-02-03 13:34:18 +00:00
#include <chrono>
#include <Storages/MergeTree/RequestResponse.h>
#include <Core/ProtocolDefines.h>
#include <Common/SipHash.h>
2023-02-03 13:34:18 +00:00
#include "IO/VarInt.h"
#include <IO/WriteHelpers.h>
#include <IO/ReadHelpers.h>
#include <consistent_hashing.h>
namespace DB
{
namespace ErrorCodes
{
extern const int UNKNOWN_PROTOCOL;
}
2023-02-03 13:34:18 +00:00
void ParallelReadRequest::serialize(WriteBuffer & out) const
{
2023-02-03 13:34:18 +00:00
UInt64 version = DBMS_PARALLEL_REPLICAS_PROTOCOL_VERSION;
/// Must be the first
writeIntBinary(version, out);
writeIntBinary(mode, out);
writeIntBinary(replica_num, out);
writeIntBinary(min_number_of_marks, out);
description.serialize(out);
}
2023-02-03 13:34:18 +00:00
String ParallelReadRequest::describe() const
{
2023-02-03 13:34:18 +00:00
String result;
result += fmt::format("replica_num: {} \n", replica_num);
result += fmt::format("min_num_of_marks: {} \n", min_number_of_marks);
result += description.describe();
return result;
}
void ParallelReadRequest::deserialize(ReadBuffer & in)
{
UInt64 version;
readIntBinary(version, in);
if (version != DBMS_PARALLEL_REPLICAS_PROTOCOL_VERSION)
throw Exception(ErrorCodes::UNKNOWN_PROTOCOL, "Protocol versions for parallel reading "\
"from replicas differ. Got: {}, supported version: {}",
version, DBMS_PARALLEL_REPLICAS_PROTOCOL_VERSION);
2023-02-03 13:34:18 +00:00
readIntBinary(mode, in);
readIntBinary(replica_num, in);
readIntBinary(min_number_of_marks, in);
description.deserialize(in);
}
2023-02-03 13:34:18 +00:00
void ParallelReadRequest::merge(ParallelReadRequest & other)
{
assert(mode == other.mode);
assert(replica_num == other.replica_num);
assert(min_number_of_marks == other.min_number_of_marks);
description.merge(other.description);
}
2023-02-03 13:34:18 +00:00
void ParallelReadResponse::serialize(WriteBuffer & out) const
{
2023-02-03 13:34:18 +00:00
UInt64 version = DBMS_PARALLEL_REPLICAS_PROTOCOL_VERSION;
/// Must be the first
2023-02-03 13:34:18 +00:00
writeIntBinary(version, out);
2023-02-03 13:34:18 +00:00
writeBoolText(finish, out);
description.serialize(out);
}
2023-02-03 13:34:18 +00:00
String ParallelReadResponse::describe() const
2022-11-14 06:13:42 +00:00
{
2023-02-03 13:34:18 +00:00
String result;
result += fmt::format("finish: {} \n", finish);
result += description.describe();
return result;
2022-11-14 06:13:42 +00:00
}
2023-02-03 13:34:18 +00:00
void ParallelReadResponse::deserialize(ReadBuffer & in)
{
UInt64 version;
2023-02-03 13:34:18 +00:00
readIntBinary(version, in);
if (version != DBMS_PARALLEL_REPLICAS_PROTOCOL_VERSION)
2023-02-03 13:34:18 +00:00
throw Exception(ErrorCodes::UNKNOWN_PROTOCOL, "Protocol versions for parallel reading " \
"from replicas differ. Got: {}, supported version: {}",
version, DBMS_PARALLEL_REPLICAS_PROTOCOL_VERSION);
2023-02-03 13:34:18 +00:00
readBoolText(finish, in);
description.deserialize(in);
}
2023-02-03 13:34:18 +00:00
void InitialAllRangesAnnouncement::serialize(WriteBuffer & out) const
{
UInt64 version = DBMS_PARALLEL_REPLICAS_PROTOCOL_VERSION;
/// Must be the first
writeIntBinary(version, out);
2023-02-03 13:34:18 +00:00
description.serialize(out);
writeIntBinary(replica_num, out);
}
2023-02-03 13:34:18 +00:00
String InitialAllRangesAnnouncement::describe()
{
2023-02-03 13:34:18 +00:00
String result;
result += description.describe();
result += fmt::format("----------\nReceived from {} replica\n", replica_num);
return result;
}
2023-02-03 13:34:18 +00:00
void InitialAllRangesAnnouncement::deserialize(ReadBuffer & in)
{
UInt64 version;
2023-02-03 13:34:18 +00:00
readIntBinary(version, in);
if (version != DBMS_PARALLEL_REPLICAS_PROTOCOL_VERSION)
2023-02-03 13:34:18 +00:00
throw Exception(ErrorCodes::UNKNOWN_PROTOCOL, "Protocol versions for parallel reading " \
"from replicas differ. Got: {}, supported version: {}",
version, DBMS_PARALLEL_REPLICAS_PROTOCOL_VERSION);
2023-02-03 13:34:18 +00:00
description.deserialize(in);
readIntBinary(replica_num, in);
}
}