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