Exemple #1
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_NewEntry_Request req) throws java.io.IOException
            public override Outcome Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request req)
            {
                ReplicatedContent content = req.Content();

                Appending.AppendNewEntry(Ctx, Outcome, content);
                return(Outcome);
            }
Exemple #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.util.concurrent.Future<Object> replicate0(ReplicatedContent command, boolean trackResult, org.neo4j.causalclustering.identity.MemberId leader) throws ReplicationFailureException
        private Future <object> Replicate0(ReplicatedContent command, bool trackResult, MemberId leader)
        {
            _replicationMonitor.startReplication();
            try
            {
                OperationContext session = _sessionPool.acquireSession();

                DistributedOperation operation = new DistributedOperation(command, session.GlobalSession(), session.LocalOperationId());
                Progress             progress  = _progressTracker.start(operation);

                Org.Neo4j.causalclustering.helper.TimeoutStrategy_Timeout progressTimeout = _progressTimeoutStrategy.newTimeout();
                int attempts = 0;
                try
                {
                    while (true)
                    {
                        attempts++;
                        if (attempts > 1)
                        {
                            _log.info("Retrying replication. Current attempt: %d Content: %s", attempts, command);
                        }
                        _replicationMonitor.replicationAttempt();
                        AssertDatabaseAvailable();
                        // blocking at least until the send has succeeded or failed before retrying
                        _outbound.send(leader, new Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request(_me, operation), true);
                        progress.AwaitReplication(progressTimeout.Millis);
                        if (progress.Replicated)
                        {
                            break;
                        }
                        progressTimeout.Increment();
                        leader = _leaderProvider.awaitLeader();
                    }
                }
                catch (InterruptedException e)
                {
                    _progressTracker.abort(operation);
                    throw new ReplicationFailureException("Interrupted while replicating", e);
                }

                System.Action <object, Exception> cleanup = (ignored1, ignored2) => _sessionPool.releaseSession(session);

                if (trackResult)
                {
                    progress.FutureResult().whenComplete(cleanup);
                }
                else
                {
                    cleanup(null, null);
                }
                _replicationMonitor.successfulReplication();
                return(progress.FutureResult());
            }
            catch (Exception t)
            {
                _replicationMonitor.failedReplication(t);
                throw t;
            }
        }
Exemple #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.util.concurrent.Future<Object> replicate(ReplicatedContent command, boolean trackResult) throws ReplicationFailureException
        public override Future <object> Replicate(ReplicatedContent command, bool trackResult)
        {
            MemberId currentLeader = _leaderProvider.currentLeader();

            if (currentLeader == null)
            {
                throw new ReplicationFailureException("Replication aborted since no leader was available");
            }
            return(Replicate0(command, trackResult, currentLeader));
        }
Exemple #4
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));
        }
Exemple #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.util.List<int> integerValues(org.neo4j.causalclustering.core.consensus.log.ReadableRaftLog log) throws java.io.IOException
        private IList <int> IntegerValues(ReadableRaftLog log)
        {
            IList <int> actual = new List <int>();

            for (long logIndex = 0; logIndex <= log.AppendIndex(); logIndex++)
            {
                ReplicatedContent content = readLogEntry(log, logIndex).content();
                if (content is ReplicatedInteger)
                {
                    ReplicatedInteger integer = ( ReplicatedInteger )content;
                    actual.Add(integer.Get());
                }
            }
            return(actual);
        }
Exemple #6
0
            public override Optional <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage> MaybeComplete(LinkedList <long> terms, LinkedList <ReplicatedContent> contents)
            {
                if (terms.Count < EntryCount || contents.Count < EntryCount)
                {
                    return(null);
                }

                RaftLogEntry[] entries = new RaftLogEntry[EntryCount];
                for (int i = 0; i < EntryCount; i++)
                {
                    long term = terms.RemoveFirst();
                    ReplicatedContent content = contents.RemoveFirst();
                    entries[i] = new RaftLogEntry(term, content);
                }
                return(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request(From, Term, PrevLogIndex, PrevLogTerm, entries, LeaderCommit));
            }
Exemple #7
0
        public override Future <object> Replicate(ReplicatedContent content, bool trackResult)
        {
            lock (this)
            {
                AtomicReference <CompletableFuture <object> > futureResult = new AtomicReference <CompletableFuture <object> >(new CompletableFuture <>());
                _stateMachine.applyCommand((Command)content, _commandIndex++, result =>
                {
                    if (trackResult)
                    {
                        futureResult.getAndUpdate(result.apply);
                    }
                });

                return(futureResult.get());
            }
        }
Exemple #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertMarshalingEquality(io.netty.buffer.ByteBuf buffer, org.neo4j.causalclustering.core.state.machines.tx.TransactionRepresentationReplicatedTransaction replicatedTx) throws java.io.IOException, org.neo4j.causalclustering.messaging.EndOfStreamException
        private void AssertMarshalingEquality(ByteBuf buffer, TransactionRepresentationReplicatedTransaction replicatedTx)
        {
            _marshal.marshal(replicatedTx, new NetworkWritableChannel(buffer));

            ReplicatedContent unmarshal = _marshal.unmarshal(new NetworkReadableClosableChannelNetty4(buffer));

            TransactionRepresentation tx = replicatedTx.Tx();

            sbyte[] extraHeader = tx.AdditionalHeader();
            if (extraHeader == null)
            {
                // hackishly set additional header to empty array...
                (( PhysicalTransactionRepresentation )tx).setHeader(new sbyte[0], tx.MasterId, tx.AuthorId, tx.TimeStarted, tx.LatestCommittedTxWhenStarted, tx.TimeCommitted, tx.LockSessionId);
                extraHeader = tx.AdditionalHeader();
            }
            TransactionRepresentation representation = ReplicatedTransactionFactory.extractTransactionRepresentation(( ReplicatedTransaction )unmarshal, extraHeader);

            assertThat(representation, equalTo(tx));
        }
Exemple #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException
        public static void Main(string[] args)
        {
            Args arg = Args.parse(args);

            string from = arg.Get("from");

            Console.WriteLine("From is " + from);
            string to = arg.Get("to");

            Console.WriteLine("to is " + to);

            File logDirectory = new File(from);

            Console.WriteLine("logDirectory = " + logDirectory);
            Config config = Config.defaults(stringMap());

            using (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction())
            {
                LogProvider            logProvider     = Instance;
                CoreLogPruningStrategy pruningStrategy = (new CoreLogPruningStrategyFactory(config.Get(raft_log_pruning_strategy), logProvider)).newInstance();
                SegmentedRaftLog       log             = new SegmentedRaftLog(fileSystem, logDirectory, config.Get(raft_log_rotation_size), CoreReplicatedContentMarshal.marshaller(), logProvider, config.Get(raft_log_reader_pool_size), Clocks.systemClock(), new ThreadPoolJobScheduler(), pruningStrategy);

                long totalCommittedEntries = log.AppendIndex();                         // Not really, but we need to have a way to pass in the commit index
                for (int i = 0; i <= totalCommittedEntries; i++)
                {
                    ReplicatedContent content = readLogEntry(log, i).content();
                    if (content is ReplicatedTransaction)
                    {
                        ReplicatedTransaction tx = ( ReplicatedTransaction )content;
                        ReplicatedTransactionFactory.extractTransactionRepresentation(tx, new sbyte[0]).accept(element =>
                        {
                            Console.WriteLine(element);
                            return(false);
                        });
                    }
                }
            }
        }
Exemple #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertMarshalingEquality(io.netty.buffer.ByteBuf buffer, ReplicatedContent replicatedTx) throws java.io.IOException, org.neo4j.causalclustering.messaging.EndOfStreamException
        private void AssertMarshalingEquality(ByteBuf buffer, ReplicatedContent replicatedTx)
        {
            _marshal.marshal(replicatedTx, new NetworkWritableChannel(buffer));

            assertThat(_marshal.unmarshal(new NetworkReadableClosableChannelNetty4(buffer)), equalTo(replicatedTx));
        }
Exemple #11
0
 public DistributedOperation(ReplicatedContent content, GlobalSession globalSession, LocalOperationId operationId)
 {
     this._content       = content;
     this._globalSession = globalSession;
     this._operationId   = operationId;
 }
Exemple #12
0
 public virtual void Replicate(ReplicatedContent content)
 {
     _outbound.send(_myself, new Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request(_myself, content));
 }
Exemple #13
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));
        }
Exemple #14
0
 public RaftMessages_NewEntry_Request(MemberId from, ReplicatedContent content) : base(from, RaftMessages_Type.NewEntryRequest)
 {
     this.ContentConflict = content;
 }
Exemple #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void serializableContents(org.neo4j.causalclustering.core.replication.ReplicatedContent content, java.util.List<Object> out) throws java.io.IOException
            internal virtual void SerializableContents(ReplicatedContent content, IList <object> @out)
            {
                @out.Add(ContentType.ReplicatedContent);
                outerInstance.codec.Encode(content, @out);
            }