コード例 #1
0
ファイル: Candidate.cs プロジェクト: fjsnogueira/RAFTiNG
        internal override void ProcessVote(GrantVote vote)
        {
            if (vote.VoterTerm > this.CurrentTerm)
            {
                this.Node.State.CurrentTerm = vote.VoterTerm;
                this.Logger.DebugFormat(
                    "Received a vote from a node with a higher term. Dropping candidate status down. Message discarded {0}.",
                    vote);
                this.Node.SwitchTo(NodeStatus.Follower);
                return;
            }

            if (this.voteReceived.ContainsKey(vote.VoterId))
            {
                // we already received a vote from the voter!
                this.Logger.WarnFormat(
                    "We received a second vote from {0}. Initial vote: {1}. Second vote: {2}.",
                    vote.VoterId,
                    this.voteReceived[vote.VoterId],
                    vote);
                return;
            }

            this.RegisterVote(vote);
        }
コード例 #2
0
ファイル: Candidate.cs プロジェクト: fjsnogueira/RAFTiNG
        private void RegisterVote(GrantVote vote)
        {
            this.voteReceived.Add(vote.VoterId, vote);

            // count votes
            var votes = this.voteReceived.Values.Count(grantVote => grantVote.VoteGranted);

            if (votes < this.Node.Settings.Majority)
            {
                return;
            }

            var nodes = new StringBuilder();

            foreach (var key in this.voteReceived.Keys)
            {
                nodes.AppendFormat("{0},", key);
            }

            // we have a majority
            this.Logger.InfoFormat("I am the LEADER (with {0} votes): {1}.", this.voteReceived.Count, nodes);
            this.Node.SwitchTo(NodeStatus.Leader);
        }
コード例 #3
0
ファイル: Leader.cs プロジェクト: fjsnogueira/RAFTiNG
 // process vote
 internal override void ProcessVote(GrantVote vote)
 {
     this.Logger.TraceFormat(
         "Received a vote but we are no longer interested: {0}", vote);
 }
コード例 #4
0
ファイル: Follower.cs プロジェクト: fjsnogueira/RAFTiNG
 internal override void ProcessVote(GrantVote vote)
 {
     this.Logger.DebugFormat(
         "Received a vote but I am a follower. Message discarded: {0}.", vote);
 }
コード例 #5
0
 internal abstract void ProcessVote(GrantVote vote);