Пример #1
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 = activeLog.commitPositionId;
                baseLogPosition  = CommitPos.GetBaseLogPosition(counters, counterId);
                leadershipTermId = CommitPos.GetLeadershipTermId(counters, counterId);

                using (Subscription subscription = aeron.AddSubscription(activeLog.channel, activeLog.streamId))
                {
                    serviceControlPublisher.AckAction(baseLogPosition, leadershipTermId, serviceId,
                                                      ClusterAction.READY);

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

                    ConsumeImage(image, adapter);

                    long logPosition = baseLogPosition + image.Position();
                    serviceControlPublisher.AckAction(logPosition, leadershipTermId, serviceId, ClusterAction.REPLAY);
                }
            }

            service.OnReplayEnd();
        }
Пример #2
0
        private void JoinActiveLog(CountersReader counters)
        {
            AwaitActiveLog();

            int commitPositionId = activeLog.commitPositionId;

            if (!CommitPos.IsActive(counters, commitPositionId))
            {
                throw new System.InvalidOperationException("CommitPos counter not active: " + commitPositionId);
            }

            int logSessionId = activeLog.sessionId;

            leadershipTermId = activeLog.leadershipTermId;
            baseLogPosition  = CommitPos.GetBaseLogPosition(counters, commitPositionId);

            Subscription logSubscription = aeron.AddSubscription(activeLog.channel, activeLog.streamId);
            Image        image           = AwaitImage(logSessionId, logSubscription);

            serviceControlPublisher.AckAction(baseLogPosition, leadershipTermId, serviceId, ClusterAction.READY);

            logAdapter = new BoundedLogAdapter(image, new ReadableCounter(counters, commitPositionId), this);
            activeLog  = null;
        }