-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_registry.cc
44 lines (31 loc) · 936 Bytes
/
node_registry.cc
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
#include "node_registry.h"
using ::std::make_shared;
using ::std::shared_ptr;
using ::std::string;
using ::std::unordered_set;
namespace paxos {
unordered_set<shared_ptr<Node>> NodeRegistry::nodes_;
shared_ptr<Node> NodeRegistry::Register(int nodeId) {
const auto& node = make_shared<Node>(nodeId);
nodes_.insert(node);
return node;
}
unordered_set<shared_ptr<Node>> NodeRegistry::Get() {
return nodes_;
}
shared_ptr<string> NodeRegistry::GetCommittedValue() {
shared_ptr<string> committed_value = nullptr;
for (const auto& node : nodes_) {
const auto& node_committed_value = node->GetCommittedValue();
if (!node_committed_value) {
return nullptr;
}
if (!committed_value) {
committed_value = node_committed_value;
} else if (*committed_value != *node_committed_value) {
return nullptr;
}
}
return committed_value;
}
}