ClickHouse/src/Storages/MergeTree/ReplicatedMergeTreeQuorumEntry.h

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

77 lines
1.9 KiB
C++
Raw Normal View History

#pragma once
#include <set>
2021-10-02 07:13:14 +00:00
#include <base/types.h>
#include <IO/ReadBuffer.h>
#include <IO/ReadBufferFromString.h>
#include <IO/WriteBuffer.h>
#include <IO/WriteBufferFromString.h>
#include <IO/Operators.h>
#include <Common/ZooKeeper/ZooKeeper.h>
namespace DB
{
2017-04-16 15:00:33 +00:00
/** To implement the functionality of the "quorum write".
* Information about which replicas the inserted part of data appeared on,
* and on how many replicas it should be.
*/
struct ReplicatedMergeTreeQuorumEntry
{
String part_name;
2019-06-16 18:12:14 +00:00
size_t required_number_of_replicas{};
std::set<String> replicas;
ReplicatedMergeTreeQuorumEntry() = default;
explicit ReplicatedMergeTreeQuorumEntry(const String & str)
2015-10-02 18:33:46 +00:00
{
fromString(str);
}
void writeText(WriteBuffer & out) const
{
out << "version: 1\n"
<< "part_name: " << part_name << "\n"
<< "required_number_of_replicas: " << required_number_of_replicas << "\n"
<< "actual_number_of_replicas: " << replicas.size() << "\n"
<< "replicas:\n";
for (const auto & replica : replicas)
out << escape << replica << "\n";
}
void readText(ReadBuffer & in)
{
size_t actual_number_of_replicas = 0;
in >> "version: 1\n"
>> "part_name: " >> part_name >> "\n"
>> "required_number_of_replicas: " >> required_number_of_replicas >> "\n"
>> "actual_number_of_replicas: " >> actual_number_of_replicas >> "\n"
>> "replicas:\n";
for (size_t i = 0; i < actual_number_of_replicas; ++i)
{
String replica;
in >> escape >> replica >> "\n";
replicas.insert(replica);
}
}
String toString() const
{
2017-07-31 21:39:24 +00:00
WriteBufferFromOwnString out;
writeText(out);
return out.str();
}
void fromString(const String & str)
{
ReadBufferFromString in(str);
readText(in);
}
};
}