use of io.aeron.archive.client.RecordingSignalPoller in project Aeron by real-logic.
the class ConsensusModuleAgent method pollArchiveEvents.
int pollArchiveEvents() {
int workCount = 0;
if (null != archive) {
final RecordingSignalPoller poller = this.recordingSignalPoller;
workCount += poller.poll();
if (poller.isPollComplete()) {
final int templateId = poller.templateId();
if (ControlResponseDecoder.TEMPLATE_ID == templateId && poller.code() == ControlResponseCode.ERROR) {
for (final ClusterMember member : activeMembers) {
if (member.catchupReplayCorrelationId() == poller.correlationId()) {
member.catchupReplaySessionId(NULL_VALUE);
member.catchupReplayCorrelationId(NULL_VALUE);
ctx.countedErrorHandler().onError(new ClusterEvent("catchup replay failed - " + poller.errorMessage()));
return workCount;
}
}
final ArchiveException ex = new ArchiveException(poller.errorMessage(), (int) poller.relevantId(), poller.correlationId());
if (ex.errorCode() == ArchiveException.STORAGE_SPACE) {
ctx.countedErrorHandler().onError(ex);
unexpectedTermination();
}
if (null != election) {
election.handleError(clusterClock.timeNanos(), ex);
}
} else if (RecordingSignalEventDecoder.TEMPLATE_ID == templateId) {
final long recordingId = poller.recordingId();
final long position = poller.recordingPosition();
final RecordingSignal signal = poller.recordingSignal();
if (RecordingSignal.STOP == signal && recordingId == logRecordingId) {
this.logRecordedPosition = position;
}
if (null != election) {
election.onRecordingSignal(poller.correlationId(), recordingId, position, signal);
}
if (null != dynamicJoin) {
dynamicJoin.onRecordingSignal(poller.correlationId(), recordingId, position, signal);
}
}
} else if (0 == workCount && !poller.subscription().isConnected()) {
ctx.countedErrorHandler().onError(new ClusterEvent("local archive is not connected"));
unexpectedTermination();
}
}
return workCount;
}
use of io.aeron.archive.client.RecordingSignalPoller in project aeron by real-logic.
the class ConsensusModuleAgent method pollArchiveEvents.
int pollArchiveEvents() {
int workCount = 0;
if (null != archive) {
final RecordingSignalPoller poller = this.recordingSignalPoller;
workCount += poller.poll();
if (poller.isPollComplete()) {
final int templateId = poller.templateId();
if (ControlResponseDecoder.TEMPLATE_ID == templateId && poller.code() == ControlResponseCode.ERROR) {
for (final ClusterMember member : activeMembers) {
if (member.catchupReplayCorrelationId() == poller.correlationId()) {
member.catchupReplaySessionId(NULL_VALUE);
member.catchupReplayCorrelationId(NULL_VALUE);
ctx.countedErrorHandler().onError(new ClusterEvent("catchup replay failed - " + poller.errorMessage()));
return workCount;
}
}
final ArchiveException ex = new ArchiveException(poller.errorMessage(), (int) poller.relevantId(), poller.correlationId());
if (ex.errorCode() == ArchiveException.STORAGE_SPACE) {
ctx.countedErrorHandler().onError(ex);
unexpectedTermination();
}
if (null != election) {
election.handleError(clusterClock.timeNanos(), ex);
}
} else if (RecordingSignalEventDecoder.TEMPLATE_ID == templateId) {
final long recordingId = poller.recordingId();
final long position = poller.recordingPosition();
final RecordingSignal signal = poller.recordingSignal();
if (RecordingSignal.STOP == signal && recordingId == logRecordingId) {
this.logRecordedPosition = position;
}
if (null != election) {
election.onRecordingSignal(poller.correlationId(), recordingId, position, signal);
}
if (null != dynamicJoin) {
dynamicJoin.onRecordingSignal(poller.correlationId(), recordingId, position, signal);
}
}
} else if (0 == workCount && !poller.subscription().isConnected()) {
ctx.countedErrorHandler().onError(new ClusterEvent("local archive is not connected"));
unexpectedTermination();
}
}
return workCount;
}
use of io.aeron.archive.client.RecordingSignalPoller in project aeron by real-logic.
the class ConsensusModuleAgent method onStart.
/**
* {@inheritDoc}
*/
public void onStart() {
archive = AeronArchive.connect(ctx.archiveContext().clone());
recordingSignalPoller = new RecordingSignalPoller(archive.controlSessionId(), archive.controlResponsePoller().subscription());
if (null == (dynamicJoin = requiresDynamicJoin())) {
final long lastTermRecordingId = recordingLog.findLastTermRecordingId();
if (NULL_VALUE != lastTermRecordingId) {
archive.tryStopRecordingByIdentity(lastTermRecordingId);
}
recoveryPlan = recordingLog.createRecoveryPlan(archive, ctx.serviceCount(), logRecordingId);
if (null != recoveryPlan.log) {
logRecordingId = recoveryPlan.log.recordingId;
}
try (Counter counter = addRecoveryStateCounter(recoveryPlan)) {
assert null != counter;
if (!recoveryPlan.snapshots.isEmpty()) {
loadSnapshot(recoveryPlan.snapshots.get(0), archive);
}
while (!ServiceAck.hasReached(expectedAckPosition, serviceAckId, serviceAckQueues)) {
idle(consensusModuleAdapter.poll());
}
captureServiceClientIds();
++serviceAckId;
}
ClusterMember.addConsensusPublications(activeMembers, thisMember, ctx.consensusChannel(), ctx.consensusStreamId(), aeron, ctx.countedErrorHandler());
election = new Election(true, recoveryPlan.lastLeadershipTermId, commitPosition.getWeak(), recoveryPlan.appendedLogPosition, activeMembers, clusterMemberByIdMap, thisMember, consensusPublisher, ctx, this);
election.doWork(clusterClock.timeNanos());
state(ConsensusModule.State.ACTIVE);
}
unavailableCounterHandlerRegistrationId = aeron.addUnavailableCounterHandler(this::onUnavailableCounter);
}
use of io.aeron.archive.client.RecordingSignalPoller in project Aeron by real-logic.
the class ConsensusModuleAgent method onStart.
/**
* {@inheritDoc}
*/
public void onStart() {
archive = AeronArchive.connect(ctx.archiveContext().clone());
recordingSignalPoller = new RecordingSignalPoller(archive.controlSessionId(), archive.controlResponsePoller().subscription());
if (null == (dynamicJoin = requiresDynamicJoin())) {
final long lastTermRecordingId = recordingLog.findLastTermRecordingId();
if (NULL_VALUE != lastTermRecordingId) {
archive.tryStopRecordingByIdentity(lastTermRecordingId);
}
recoveryPlan = recordingLog.createRecoveryPlan(archive, ctx.serviceCount(), logRecordingId);
if (null != recoveryPlan.log) {
logRecordingId = recoveryPlan.log.recordingId;
}
try (Counter counter = addRecoveryStateCounter(recoveryPlan)) {
assert null != counter;
if (!recoveryPlan.snapshots.isEmpty()) {
loadSnapshot(recoveryPlan.snapshots.get(0), archive);
}
while (!ServiceAck.hasReached(expectedAckPosition, serviceAckId, serviceAckQueues)) {
idle(consensusModuleAdapter.poll());
}
captureServiceClientIds();
++serviceAckId;
}
ClusterMember.addConsensusPublications(activeMembers, thisMember, ctx.consensusChannel(), ctx.consensusStreamId(), aeron, ctx.countedErrorHandler());
election = new Election(true, recoveryPlan.lastLeadershipTermId, commitPosition.getWeak(), recoveryPlan.appendedLogPosition, activeMembers, clusterMemberByIdMap, thisMember, consensusPublisher, ctx, this);
election.doWork(clusterClock.timeNanos());
state(ConsensusModule.State.ACTIVE);
}
unavailableCounterHandlerRegistrationId = aeron.addUnavailableCounterHandler(this::onUnavailableCounter);
}
Aggregations