Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSendCompactionInfoIfFailureWithNoEarlierEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSendCompactionInfoIfFailureWithNoEarlierEntries()
        {
            // given
            Leader leader          = new Leader();
            long   term            = 1;
            long   leaderPrevIndex = 3;
            long   followerIndex   = leaderPrevIndex - 1;

            InMemoryRaftLog raftLog = new InMemoryRaftLog();

            raftLog.Skip(leaderPrevIndex, term);

            RaftState state = raftState().term(term).entryLog(raftLog).build();

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response incomingResponse = appendEntriesResponse().failure().term(term).appendIndex(followerIndex).from(_member1).build();

            // when
            Outcome outcome = leader.Handle(incomingResponse, state, Log());

            // then
            Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage outgoingMessage = messageFor(outcome, _member1);
            assertThat(outgoingMessage, instanceOf(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo)));

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo typedOutgoingMessage = (Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo)outgoingMessage;
            assertThat(typedOutgoingMessage.PrevIndex(), equalTo(leaderPrevIndex));
        }
Exemplo n.º 2
0
 public override Outcome Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo logCompactionInfo)
 {
     return(Outcome);
 }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
 public override Void Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo logCompactionInfo)
 {
     Channel.putLong(logCompactionInfo.LeaderTerm());
     Channel.putLong(logCompactionInfo.PrevIndex());
     return(null);
 }
Exemplo n.º 5
0
        private static void HandleLeaderLogCompaction(ReadableRaftState ctx, Outcome outcome, Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo compactionInfo)
        {
            if (compactionInfo.LeaderTerm() < ctx.Term())
            {
                return;
            }

            if (ctx.EntryLog().appendIndex() <= -1 || compactionInfo.PrevIndex() > ctx.EntryLog().appendIndex())
            {
                outcome.MarkNeedForFreshSnapshot();
            }
        }