• Shaya Potter's avatar
    Adding support for TimeoutNow RPC (#7) · 575335c3
    Shaya Potter authored
    this is the small modifications needed for raftlib to support timeout now rpc
    
    1) add a flag to requestvote type to tell other nodes its overriding normal chec
    2) new send_timeoutnow callback to send a timeout now rpc at right time
    3) call said callback is we've marked the node as timeout now and in raft_appendentries_response raft_get_current_idx(me_) == r->current_idx (i.e. response says the node's idx is up to date with leader)
    4) add helper functions to set/get/reset timeout flag on node structs for targeted node.
    
    how it would be used by client
    
    1) client of libraft will call raft_transfer_leader(raft_server_t* me_, raft_node_id_t node_id) to target the node they want to transfer to.
    
    2) client of libraft will provide the send_timeoutnow() callback for the actual sending of the rpc
    
    3) client of libraft will modify their existing notify_state_event() callback to observe the result of the timeout now operation.
    
    if it receives a RAFT_STATE_LEADERSHIP_TRANSFER_FAILED, then the transfer failed
    
    if it received a RAFT_STATE_FOLLOWER, then it inspects for the actual leader to see if its the expected one and can return that it was transferred to expected node or not
    
    if it received a RAFT_STATE_CANDIDATE, then the transfer also failed, as the targeted node sent a request vote which removed leadership, but wasn't able to win the election.
    
    With PreVote, this latter case should be very rare.
    575335c3
raft_server.c 51.8 KB