Example #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static void appendNewEntry(org.neo4j.causalclustering.core.consensus.state.ReadableRaftState ctx, org.neo4j.causalclustering.core.consensus.outcome.Outcome outcome, org.neo4j.causalclustering.core.replication.ReplicatedContent content) throws java.io.IOException
        internal static void AppendNewEntry(ReadableRaftState ctx, Outcome outcome, ReplicatedContent content)
        {
            long prevLogIndex = ctx.EntryLog().appendIndex();
            long prevLogTerm  = prevLogIndex == -1 ? -1 : prevLogIndex > ctx.LastLogIndexBeforeWeBecameLeader() ? ctx.Term() : ctx.EntryLog().readEntryTerm(prevLogIndex);

            RaftLogEntry newLogEntry = new RaftLogEntry(ctx.Term(), content);

            outcome.AddShipCommand(new ShipCommand.NewEntries(prevLogIndex, prevLogTerm, new RaftLogEntry[] { newLogEntry }));
            outcome.AddLogCommand(new AppendLogEntry(prevLogIndex + 1, newLogEntry));
        }
Example #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static void appendNewEntries(org.neo4j.causalclustering.core.consensus.state.ReadableRaftState ctx, org.neo4j.causalclustering.core.consensus.outcome.Outcome outcome, java.util.Collection<org.neo4j.causalclustering.core.replication.ReplicatedContent> contents) throws java.io.IOException
        internal static void AppendNewEntries(ReadableRaftState ctx, Outcome outcome, ICollection <ReplicatedContent> contents)
        {
            long prevLogIndex = ctx.EntryLog().appendIndex();
            long prevLogTerm  = prevLogIndex == -1 ? -1 : prevLogIndex > ctx.LastLogIndexBeforeWeBecameLeader() ? ctx.Term() : ctx.EntryLog().readEntryTerm(prevLogIndex);

//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            RaftLogEntry[] raftLogEntries = contents.Select(content => new RaftLogEntry(ctx.Term(), content)).ToArray(RaftLogEntry[] ::new);

            outcome.AddShipCommand(new ShipCommand.NewEntries(prevLogIndex, prevLogTerm, raftLogEntries));
            outcome.AddLogCommand(new BatchAppendLogEntries(prevLogIndex + 1, 0, raftLogEntries));
        }
Example #3
0
        private void Defaults(Role currentRole, ReadableRaftState ctx)
        {
            _nextRole = currentRole;

            _term   = ctx.Term();
            _leader = ctx.Leader();

            _leaderCommit = ctx.LeaderCommit();

            _votedFor             = ctx.VotedFor();
            _renewElectionTimeout = false;
            _needsFreshSnapshot   = false;

            _isPreElection      = (currentRole == Role.FOLLOWER) && ctx.PreElection;
            _steppingDownInTerm = long?.empty();
            _preVotesForMe      = _isPreElection ? new HashSet <MemberId>(ctx.PreVotesForMe()) : emptySet();
            _votesForMe         = (currentRole == Role.CANDIDATE) ? new HashSet <MemberId>(ctx.VotesForMe()) : emptySet();
            _heartbeatResponses = (currentRole == Role.LEADER) ? new HashSet <MemberId>(ctx.HeartbeatResponses()) : emptySet();

            _lastLogIndexBeforeWeBecameLeader = (currentRole == Role.LEADER) ? ctx.LastLogIndexBeforeWeBecameLeader() : -1;
            _followerStates = (currentRole == Role.LEADER) ? ctx.FollowerStates() : new FollowerStates <MemberId>();

            _commitIndex = ctx.CommitIndex();
        }