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());
}
}
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;
}
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;
}
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());
}
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;
}
}
Aggregations