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