Search in sources :

Example 6 with ClusterEvent

use of io.aeron.cluster.client.ClusterEvent in project Aeron by real-logic.

the class ConsensusModuleAgent method onUnavailableCounter.

private void onUnavailableCounter(final CountersReader counters, final long registrationId, final int counterId) {
    if (ConsensusModule.State.TERMINATING != state && ConsensusModule.State.QUITTING != state) {
        for (final long clientId : serviceClientIds) {
            if (registrationId == clientId) {
                ctx.countedErrorHandler().onError(new ClusterEvent("Aeron client in service closed unexpectedly"));
                state(ConsensusModule.State.CLOSED);
                return;
            }
        }
        if (null != appendPosition && appendPosition.registrationId() == registrationId) {
            appendPosition = null;
            logSubscriptionId = NULL_VALUE;
            if (null != election) {
                election.handleError(clusterClock.timeNanos(), new ClusterEvent("log recording ended unexpectedly (null != election)"));
            } else if (NULL_POSITION == terminationPosition) {
                ctx.countedErrorHandler().onError(new ClusterEvent("log recording ended unexpectedly (NULL_POSITION == terminationPosition"));
                isElectionRequired = true;
            }
        }
    }
}
Also used : ClusterEvent(io.aeron.cluster.client.ClusterEvent)

Example 7 with ClusterEvent

use of io.aeron.cluster.client.ClusterEvent 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 8 with ClusterEvent

use of io.aeron.cluster.client.ClusterEvent in project aeron by real-logic.

the class ConsensusModuleAgent method onCommitPosition.

void onCommitPosition(final long leadershipTermId, final long logPosition, final int leaderMemberId) {
    if (null != election) {
        election.onCommitPosition(leadershipTermId, logPosition, leaderMemberId);
    } else if (leadershipTermId == this.leadershipTermId && leaderMemberId == leaderMember.id() && Cluster.Role.FOLLOWER == role) {
        notifiedCommitPosition = logPosition;
        timeOfLastLogUpdateNs = clusterClock.timeNanos();
    } else if (leadershipTermId > this.leadershipTermId && null == dynamicJoin) {
        ctx.countedErrorHandler().onError(new ClusterEvent("unexpected commit position from new leader"));
        enterElection();
    }
}
Also used : ClusterEvent(io.aeron.cluster.client.ClusterEvent)

Example 9 with ClusterEvent

use of io.aeron.cluster.client.ClusterEvent in project aeron by real-logic.

the class ConsensusModuleAgent method replayLogPoll.

int replayLogPoll(final LogAdapter logAdapter, final long stopPosition) {
    int workCount = 0;
    if (ConsensusModule.State.ACTIVE == state || ConsensusModule.State.SUSPENDED == state) {
        final int fragments = logAdapter.poll(stopPosition);
        final long position = logAdapter.position();
        if (fragments > 0) {
            commitPosition.setOrdered(position);
        } else if (logAdapter.isImageClosed() && position < stopPosition) {
            throw new ClusterEvent("unexpected image close when replaying log: position=" + position);
        }
        workCount += fragments;
    }
    workCount += consensusModuleAdapter.poll();
    return workCount;
}
Also used : ClusterEvent(io.aeron.cluster.client.ClusterEvent)

Example 10 with ClusterEvent

use of io.aeron.cluster.client.ClusterEvent in project aeron by real-logic.

the class ConsensusModuleAgent method onNewLeadershipTerm.

void onNewLeadershipTerm(final long logLeadershipTermId, final long nextLeadershipTermId, final long nextTermBaseLogPosition, final long nextLogPosition, final long leadershipTermId, final long termBaseLogPosition, final long logPosition, final long leaderRecordingId, final long timestamp, final int leaderId, final int logSessionId, final boolean isStartup) {
    if (null != election) {
        election.onNewLeadershipTerm(logLeadershipTermId, nextLeadershipTermId, nextTermBaseLogPosition, nextLogPosition, leadershipTermId, termBaseLogPosition, logPosition, leaderRecordingId, timestamp, leaderId, logSessionId, isStartup);
    } else if (Cluster.Role.FOLLOWER == role && leadershipTermId == this.leadershipTermId && leaderId == leaderMember.id()) {
        notifiedCommitPosition = Math.max(notifiedCommitPosition, logPosition);
        timeOfLastLogUpdateNs = clusterClock.timeNanos();
    } else if (leadershipTermId > this.leadershipTermId && null == dynamicJoin) {
        ctx.countedErrorHandler().onError(new ClusterEvent("unexpected new leadership term event"));
        enterElection();
    }
}
Also used : ClusterEvent(io.aeron.cluster.client.ClusterEvent)

Aggregations

ClusterEvent (io.aeron.cluster.client.ClusterEvent)14 ArchiveException (io.aeron.archive.client.ArchiveException)2 RecordingSignalPoller (io.aeron.archive.client.RecordingSignalPoller)2