コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSerializeVoteRequest() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSerializeVoteRequest()
        {
            MemberId sender = new MemberId(System.Guid.randomUUID());

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request request = (new VoteRequestBuilder()).candidate(sender).from(sender).lastLogIndex(2).lastLogTerm(1).term(3).build();
            SerializeReadBackAndVerifyMessage(request);
        }
コード例 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Void handle(org.neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request voteRequest) throws Exception
            public override Void Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request voteRequest)
            {
                MemberMarshal.marshal(voteRequest.Candidate(), Channel);
                Channel.putLong(voteRequest.Term());
                Channel.putLong(voteRequest.LastLogIndex());
                Channel.putLong(voteRequest.LastLogTerm());

                return(null);
            }
コード例 #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())
                {
                    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);
            }
コード例 #4
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);
            }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldEncodeAndDecodeVoteRequest()
        public virtual void ShouldEncodeAndDecodeVoteRequest()
        {
            // given
            MemberId member = new MemberId(System.Guid.randomUUID());

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request request = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request(member, 1, member, 1, 1);

            // when
            _channel.writeOutbound(request);
            object message = _channel.readOutbound();

            _channel.writeInbound(message);

            // then
            assertEquals(request, _channel.readInbound());
        }
コード例 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static boolean startRealElection(org.neo4j.causalclustering.core.consensus.state.ReadableRaftState ctx, org.neo4j.causalclustering.core.consensus.outcome.Outcome outcome, org.neo4j.logging.Log log) throws java.io.IOException
        public static bool StartRealElection(ReadableRaftState ctx, Outcome outcome, Log log)
        {
            ISet <MemberId> currentMembers = ctx.VotingMembers();

            if (currentMembers == null || !currentMembers.Contains(ctx.Myself()))
            {
                log.Info("Election attempted but not started, current members are %s, I am %s", currentMembers, ctx.Myself());
                return(false);
            }

            outcome.NextTerm = ctx.Term() + 1;

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request voteForMe = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request(ctx.Myself(), outcome.Term, ctx.Myself(), ctx.EntryLog().appendIndex(), ctx.EntryLog().readEntryTerm(ctx.EntryLog().appendIndex()));

            currentMembers.Where(member => !member.Equals(ctx.Myself())).ForEach(member => outcome.addOutgoingMessage(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Directed(member, voteForMe)));

            outcome.VotedFor = ctx.Myself();
            log.Info("Election started with vote request: %s and members: %s", voteForMe, currentMembers);
            return(true);
        }
コード例 #7
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)));
        }
コード例 #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf buffer, java.util.List<Object> list) throws Exception
        public override void Decode(ChannelHandlerContext ctx, ByteBuf buffer, IList <object> list)
        {
            ReadableChannel channel   = new NetworkReadableClosableChannelNetty4(buffer);
            ClusterId       clusterId = ClusterId.Marshal.INSTANCE.unmarshal(channel);

            int messageTypeWire = channel.Int;

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type[] values      = Enum.GetValues(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type));
            Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type   messageType = values[messageTypeWire];

            MemberId from = RetrieveMember(channel);

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage result;

            if (messageType.Equals(VOTE_REQUEST))
            {
                MemberId candidate = RetrieveMember(channel);

                long term         = channel.Long;
                long lastLogIndex = channel.Long;
                long lastLogTerm  = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request(from, term, candidate, lastLogIndex, lastLogTerm);
            }
            else if (messageType.Equals(VOTE_RESPONSE))
            {
                long term        = channel.Long;
                bool voteGranted = channel.Get() == 1;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Response(from, term, voteGranted);
            }
            else if (messageType.Equals(PRE_VOTE_REQUEST))
            {
                MemberId candidate = RetrieveMember(channel);

                long term         = channel.Long;
                long lastLogIndex = channel.Long;
                long lastLogTerm  = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_PreVote_Request(from, term, candidate, lastLogIndex, lastLogTerm);
            }
            else if (messageType.Equals(PRE_VOTE_RESPONSE))
            {
                long term        = channel.Long;
                bool voteGranted = channel.Get() == 1;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_PreVote_Response(from, term, voteGranted);
            }
            else if (messageType.Equals(APPEND_ENTRIES_REQUEST))
            {
                // how many
                long term         = channel.Long;
                long prevLogIndex = channel.Long;
                long prevLogTerm  = channel.Long;

                long leaderCommit = channel.Long;
                long count        = channel.Long;

                RaftLogEntry[] entries = new RaftLogEntry[( int )count];
                for (int i = 0; i < count; i++)
                {
                    long entryTerm = channel.Long;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.core.replication.ReplicatedContent content = marshal.unmarshal(channel);
                    ReplicatedContent content = _marshal.unmarshal(channel);
                    entries[i] = new RaftLogEntry(entryTerm, content);
                }

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request(from, term, prevLogIndex, prevLogTerm, entries, leaderCommit);
            }
            else if (messageType.Equals(APPEND_ENTRIES_RESPONSE))
            {
                long term        = channel.Long;
                bool success     = channel.Get() == 1;
                long matchIndex  = channel.Long;
                long appendIndex = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response(from, term, success, matchIndex, appendIndex);
            }
            else if (messageType.Equals(NEW_ENTRY_REQUEST))
            {
                ReplicatedContent content = _marshal.unmarshal(channel);

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request(from, content);
            }
            else if (messageType.Equals(HEARTBEAT))
            {
                long leaderTerm      = channel.Long;
                long commitIndexTerm = channel.Long;
                long commitIndex     = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat(from, leaderTerm, commitIndex, commitIndexTerm);
            }
            else if (messageType.Equals(HEARTBEAT_RESPONSE))
            {
                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_HeartbeatResponse(from);
            }
            else if (messageType.Equals(LOG_COMPACTION_INFO))
            {
                long leaderTerm = channel.Long;
                long prevIndex  = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo(from, leaderTerm, prevIndex);
            }
            else
            {
                throw new System.ArgumentException("Unknown message type");
            }

            list.Add(Org.Neo4j.causalclustering.core.consensus.RaftMessages_ReceivedInstantClusterIdAwareMessage.of(_clock.instant(), clusterId, result));
        }
コード例 #9
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 request) throws java.io.IOException
            public override Outcome Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request request)
            {
                Voting.HandleVoteRequest(Ctx, Outcome, request, Log);
                return(Outcome);
            }
コード例 #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Void handle(org.neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request request) throws Exception
            public override Void Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request request)
            {
                return(null);
            }