canonical / raft

Unmaintained C implementation of the Raft consensus protocol
Other
937 stars 136 forks source link

Implement prevoting before an actual vote #65

Closed matthewaveryusa closed 4 years ago

matthewaveryusa commented 5 years ago

Let me start by saying that this implementation looks fantastic and I'm really excited to see such a library written in C. What are your opinions on adding a pre-vote phase to the vote? From Ongardie's long-form thesis paper (https://github.com/ongardie/dissertation#readme), the concept of pre-vote is explained:

One downside of Raft’s leader election algorithm is that a server that has been partitioned from the cluster is likely to cause a disruption when it regains connectivity. When a server is partitioned, it will not receive heartbeats. It will soon increment its term to start an election, although it won’t be able to collect enough votes to become leader. When the server regains connectivity sometime later, its larger term number will propagate to the rest of the cluster (either through the server’s RequestVote requests or through its AppendEntries response). This will force the cluster leader to step down, and a new election will have to take place to select a new leader. Fortunately, such events are likely to be rare, and each will only cause one leader to step down.

I've worked on networks where these situations are not as rare (world-distributed with tighter heartbeats) and it can cause non-negligible leadership churn.

Here's an example of how it works in my toy raft implementation: (https://github.com/matthewaveryusa/raft.ts/blob/master/src/server.ts#L401-L455)

Would you be interested in a pull request with pre-voting?

freeekanayaka commented 5 years ago

Yes, I'd be interested. My medium term goal is to be feature-complete wrt the raft paper.

I think there are still areas of code that need to be improved and thought better about. Not sure how urgent such a feature would be for you, but maybe I'd suggest waiting a bit. Anyway, it's just a suggestion, if you find your way into the code and you have a PR to submit, I'll be happy to merge.

I did not tag this project as v1 since I still want to break API compatibility if I need to.