Search in sources :

Example 26 with ClusterException

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

the class LogReplication method onSignal.

void onSignal(final long correlationId, final long recordingId, final long position, final RecordingSignal signal) {
    if (correlationId == replicationId) {
        switch(signal) {
            case EXTEND:
                final CountersReader counters = archive.context().aeron().countersReader();
                recordingPositionCounterId = RecordingPos.findCounterIdByRecording(counters, recordingId);
                break;
            case DELETE:
                throw new ClusterException("recording was deleted during replication: " + this);
            case STOP:
                isStopped = true;
                break;
        }
        this.recordingId = recordingId;
        this.position = position;
        this.lastRecordingSignal = signal;
    }
}
Also used : ClusterException(io.aeron.cluster.client.ClusterException) CountersReader(org.agrona.concurrent.status.CountersReader)

Example 27 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 28 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 29 with ClusterException

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

the class RecordingLogTest method appendSnapshotShouldRejectNullValueAsRecordingId.

@Test
void appendSnapshotShouldRejectNullValueAsRecordingId() {
    try (RecordingLog recordingLog = new RecordingLog(tempDir, true)) {
        final ClusterException exception = assertThrows(ClusterException.class, () -> recordingLog.appendSnapshot(NULL_VALUE, 0, 0, 0, 0, 0));
        assertEquals("ERROR - invalid recordingId=-1", exception.getMessage());
        assertEquals(0, recordingLog.entries().size());
    }
}
Also used : ClusterException(io.aeron.cluster.client.ClusterException) Test(org.junit.jupiter.api.Test)

Example 30 with ClusterException

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

the class RecordingLogTest method appendTermShouldOnlyAllowASingleValidTermForTheSameLeadershipTermId.

@Test
void appendTermShouldOnlyAllowASingleValidTermForTheSameLeadershipTermId() {
    try (RecordingLog recordingLog = new RecordingLog(tempDir, true)) {
        recordingLog.appendTerm(8, 0, 0, 0);
        recordingLog.appendTerm(8, 1, 1, 1);
        recordingLog.invalidateEntry(0, 0);
        recordingLog.appendTerm(8, 0, 100, 100);
        final ClusterException exception = assertThrows(ClusterException.class, () -> recordingLog.appendTerm(8, 1, 5, 5));
        assertEquals("ERROR - duplicate TERM entry for leadershipTermId=1", exception.getMessage());
        assertEquals(3, recordingLog.entries().size());
    }
}
Also used : ClusterException(io.aeron.cluster.client.ClusterException) Test(org.junit.jupiter.api.Test)

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