예제 #1
0
 internal BoundedLogAdapter(Image image, ReadableCounter upperBound, ClusteredServiceAgent agent)
 {
     fragmentAssembler = new ImageControlledFragmentAssembler(this, INITIAL_BUFFER_LENGTH);
     this.image        = image;
     this.upperBound   = upperBound;
     this.agent        = agent;
 }
예제 #2
0
        public void OnStart()
        {
            service.OnStart(this);

            CountersReader counters          = aeron.CountersReader();
            int            recoveryCounterId = AwaitRecoveryCounterId(counters);

            isRecovering = true;
            CheckForSnapshot(counters, recoveryCounterId);
            CheckForReplay(counters, recoveryCounterId);
            isRecovering = false;

            JoinActiveLog(counters);

            roleCounter = AwaitClusterRoleCounter(counters);
            role        = (ClusterRole)roleCounter.Get();

            if (ClusterRole.Leader == role)
            {
                foreach (ClientSession session in sessionByIdMap.Values)
                {
                    session.Connect(aeron);
                }
            }
        }
예제 #3
0
        public void OnStart()
        {
            aeron.AddCloseHandler(abortHandler);
            CountersReader counters = aeron.CountersReader;

            roleCounter    = AwaitClusterRoleCounter(counters, ctx.ClusterId());
            commitPosition = AwaitCommitPositionCounter(counters, ctx.ClusterId());

            RecoverState(counters);
        }
예제 #4
0
        public void OnStart()
        {
            CountersReader counters = aeron.CountersReader;

            roleCounter    = AwaitClusterRoleCounter(counters);
            commitPosition = AwaitCommitPositionCounter(counters);

            int recoveryCounterId = AwaitRecoveryCounter(counters);

            isServiceActive = true;
            CheckForSnapshot(counters, recoveryCounterId);
            CheckForReplay(counters, recoveryCounterId);
        }
예제 #5
0
        public void OnStart()
        {
            CountersReader counters = aeron.CountersReader();

            roleCounter = AwaitClusterRoleCounter(counters);
            FindHeartbeatCounter(counters);

            service.OnStart(this);
            isRecovering = true;
            int recoveryCounterId = AwaitRecoveryCounter(counters);

            CheckForSnapshot(counters, recoveryCounterId);
            CheckForReplay(counters, recoveryCounterId);
            isRecovering = false;
            service.OnReady();
        }
예제 #6
0
        public void OnStart()
        {
            CountersReader counters = aeron.CountersReader;

            roleCounter      = AwaitClusterRoleCounter(counters);
            heartbeatCounter = AwaitHeartbeatCounter(counters);
            commitPosition   = AwaitCommitPositionCounter(counters);

            service.OnStart(this);

            int recoveryCounterId = AwaitRecoveryCounter(counters);

            heartbeatCounter.SetOrdered(epochClock.Time());
            CheckForSnapshot(counters, recoveryCounterId);
            CheckForReplay(counters, recoveryCounterId);
        }
예제 #7
0
        private void CheckForReplay(CountersReader counters, int recoveryCounterId)
        {
            long replayTermCount = RecoveryState.GetReplayTermCount(counters, recoveryCounterId);

            if (0 == replayTermCount)
            {
                return;
            }

            service.OnReplayBegin();

            for (int i = 0; i < replayTermCount; i++)
            {
                AwaitActiveLog();
                int counterId = newActiveLogEvent.commitPositionId;
                leadershipTermId    = CommitPos.GetLeadershipTermId(counters, counterId);
                termBaseLogPosition = CommitPos.GetTermBaseLogPosition(counters, counterId); // TODO MARK

                if (CommitPos.GetLeadershipTermLength(counters, counterId) > 0)
                {
                    using (Subscription subscription = aeron.AddSubscription(newActiveLogEvent.channel, newActiveLogEvent.streamId))
                    {
                        serviceControlPublisher.AckAction(termBaseLogPosition, leadershipTermId, serviceId, ClusterAction.READY);

                        Image             image   = AwaitImage(newActiveLogEvent.sessionId, subscription);
                        ReadableCounter   limit   = new ReadableCounter(counters, counterId);
                        BoundedLogAdapter adapter = new BoundedLogAdapter(image, limit, this);

                        ConsumeImage(image, adapter);

                        termBaseLogPosition += image.Position();
                    }
                }

                newActiveLogEvent = null;
                serviceControlPublisher.AckAction(termBaseLogPosition, leadershipTermId, serviceId, ClusterAction.REPLAY);
            }

            service.OnReplayEnd();
        }
예제 #8
0
        private void CheckForReplay(CountersReader counters, int recoveryCounterId)
        {
            if (RecoveryState.HasReplay(counters, recoveryCounterId))
            {
                AwaitActiveLog();

                int counterId = _activeLogEvent.commitPositionId;

                using (Subscription subscription = aeron.AddSubscription(_activeLogEvent.channel, _activeLogEvent.streamId))
                {
                    _consensusModuleProxy.Ack(CommitPos.GetLogPosition(counters, counterId), ackId++, serviceId);

                    Image             image   = AwaitImage(_activeLogEvent.sessionId, subscription);
                    ReadableCounter   limit   = new ReadableCounter(counters, counterId);
                    BoundedLogAdapter adapter = new BoundedLogAdapter(image, limit, this);

                    ConsumeImage(image, adapter);
                }

                _activeLogEvent = null;
                heartbeatCounter.SetOrdered(epochClock.Time());
            }
        }