示例#1
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);
                }
            }
        }
示例#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();
                }
            }
        }
示例#3
0
        public int DoWork()
        {
            int workCount = 0;

            if (CheckForClockTick())
            {
                PollServiceAdapter();
                workCount += 1;
            }

            if (null != logAdapter.Image())
            {
                int polled = logAdapter.Poll(commitPosition.Get());
                if (0 == polled && logAdapter.IsDone())
                {
                    CloseLog();
                }

                workCount += polled;
            }

            return(workCount);
        }
示例#4
0
        private void JoinActiveLog()
        {
            if (null != logAdapter)
            {
                if (!logAdapter.IsCaughtUp())
                {
                    return;
                }

                logAdapter.Dispose();
                logAdapter = null;
            }


            CountersReader counters = aeron.CountersReader();

            int commitPositionId = newActiveLogEvent.commitPositionId;

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

            int logSessionId = newActiveLogEvent.sessionId;

            leadershipTermId    = newActiveLogEvent.leadershipTermId;
            termBaseLogPosition = CommitPos.GetTermBaseLogPosition(counters, commitPositionId);

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

            if (newActiveLogEvent.ackBeforeImage)
            {
                serviceControlPublisher.AckAction(termBaseLogPosition, leadershipTermId, serviceId, ClusterAction.READY);
            }

            Image image = AwaitImage(logSessionId, logSubscription);

            heartbeatCounter.SetOrdered(epochClock.Time());

            if (!newActiveLogEvent.ackBeforeImage)
            {
                serviceControlPublisher.AckAction(termBaseLogPosition, leadershipTermId, serviceId, ClusterAction.READY);
            }

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

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

            foreach (ClientSession session in sessionByIdMap.Values)
            {
                if (ClusterRole.Leader == role)
                {
                    session.Connect(aeron);
                }
                else
                {
                    session.Disconnect();
                }
            }
        }
示例#5
0
 public int Poll()
 {
     return(image.BoundedControlledPoll(fragmentAssembler, upperBound.Get(), FRAGMENT_LIMIT));
 }
示例#6
0
 public bool IsCaughtUp()
 {
     return(image.Position() >= upperBound.Get());
 }