Hi all,
While working on the raft implementation I am a little perplexed by the following statement in the paper.
Once a leader has been elected, it begins servicing
client requests. Each client request contains a command to
be executed by the replicated state machines. The leader
appends the command to its log as a new entry, then issues AppendEntries RPCs in parallel to each of the other
servers to replicate the entry. When the entry has been
safely replicated (as described below), the leader applies
the entry to its state machine and returns the result of that
execution to the client. If followers crash or run slowly,
or if network packets are lost, the leader retries AppendEntries RPCs indefinitely (even after it has responded to
the client) until all followers eventually store all log entries.
It seems like the paper is suggesting spawning separate AppendEntry request threads and have a countdown latch (with the majority count) that is decremented upon a successful completion of the AppendEntry request. Once the majority count has reached the leader applies the command to the resident state machine and then responding to the client with an ACK.
My question is regarding the subset of threads from the original request that are still in a retry loop or in a delayed state due to either network/server failures, network flaps or in a state of maintaining a log-matching property. If we are keeping those threads alive, what happens when a subsequent client request arrives at the node? Do we cancel the execution of the threads from the previous request before re-spawning a new set of requests from the leader?
Here is an example:
We have a set of 5 nodes: [A, B, C, D, E]
' A' is the leader.
Here's the chronology of events:
1. Client request C1 is intercepted by 'A'.
2. A appends the entry to its own log.
3. A initializes a counting semaphore of size 3 (5 nodes, the majority will be 3)
4. A spawns 4 RPC threads , [RPC-B, RPC-C, RPC-D, RPC-E]
5. [RPC-B,RPC-C, RPC-D] completes, decrementing the semaphore upon each completion.
6. A meets the majority requirement and commits the entry.
7. A returns an OK response for client request C1. [RPC-E] is still running in the background.
8. Client request C2 is intercepted by 'A'
9. Same as steps 2 and 3.
10. Spawn 4 RPC threads for B, C, D and E. (Since E is still in progress, do we dispatch another thread for E???)
It will be great if somebody could clarify what I am missing here.
Thanks