public void OnCommand(RaftCommand command, out bool accepted, out int willCommitAt) { if (this.state != State.LEADER) { accepted = false; willCommitAt = -1; return; } this.log.Add(new RaftLog() { Command = command, Term = this.currentTerm }); nextIndex[this.Id] = this.log.Count; matchIndex[this.Id] = this.log.Count - 1; // TODO: persist Raft state // trigger sending of AppendEntries this.OnHeartbeatTimerOrSendTrigger(); this.leaderTimer.Stop(); this.leaderTimer.Start(); accepted = true; willCommitAt = this.log.Count - 1; Console.WriteLine("Accepted command at commit " + willCommitAt); }
// This function updates the state machine as a result of the command we pass // it. In order to build a replicated state machine, we need to call // StateMachine with the same commands, in the same order, on all servers. void StateMachine(RaftCommand command) { Console.WriteLine("################# COMMAND #############"); Console.WriteLine(command.Name); Console.WriteLine("################# COMMAND #############"); }