Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disconnection #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions raft.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,16 @@ let View = function(controller, svg, module) {
rule: 'clientRequest',
args: s.serverId,
},
{
label: 'disconnect from network',
rule: 'disconnect',
args: s.serverId,
},
{
label: 'connect to network',
rule: 'connect',
args: s.serverId,
},
]);
});

Expand Down
12 changes: 11 additions & 1 deletion raft.model
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Server : record {
log: Log,

// Volatile state
disconnected : Boolean,
state: either {
Follower,
Candidate {
Expand Down Expand Up @@ -145,6 +146,7 @@ function sendMessage(message: Message) {
function init() {
for server in servers {
server.timeoutAt = makeElectionTimeout();
server.disconnected = False;
}
}

Expand Down Expand Up @@ -178,6 +180,14 @@ external startup for serverId, server in servers {
}
}

external disconnect for server in servers {
server.disconnected = True;
}

external connect for server in servers {
server.disconnected = False;
}

function stableLeader() -> Boolean {
for serverId, server in servers {
match server.state {
Expand Down Expand Up @@ -424,7 +434,7 @@ rule handleMessage for message in network {
if past(message.deliverAt) {
var from : ServerId = message.from;
var to : ServerId = message.to;
if servers[message.to].state == Offline {
if servers[to].state == Offline || servers[from].disconnected || servers[to].disconnected {
remove(network, message);
} else {
match message.payload {
Expand Down