コード例 #1
0
        public void processAppendEntriesResponse(AppendEntriesResponse appendEntriesResponse, IActorRef sender)
        {
            //If false, reduce the next index, but make sure the next index does not fall below 1, return
            if (!appendEntriesResponse.success)
            {
                this.followerNextIndexes.updateValue(sender, Math.Max(this.followerNextIndexes.getValue(sender) - 1, 1));
                //When leader sees failed AppendEntries RPC, immediately send new RPC
                this.sendAppendEntryToNode(sender);
                return;
            }

            //Got a success response from a follower, update its next index
            this.followerNextIndexes.updateValue(sender, appendEntriesResponse.lastLogIndex + 1);
            this.followerMatchIndexes.updateValue(sender, appendEntriesResponse.lastLogIndex);

            //Update commit index
            int newCommitIndex = 0;

            //For each index after the last commit index, check which one has the most match
            for (int i = this.commitIndex + 1; i < this.logEntries.getLastLogIndex() + 1; i++)
            {
                //Init to 1 to include self
                int matchCount = 1;

                foreach (KeyValuePair <IActorRef, int> entry in followerMatchIndexes.entries)
                {
                    if (entry.Value >= i)
                    {
                        matchCount++;
                    }
                }

                //If the match count is of majority of the nodes and the current term
                if (matchCount > (this.allNodes.Count / 2) && this.currentTerm == this.logEntries.getLogEntryTerm(i))
                {
                    newCommitIndex = i;
                }
            }

            if (newCommitIndex > this.commitIndex)
            {
                this.setCommitIndex(newCommitIndex);
            }

            this.updateLastApplied();
        }
コード例 #2
0
 public void handleAppendEntriesResponse(AppendEntriesResponse appendEntriesResponse, IActorRef sender)
 {
     //Do nothing
 }
コード例 #3
0
 public void handleAppendEntriesResponse(AppendEntriesResponse appendEntriesResponse, IActorRef sender)
 {
     this.node.processAppendEntriesResponse(appendEntriesResponse, sender);
 }