Search in sources :

Example 21 with ClusterException

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

the class LogReplication method isDone.

boolean isDone(final long nowNs) {
    if (position == stopPosition && isStopped) {
        return true;
    }
    if (position > stopPosition) {
        throw new ClusterException("log replication has progressed past stopPosition: " + this);
    }
    if (nowNs >= progressCheckDeadlineNs) {
        progressCheckDeadlineNs = nowNs + progressCheckIntervalNs;
        if (NULL_COUNTER_ID != recordingPositionCounterId) {
            final CountersReader counters = archive.context().aeron().countersReader();
            final long recordingPosition = counters.getCounterValue(recordingPositionCounterId);
            if (RecordingPos.isActive(counters, recordingPositionCounterId, recordingId) && recordingPosition > position) {
                position = recordingPosition;
                progressDeadlineNs = nowNs + progressCheckTimeoutNs;
            }
        }
    }
    if (nowNs >= progressDeadlineNs) {
        if (position < stopPosition) {
            throw new ClusterException("log replication has not progressed: " + this, AeronException.Category.WARN);
        } else {
            throw new ClusterException("log replication failed to stop: " + this);
        }
    }
    return false;
}
Also used : ClusterException(io.aeron.cluster.client.ClusterException) CountersReader(org.agrona.concurrent.status.CountersReader)

Example 22 with ClusterException

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

the class ClusteredServiceAgent method onNewLeadershipTermEvent.

void onNewLeadershipTermEvent(final long leadershipTermId, final long logPosition, final long timestamp, final long termBaseLogPosition, final int leaderMemberId, final int logSessionId, final TimeUnit timeUnit, final int appVersion) {
    if (SemanticVersion.major(ctx.appVersion()) != SemanticVersion.major(appVersion)) {
        ctx.errorHandler().onError(new ClusterException("incompatible version: " + SemanticVersion.toString(ctx.appVersion()) + " log=" + SemanticVersion.toString(appVersion)));
        throw new AgentTerminationException();
    } else {
        sessionMessageHeaderEncoder.leadershipTermId(leadershipTermId);
        this.logPosition = logPosition;
        clusterTime = timestamp;
        this.timeUnit = timeUnit;
        service.onNewLeadershipTermEvent(leadershipTermId, logPosition, timestamp, termBaseLogPosition, leaderMemberId, logSessionId, timeUnit, appVersion);
    }
}
Also used : ClusterException(io.aeron.cluster.client.ClusterException)

Example 23 with ClusterException

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

the class ServiceProxy method terminationPosition.

void terminationPosition(final long logPosition, final ErrorHandler errorHandler) {
    if (!publication.isClosed()) {
        final int length = MessageHeaderDecoder.ENCODED_LENGTH + ServiceTerminationPositionEncoder.BLOCK_LENGTH;
        long result;
        int attempts = SEND_ATTEMPTS;
        do {
            result = publication.tryClaim(length, bufferClaim);
            if (result > 0) {
                serviceTerminationPositionEncoder.wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder).logPosition(logPosition);
                bufferClaim.commit();
                return;
            }
            if (Publication.BACK_PRESSURED == result) {
                Thread.yield();
            }
        } while (--attempts > 0);
        errorHandler.onError(new ClusterException("failed to send service termination position: result=" + result, AeronException.Category.WARN));
    }
}
Also used : ClusterException(io.aeron.cluster.client.ClusterException)

Example 24 with ClusterException

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

the class ConsensusModuleAgent method onReplayNewLeadershipTermEvent.

void onReplayNewLeadershipTermEvent(final long leadershipTermId, final long logPosition, final long timestamp, final long termBaseLogPosition, final TimeUnit timeUnit, final int appVersion) {
    if (timeUnit != clusterTimeUnit) {
        ctx.countedErrorHandler().onError(new ClusterException("incompatible timestamp units: " + clusterTimeUnit + " log=" + timeUnit, AeronException.Category.FATAL));
        unexpectedTermination();
    }
    if (SemanticVersion.major(ctx.appVersion()) != SemanticVersion.major(appVersion)) {
        ctx.countedErrorHandler().onError(new ClusterException("incompatible version: " + SemanticVersion.toString(ctx.appVersion()) + " log=" + SemanticVersion.toString(appVersion), AeronException.Category.FATAL));
        unexpectedTermination();
    }
    leadershipTermId(leadershipTermId);
    if (null != election) {
        election.onReplayNewLeadershipTermEvent(logRecordingId, leadershipTermId, logPosition, timestamp, termBaseLogPosition);
    }
}
Also used : ClusterException(io.aeron.cluster.client.ClusterException)

Example 25 with ClusterException

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

the class ClusterBackupAgent method pollBackupArchiveEvents.

private int pollBackupArchiveEvents() {
    int workCount = 0;
    if (null != backupArchive) {
        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) {
                final ArchiveException ex = new ArchiveException(poller.errorMessage(), (int) poller.relevantId(), poller.correlationId());
                if (ex.errorCode() == ArchiveException.STORAGE_SPACE) {
                    ctx.countedErrorHandler().onError(ex);
                    throw new AgentTerminationException();
                } else {
                    throw ex;
                }
            } else if (RecordingSignalEventDecoder.TEMPLATE_ID == templateId && null != snapshotReplication) {
                snapshotReplication.onSignal(poller.correlationId(), poller.recordingId(), poller.recordingPosition(), poller.recordingSignal());
            }
        } else if (0 == workCount && !poller.subscription().isConnected()) {
            ctx.countedErrorHandler().onError(new ClusterException("local archive is not connected", WARN));
            throw new AgentTerminationException();
        }
    }
    return workCount;
}
Also used : AgentTerminationException(org.agrona.concurrent.AgentTerminationException) ClusterException(io.aeron.cluster.client.ClusterException)

Aggregations

ClusterException (io.aeron.cluster.client.ClusterException)34 Test (org.junit.jupiter.api.Test)12 AgentTerminationException (org.agrona.concurrent.AgentTerminationException)6 CountersReader (org.agrona.concurrent.status.CountersReader)4 AeronException (io.aeron.exceptions.AeronException)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 ByteBuffer (java.nio.ByteBuffer)2 MappedByteBuffer (java.nio.MappedByteBuffer)2 FileChannel (java.nio.channels.FileChannel)2 Path (java.nio.file.Path)2 TimeUnit (java.util.concurrent.TimeUnit)2 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2