Skip to content

Commit

Permalink
GetAllNodes also go through the consistency process
Browse files Browse the repository at this point in the history
  • Loading branch information
CatKang committed Dec 28, 2017
1 parent 4085705 commit d76ac91
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 72 deletions.
26 changes: 17 additions & 9 deletions floyd/example/simple/remove_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ uint64_t NowMicros() {
return static_cast<uint64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
}

bool print_members(Floyd* f) {
std::set<std::string> nodes;
Status s = f->GetAllServers(&nodes);
if (!s.ok()) {
return false;
}
printf("Membership: ");
for (const std::string& n : nodes) {
printf(" %s", n.c_str());
}
printf("\n");
return true;
}

int main()
{
slash::Status s;
Expand Down Expand Up @@ -44,9 +58,7 @@ int main()
std::string msg;

while (1) {
if (f1->HasLeader()) {
f1->GetServerStatus(&msg);
printf("%s\n", msg.c_str());
if (print_members(f1)) {
break;
}
printf("electing leader... sleep 2s\n");
Expand Down Expand Up @@ -74,9 +86,7 @@ int main()
printf("Remove out server4 status %s\n", s.ToString().c_str());

while (1) {
if (f1->HasLeader()) {
f1->GetServerStatus(&msg);
printf("%s\n", msg.c_str());
if (print_members(f1)) {
break;
}
printf("electing leader after server 4 leave the cluster... sleep 2s\n");
Expand All @@ -97,9 +107,7 @@ int main()
delete f5;
printf("Remove out server5 status %s\n", s.ToString().c_str());
while (1) {
if (f1->HasLeader()) {
f1->GetServerStatus(&msg);
printf("%s\n", msg.c_str());
if (print_members(f1)) {
break;
}
printf("electing leader after server 5 leave the cluster... sleep 2s\n");
Expand Down
2 changes: 1 addition & 1 deletion floyd/include/floyd.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class Floyd {
virtual bool GetLeader(std::string* ip_port) = 0;
virtual bool GetLeader(std::string* ip, int* port) = 0;
virtual bool HasLeader() = 0;
virtual bool GetAllNodes(std::set<std::string>* nodes) = 0;
virtual bool IsLeader() = 0;
virtual Status GetAllServers(std::set<std::string>* nodes) = 0;

// used for debug
virtual bool GetServerStatus(std::string* msg) = 0;
Expand Down
5 changes: 5 additions & 0 deletions floyd/proto/floyd.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ message Entry {
kUnLock = 5;
kAddServer = 6;
kRemoveServer = 7;
kGetAllServers = 8;
}
// used in key value operator
optional uint64 term = 1;
Expand All @@ -36,6 +37,7 @@ enum Type {
kUnLock = 6;
kAddServer = 11;
kRemoveServer = 12;
kGetAllServers = 13;

// Raft RPC
kRequestVote = 8;
Expand Down Expand Up @@ -142,6 +144,8 @@ message CmdResponse {
optional uint64 last_applied = 10;
}
optional ServerStatus server_status = 7;

optional Membership all_servers = 8;
}

/*
Expand All @@ -164,3 +168,4 @@ message Membership {
}



155 changes: 103 additions & 52 deletions floyd/src/floyd.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d76ac91

Please sign in to comment.