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); } } }
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(); } } }
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); }
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(); } } }
public int Poll() { return(image.BoundedControlledPoll(fragmentAssembler, upperBound.Get(), FRAGMENT_LIMIT)); }
public bool IsCaughtUp() { return(image.Position() >= upperBound.Get()); }