0
votes

i'm trying to understand the raft consensus algorithm for trying to implement it, what i don't have understood is the leader election algorithm, the termId is incremented when one node pass from state follower to candidate, but how we can be sure that the actual termid incremented is up to date and there is no other node that in future will have the same termid ?

1

1 Answers

0
votes

There is no guarantee that a in the future, another node won't try to reuse a termId that has already been used.

But this is all fine for Raft. If there would be a peer that tries to start an election with a termId that is lower than the current termId, the vote wouldn't be granted.

This peer that started the election would receive a RPC response containing the current termId of the cluster, and would need to update it's state to match the current state of the system, turning to follower and changing it's termId.

Basically, every time a peer receives a response or a request with a termId that is higher than it's "local" termId, that peer needs to updated it's local state and turn to follower.