Exemple #1
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 #2
0
        public override Progress Start(DistributedOperation operation)
        {
            Debug.Assert(operation.GlobalSession().Equals(_myGlobalSession));

            Progress progress = new Progress();

            _tracker[operation.OperationId()] = progress;
            return(progress);
        }
Exemple #3
0
        public override void TrackResult(DistributedOperation operation, Result result)
        {
            if (!operation.GlobalSession().Equals(_myGlobalSession))
            {
                return;
            }

            Progress progress = _tracker.Remove(operation.OperationId());

            if (progress != null)
            {
                result.Apply(progress.FutureResult());
            }
        }
Exemple #4
0
        public override void TrackReplication(DistributedOperation operation)
        {
            if (!operation.GlobalSession().Equals(_myGlobalSession))
            {
                return;
            }

            Progress progress = _tracker[operation.OperationId()];

            if (progress != null)
            {
                progress.SetReplicated();
            }
        }
Exemple #5
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }
            DistributedOperation that = ( DistributedOperation )o;

            return(Objects.Equals(_content, that._content) && Objects.Equals(_globalSession, that._globalSession) && Objects.Equals(_operationId, that._operationId));
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIgnoreOtherSessions()
        public virtual void ShouldIgnoreOtherSessions()
        {
            // given
            GlobalSession        sessionB           = new GlobalSession(System.Guid.randomUUID(), null);
            DistributedOperation aliasUnderSessionB = new DistributedOperation(ReplicatedInteger.valueOf(0), sessionB, new LocalOperationId(_operationA.operationId().localSessionId(), _operationA.operationId().sequenceNumber()));

            Progress progressA = _tracker.start(_operationA);

            // when
            _tracker.trackReplication(aliasUnderSessionB);
            _tracker.trackResult(aliasUnderSessionB, Result.of("result"));

            // then
            assertFalse(progressA.Replicated);
            assertFalse(progressA.FutureResult().Done);
        }
Exemple #7
0
 private void InitializeInstanceFields()
 {
     _operationA = new DistributedOperation(ReplicatedInteger.valueOf(0), _session, new LocalOperationId(0, 0));
     _operationB = new DistributedOperation(ReplicatedInteger.valueOf(1), _session, new LocalOperationId(1, 0));
     _tracker    = new ProgressTrackerImpl(_session);
 }
Exemple #8
0
 public override void Abort(DistributedOperation operation)
 {
     throw new System.NotSupportedException();
 }
Exemple #9
0
 public override void TrackResult(DistributedOperation operation, Result result)
 {
     throw new System.NotSupportedException();
 }
Exemple #10
0
 public abstract Progress Start(DistributedOperation operation);
Exemple #11
0
 public override Progress Start(DistributedOperation operation)
 {
     Last = new Progress();
     return(Last);
 }
Exemple #12
0
 public override void Abort(DistributedOperation operation)
 {
     _tracker.Remove(operation.OperationId());
 }