Search in sources :

Example 1 with RecordingSignalPoller

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;
}
Also used : ClusterEvent(io.aeron.cluster.client.ClusterEvent) RecordingSignalPoller(io.aeron.archive.client.RecordingSignalPoller) ArchiveException(io.aeron.archive.client.ArchiveException)

Example 2 with RecordingSignalPoller

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;
}
Also used : ClusterEvent(io.aeron.cluster.client.ClusterEvent) RecordingSignalPoller(io.aeron.archive.client.RecordingSignalPoller) ArchiveException(io.aeron.archive.client.ArchiveException)

Example 3 with RecordingSignalPoller

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);
}
Also used : ReadableCounter(io.aeron.status.ReadableCounter) RecordingSignalPoller(io.aeron.archive.client.RecordingSignalPoller)

Example 4 with RecordingSignalPoller

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);
}
Also used : ReadableCounter(io.aeron.status.ReadableCounter) RecordingSignalPoller(io.aeron.archive.client.RecordingSignalPoller)

Aggregations

RecordingSignalPoller (io.aeron.archive.client.RecordingSignalPoller)4 ArchiveException (io.aeron.archive.client.ArchiveException)2 ClusterEvent (io.aeron.cluster.client.ClusterEvent)2 ReadableCounter (io.aeron.status.ReadableCounter)2