コード例 #1
0
 public void handleAppendEntries(AppendEntries appendEntries, IActorRef sender)
 {
     //If we get an append entries message while being a candidate
     //Go back to become a follower
     this.node.setState(this.node.followerState);
     this.node.followerState.handleAppendEntries(appendEntries, sender);
 }
コード例 #2
0
 public void handleAppendEntries(AppendEntries appendEntries, IActorRef sender)
 {
     //Save the info of the leader
     this.node.setLeaderReference(sender);
     //Process the entries from the leader
     this.node.appendEntriesFromLeader(appendEntries, sender);
     //this.node.log.Info(string.Concat("Follower ", this.node.nodeId, " received Append Entries message."));
     this.node.resetElectionTimer();
 }
コード例 #3
0
        public void appendEntriesFromLeader(AppendEntries appendEntries, IActorRef leader)
        {
            //Reply false if term < currentTerm
            //Reply false if log does not contain an entry at prevLogIndex whose term matches prevLogTerm
            if (appendEntries.term < this.currentTerm ||
                this.logEntries.getLastLogIndex() < appendEntries.prevLogIndex ||
                (appendEntries.prevLogIndex > 0 && this.logEntries.getLogEntryTerm(appendEntries.prevLogIndex) != appendEntries.prevLogTerm))
            {
                leader.Tell(new AppendEntriesResponse(this.currentTerm, false, 0));
                return;
            }

            //If an existing entry conflicts with a new one (same index but different terms), delete the existing entry and all that follow it
            int startingIndexToRemove = this.logEntries.getLastLogIndex() + 1;

            foreach (LogEntry entry in appendEntries.entries)
            {
                if (this.logEntries.getLogEntryTerm(entry.index) != entry.term)
                {
                    startingIndexToRemove = entry.index;
                    break;
                }
            }

            //Remove
            if (startingIndexToRemove <= this.logEntries.getLastLogIndex())
            {
                this.logEntries.removeEntriesFromIndex(startingIndexToRemove);
            }

            //Append the missing entries
            foreach (LogEntry entry in appendEntries.entries)
            {
                if (entry.index <= this.logEntries.getLastLogIndex())
                {
                    continue;
                }
                //For followers, default responseSent to true, it's the leader's job
                this.logEntries.append(entry.term, entry.quantity, entry.command, entry.clientActorPath, true, entry.giveUpForFrontEndPath);
            }

            this.updatePersistentStorage();

            //Tell the leader it has been successful
            leader.Tell(new AppendEntriesResponse(this.currentTerm, true, this.logEntries.getLastLogIndex()));

            //Update the commit index
            if (this.commitIndex < appendEntries.commitIndex)
            {
                this.setCommitIndex(appendEntries.commitIndex);
            }

            this.updateLastApplied();

            //Recompute the tentative state
            this.stateMachine.recomputeTentativeState(this.logEntries.getEntriesFromIndex(this.lastApplied + 1));
        }
コード例 #4
0
 public void handleAppendEntries(AppendEntries appendEntries, IActorRef sender)
 {
     //If the appendEntries term is > this term, the checkTerm function already makes this node step down
 }