Ejemplo n.º 1
0
 public void OnJoinLog(
     long leadershipTermId,
     int commitPositionId,
     int logSessionId,
     int logStreamId,
     string logChannel)
 {
     _activeLogEvent = new ActiveLogEvent(
         leadershipTermId, commitPositionId, logSessionId, logStreamId, logChannel);
 }
Ejemplo n.º 2
0
        private void JoinActiveLog()
        {
            CountersReader counters         = aeron.CountersReader();
            int            commitPositionId = _activeLogEvent.commitPositionId;

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

            Subscription logSubscription = aeron.AddSubscription(_activeLogEvent.channel, _activeLogEvent.streamId);

            _consensusModuleProxy.Ack(CommitPos.GetLogPosition(counters, commitPositionId), ackId++, serviceId);

            Image image = AwaitImage(_activeLogEvent.sessionId, logSubscription);

            heartbeatCounter.SetOrdered(epochClock.Time());

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

            Role((ClusterRole)roleCounter.Get());

            foreach (ClientSession session in sessionByIdMap.Values)
            {
                if (ClusterRole.Leader == role)
                {
                    if (ctx.IsRespondingService())
                    {
                        session.Connect(aeron);
                    }

                    session.ResetClosing();
                }
                else
                {
                    session.Disconnect();
                }
            }
        }
Ejemplo n.º 3
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());
            }
        }