blob: 4cdcc936e2144469372cc708e18fbef95f7cd8d6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#pragma once
#include <set>
#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
{
/** 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;
size_t required_number_of_replicas{};
std::set<String> replicas;
ReplicatedMergeTreeQuorumEntry() = default;
explicit ReplicatedMergeTreeQuorumEntry(const String & str)
{
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
{
WriteBufferFromOwnString out;
writeText(out);
return out.str();
}
void fromString(const String & str)
{
ReadBufferFromString in(str);
readText(in);
}
};
}
|