Example #1
0
        private void CheckForSnapshot(CountersReader counters, int recoveryCounterId)
        {
            long leadershipTermId = RecoveryState.GetLeadershipTermId(counters, recoveryCounterId);

            clusterTimeMs = RecoveryState.GetTimestamp(counters, recoveryCounterId);

            if (Adaptive.Aeron.Aeron.NULL_VALUE != leadershipTermId)
            {
                LoadSnapshot(RecoveryState.GetSnapshotRecordingId(counters, recoveryCounterId, serviceId));
            }

            heartbeatCounter.SetOrdered(epochClock.Time());
            _consensusModuleProxy.Ack(RecoveryState.GetLogPosition(counters, recoveryCounterId), ackId++, serviceId);
        }
Example #2
0
        private int AwaitRecoveryCounter(CountersReader counters)
        {
            idleStrategy.Reset();
            int counterId = RecoveryState.FindCounterId(counters);

            while (CountersReader.NULL_COUNTER_ID == counterId)
            {
                CheckInterruptedStatus();
                idleStrategy.Idle();

                counterId = RecoveryState.FindCounterId(counters);
            }

            return(counterId);
        }
Example #3
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();
        }
Example #4
0
        private void CheckForSnapshot(CountersReader counters, int recoveryCounterId)
        {
            long termPosition = RecoveryState.GetTermPosition(counters, recoveryCounterId);

            leadershipTermId = RecoveryState.GetLeadershipTermId(counters, recoveryCounterId);
            timestampMs      = RecoveryState.GetTimestamp(counters, recoveryCounterId);

            if (AeronArchive.NULL_POSITION != termPosition)
            {
                RecordingLog.Entry snapshotEntry = recordingLog.GetSnapshot(leadershipTermId, termPosition);
                if (null == snapshotEntry)
                {
                    throw new InvalidOperationException(
                              "no snapshot available for term position: " + termPosition);
                }

                termBaseLogPosition = snapshotEntry.termBaseLogPosition + snapshotEntry.termPosition;
                LoadSnapshot(snapshotEntry.recordingId);
            }

            serviceControlPublisher.AckAction(termBaseLogPosition, leadershipTermId, serviceId, ClusterAction.INIT);
        }
Example #5
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());
            }
        }