Пример #1
0
            public override Void Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat heartbeat)
            {
                Channel.putLong(heartbeat.LeaderTerm());
                Channel.putLong(heartbeat.CommitIndexTerm());
                Channel.putLong(heartbeat.CommitIndex());

                return(null);
            }
Пример #2
0
        private void SendCommitUpdate(LeaderContext leaderContext)
        {
            /*
             * This is a commit update. That means that we just received enough success responses to an append
             * request to allow us to send a commit. By Raft invariants, this means that the term for the committed
             * entry is the current term.
             */
            Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat appendRequest = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat(_leader, leaderContext.Term, leaderContext.CommitIndex, leaderContext.Term);

            _outbound.send(_follower, appendRequest);
        }
Пример #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_Heartbeat req) throws java.io.IOException
            public override Outcome Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat req)
            {
                if (req.LeaderTerm() < Ctx.term())
                {
                    return(Outcome);
                }

                Outcome.NextRole = FOLLOWER;
                Log.info("Moving to FOLLOWER state after receiving heartbeat from %s at term %d (I am at %d)", req.From(), req.LeaderTerm(), Ctx.term());
                Heart.Beat(Ctx, Outcome, req, Log);
                return(Outcome);
            }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSuccessfullySendAndReceiveAMessage() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSuccessfullySendAndReceiveAMessage()
        {
            // given
            Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat raftMessage = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat(new MemberId(System.Guid.randomUUID()), 1, 2, 3);
            Org.Neo4j.causalclustering.core.consensus.RaftMessages_ClusterIdAwareMessage <Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat> networkMessage = Org.Neo4j.causalclustering.core.consensus.RaftMessages_ClusterIdAwareMessage.of(new ClusterId(System.Guid.randomUUID()), raftMessage);

            // when
            _client.send(networkMessage).syncUninterruptibly();

            // then
            assertEventually(messages => string.Format("Received messages {0} should contain message decorating {1}", messages, raftMessage), () => _server.received(), contains(MessageMatches(networkMessage)), TIMEOUT_SECONDS, SECONDS);
        }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotResultInCommitIfReferringToFutureEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotResultInCommitIfReferringToFutureEntries()
        {
            InMemoryRaftLog raftLog = new InMemoryRaftLog();
            RaftState       state   = raftState().myself(_myself).entryLog(raftLog).build();

            long leaderTerm = state.Term() + LeaderTermDifference;

            raftLog.Append(new RaftLogEntry(leaderTerm, content()));

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat heartbeat = heartbeat().from(_leader).commitIndex(raftLog.AppendIndex() + 1).commitIndexTerm(leaderTerm).leaderTerm(leaderTerm).build();

            Outcome outcome = Role.handler.handle(heartbeat, state, Log());

            assertThat(outcome.LogCommands, empty());
        }
Пример #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static void beat(org.neo4j.causalclustering.core.consensus.state.ReadableRaftState state, org.neo4j.causalclustering.core.consensus.outcome.Outcome outcome, org.neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat request, org.neo4j.logging.Log log) throws java.io.IOException
        internal static void Beat(ReadableRaftState state, Outcome outcome, Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat request, Log log)
        {
            if (request.LeaderTerm() < state.Term())
            {
                return;
            }

            outcome.PreElection  = false;
            outcome.NextTerm     = request.LeaderTerm();
            outcome.Leader       = request.From();
            outcome.LeaderCommit = request.CommitIndex();
            outcome.AddOutgoingMessage(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Directed(request.From(), new Org.Neo4j.causalclustering.core.consensus.RaftMessages_HeartbeatResponse(state.Myself())));

            if (!Follower.LogHistoryMatches(state, request.CommitIndex(), request.CommitIndexTerm()))
            {
                return;
            }

            Follower.CommitToLogOnUpdate(state, request.CommitIndex(), request.CommitIndex(), outcome);
        }
Пример #7
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));
        }
Пример #8
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_Heartbeat heartbeat) throws Exception
            public override Void Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat heartbeat)
            {
                return(null);
            }