Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static void handleVoteRequest(org.neo4j.causalclustering.core.consensus.state.ReadableRaftState state, org.neo4j.causalclustering.core.consensus.outcome.Outcome outcome, org.neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request voteRequest, org.neo4j.logging.Log log) throws java.io.IOException
        internal static void HandleVoteRequest(ReadableRaftState state, Outcome outcome, Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request voteRequest, Log log)
        {
            if (voteRequest.Term() > state.Term())
            {
                outcome.NextTerm = voteRequest.Term();
                outcome.VotedFor = null;
            }

            bool votedForAnother      = outcome.VotedFor != null && !outcome.VotedFor.Equals(voteRequest.Candidate());
            bool willVoteForCandidate = ShouldVoteFor(state, outcome, voteRequest, votedForAnother, log);

            if (willVoteForCandidate)
            {
                outcome.VotedFor = voteRequest.From();
                outcome.RenewElectionTimeout();
            }

            outcome.AddOutgoingMessage(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Directed(voteRequest.From(), new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Response(state.Myself(), outcome.Term, willVoteForCandidate)));
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.causalclustering.core.consensus.outcome.Outcome handle(org.neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request req) throws java.io.IOException
            public override Outcome Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request req)
            {
                if (req.Term() > Ctx.term())
                {
                    Outcome.VotesForMe.Clear();
                    Outcome.NextRole = FOLLOWER;
                    Log.info("Moving to FOLLOWER state after receiving vote request from %s at term %d (I am at %d)", req.From(), req.Term(), Ctx.term());
                    Voting.HandleVoteRequest(Ctx, Outcome, req, Log);
                    return(Outcome);
                }

                Outcome.addOutgoingMessage(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Directed(req.From(), new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Response(Ctx.myself(), Outcome.Term, false)));
                return(Outcome);
            }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.causalclustering.core.consensus.outcome.Outcome handle(org.neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request req) throws java.io.IOException
            public override Outcome Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request req)
            {
                if (req.Term() > Ctx.term())
                {
                    StepDownToFollower(Outcome, Ctx);
                    Log.info("Moving to FOLLOWER state after receiving vote request at term %d (my term is " + "%d) from %s", req.Term(), Ctx.term(), req.From());

                    Voting.HandleVoteRequest(Ctx, Outcome, req, Log);
                    return(Outcome);
                }

                Outcome.addOutgoingMessage(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Directed(req.From(), new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Response(Ctx.myself(), Ctx.term(), false)));
                return(Outcome);
            }