Search in sources :

Example 16 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)

Example 17 with ClusterException

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

the class ClusterBackupAgent method slowTick.

private int slowTick(final long nowMs) {
    int workCount = aeronClientInvoker.invoke();
    if (aeron.isClosed()) {
        throw new AgentTerminationException("unexpected Aeron close");
    }
    if (nowMs >= markFileUpdateDeadlineMs) {
        markFileUpdateDeadlineMs = nowMs + MARK_FILE_UPDATE_INTERVAL_MS;
        markFile.updateActivityTimestamp(nowMs);
    }
    workCount += pollBackupArchiveEvents();
    if (NULL_VALUE == correlationId && null != clusterArchive) {
        final String errorResponse = clusterArchive.pollForErrorResponse();
        if (null != errorResponse) {
            ctx.countedErrorHandler().onError(new ClusterException("cluster archive - " + errorResponse, WARN));
            state(RESET_BACKUP, nowMs);
        }
    }
    return workCount;
}
Also used : AgentTerminationException(org.agrona.concurrent.AgentTerminationException) ClusterException(io.aeron.cluster.client.ClusterException)

Example 18 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)

Example 19 with ClusterException

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

the class Election method ensureRecordingLogCoherent.

private void ensureRecordingLogCoherent(final long leadershipTermId, final long logTermBasePosition, final long logPosition, final long nowNs) {
    final long recordingId = consensusModuleAgent.logRecordingId();
    if (NULL_VALUE == recordingId) {
        if (0 == logPosition) {
            return;
        }
        throw new AgentTerminationException("log recording id not found");
    }
    final long timestamp = ctx.clusterClock().timeUnit().convert(nowNs, TimeUnit.NANOSECONDS);
    final RecordingLog recordingLog = ctx.recordingLog();
    RecordingLog.Entry lastTerm = recordingLog.findLastTerm();
    if (null == lastTerm) {
        for (long termId = 0; termId < leadershipTermId; termId++) {
            recordingLog.appendTerm(recordingId, termId, 0, timestamp);
            recordingLog.commitLogPosition(termId, 0);
        }
        recordingLog.appendTerm(recordingId, leadershipTermId, 0, timestamp);
        if (NULL_VALUE != logPosition) {
            recordingLog.commitLogPosition(leadershipTermId, logPosition);
        }
    } else if (lastTerm.leadershipTermId < leadershipTermId) {
        if (NULL_VALUE == lastTerm.logPosition) {
            if (NULL_VALUE == logTermBasePosition) {
                throw new ClusterException("Prior term was not committed: " + lastTerm + " and logTermBasePosition was not specified: leadershipTermId = " + leadershipTermId + ", logTermBasePosition = " + logTermBasePosition + ", logPosition = " + logPosition + ", nowNs = " + nowNs);
            } else {
                recordingLog.commitLogPosition(lastTerm.leadershipTermId, logTermBasePosition);
                lastTerm = Objects.requireNonNull(recordingLog.findLastTerm());
            }
        }
        for (long termId = lastTerm.leadershipTermId + 1; termId < leadershipTermId; termId++) {
            recordingLog.appendTerm(recordingId, termId, lastTerm.logPosition, timestamp);
            recordingLog.commitLogPosition(termId, lastTerm.logPosition);
        }
        recordingLog.appendTerm(recordingId, leadershipTermId, lastTerm.logPosition, timestamp);
        if (NULL_VALUE != logPosition) {
            recordingLog.commitLogPosition(leadershipTermId, logPosition);
        }
    } else {
        if (NULL_VALUE != logPosition) {
            recordingLog.commitLogPosition(leadershipTermId, logPosition);
        }
    }
    recordingLog.force(ctx.fileSyncLevel());
}
Also used : AgentTerminationException(org.agrona.concurrent.AgentTerminationException) ClusterException(io.aeron.cluster.client.ClusterException)

Example 20 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)

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