use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.
the class RecordingWriter method onBlock.
/**
* {@inheritDoc}
*/
public void onBlock(final DirectBuffer termBuffer, final int termOffset, final int length, final int sessionId, final int termId) {
try {
final boolean isPaddingFrame = termBuffer.getShort(typeOffset(termOffset)) == PADDING_FRAME_TYPE;
final int dataLength = isPaddingFrame ? HEADER_LENGTH : length;
final ByteBuffer byteBuffer;
if (null == checksum || isPaddingFrame) {
byteBuffer = termBuffer.byteBuffer();
byteBuffer.limit(termOffset + dataLength).position(termOffset);
} else {
checksumBuffer.putBytes(0, termBuffer, termOffset, dataLength);
computeChecksum(checksum, checksumBuffer, dataLength);
byteBuffer = checksumBuffer.byteBuffer();
byteBuffer.limit(dataLength).position(0);
}
int fileOffset = segmentOffset;
do {
fileOffset += recordingFileChannel.write(byteBuffer, fileOffset);
} while (byteBuffer.remaining() > 0);
if (forceWrites) {
recordingFileChannel.force(forceMetadata);
}
segmentOffset += length;
if (segmentOffset >= segmentLength) {
onFileRollOver();
}
} catch (final ClosedByInterruptException ex) {
close();
throw new ArchiveException("file closed by interrupt, recording aborted", ex, ArchiveException.GENERIC);
} catch (final IOException ex) {
close();
checkErrorType(ex, length);
} catch (final Exception ex) {
close();
LangUtil.rethrowUnchecked(ex);
}
}
use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.
the class BasicArchiveTest method purgeRecordingFailsIfThereAreActiveReplays.
@Test
@InterruptAfter(10)
@SuppressWarnings("try")
public void purgeRecordingFailsIfThereAreActiveReplays() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long stopPosition;
final long subscriptionId = aeronArchive.startRecording(RECORDED_CHANNEL, RECORDED_STREAM_ID, LOCAL);
final long recordingIdFromCounter;
final int sessionId;
try (Subscription subscription = aeron.addSubscription(RECORDED_CHANNEL, RECORDED_STREAM_ID);
Publication publication = aeron.addPublication(RECORDED_CHANNEL, RECORDED_STREAM_ID)) {
sessionId = publication.sessionId();
final CountersReader counters = aeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, sessionId);
recordingIdFromCounter = RecordingPos.getRecordingId(counters, counterId);
assertEquals(CommonContext.IPC_CHANNEL, RecordingPos.getSourceIdentity(counters, counterId));
offer(publication, messageCount, messagePrefix);
consume(subscription, messageCount, messagePrefix);
stopPosition = publication.position();
awaitPosition(counters, counterId, stopPosition);
final long joinPosition = subscription.imageBySessionId(sessionId).joinPosition();
assertEquals(joinPosition, aeronArchive.getStartPosition(recordingIdFromCounter));
assertEquals(stopPosition, aeronArchive.getRecordingPosition(recordingIdFromCounter));
assertEquals(NULL_VALUE, aeronArchive.getStopPosition(recordingIdFromCounter));
}
aeronArchive.stopRecording(subscriptionId);
final long recordingId = aeronArchive.findLastMatchingRecording(0, "alias=" + RECORDED_CHANNEL_ALIAS, RECORDED_STREAM_ID, sessionId);
assertEquals(recordingIdFromCounter, recordingId);
assertEquals(stopPosition, aeronArchive.getStopPosition(recordingIdFromCounter));
final long position = 0L;
final long length = stopPosition - position;
try (Subscription ignore = aeronArchive.replay(recordingId, position, length, REPLAY_CHANNEL, REPLAY_STREAM_ID)) {
final ArchiveException exception = assertThrows(ArchiveException.class, () -> aeronArchive.purgeRecording(recordingId));
assertThat(exception.getMessage(), endsWith("error: cannot purge recording with active replay " + recordingId));
final String[] segmentFiles = Catalog.listSegmentFiles(archiveDir, recordingId);
assertNotNull(segmentFiles);
assertNotEquals(0, segmentFiles.length);
for (final String segmentFile : segmentFiles) {
assertTrue(new File(archiveDir, segmentFile).exists());
}
}
}
use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.
the class BasicArchiveTest method purgeRecordingFailsIfRecordingIsActive.
@Test
@InterruptAfter(10)
public void purgeRecordingFailsIfRecordingIsActive() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long stopPosition;
final long subscriptionId = aeronArchive.startRecording(RECORDED_CHANNEL, RECORDED_STREAM_ID, LOCAL);
try {
final long recordingIdFromCounter;
final int sessionId;
try (Subscription subscription = aeron.addSubscription(RECORDED_CHANNEL, RECORDED_STREAM_ID);
Publication publication = aeron.addPublication(RECORDED_CHANNEL, RECORDED_STREAM_ID)) {
sessionId = publication.sessionId();
final CountersReader counters = aeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, sessionId);
recordingIdFromCounter = RecordingPos.getRecordingId(counters, counterId);
assertEquals(CommonContext.IPC_CHANNEL, RecordingPos.getSourceIdentity(counters, counterId));
offer(publication, messageCount, messagePrefix);
consume(subscription, messageCount, messagePrefix);
stopPosition = publication.position();
awaitPosition(counters, counterId, stopPosition);
final long joinPosition = subscription.imageBySessionId(sessionId).joinPosition();
assertEquals(joinPosition, aeronArchive.getStartPosition(recordingIdFromCounter));
assertEquals(stopPosition, aeronArchive.getRecordingPosition(recordingIdFromCounter));
assertEquals(NULL_VALUE, aeronArchive.getStopPosition(recordingIdFromCounter));
final long recordingId = aeronArchive.findLastMatchingRecording(0, "alias=" + RECORDED_CHANNEL_ALIAS, RECORDED_STREAM_ID, sessionId);
assertEquals(recordingIdFromCounter, recordingId);
final ArchiveException exception = assertThrows(ArchiveException.class, () -> aeronArchive.purgeRecording(recordingId));
assertThat(exception.getMessage(), endsWith("error: cannot purge active recording " + recordingId));
final String[] segmentFiles = Catalog.listSegmentFiles(archiveDir, recordingId);
assertNotNull(segmentFiles);
assertNotEquals(0, segmentFiles.length);
for (final String segmentFile : segmentFiles) {
assertTrue(new File(archiveDir, segmentFile).exists());
}
}
} finally {
aeronArchive.stopRecording(subscriptionId);
}
}
use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.
the class Catalog method refreshAndFixDescriptor.
private void refreshAndFixDescriptor(final RecordingDescriptorHeaderDecoder headerDecoder, final RecordingDescriptorEncoder encoder, final RecordingDescriptorDecoder decoder, final Checksum checksum, final UnsafeBuffer buffer) {
final long recordingId = decoder.recordingId();
if (VALID == headerDecoder.state() && NULL_POSITION == decoder.stopPosition()) {
final String[] segmentFiles = listSegmentFiles(archiveDir, recordingId);
final String maxSegmentFile = findSegmentFileWithHighestPosition(segmentFiles);
encoder.stopPosition(computeStopPosition(archiveDir, maxSegmentFile, decoder.startPosition(), decoder.termBufferLength(), decoder.segmentFileLength(), checksum, buffer, (segmentFile) -> {
throw new ArchiveException("Found potentially incomplete last fragment straddling page boundary in file: " + segmentFile.getAbsolutePath() + "\nRun `ArchiveTool verify` for corrective action!");
}));
encoder.stopTimestamp(epochClock.time());
}
}
use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.
the class Catalog method growCatalog.
void growCatalog(final long maxCatalogCapacity, final int frameLength) {
final long oldCapacity = capacity;
final long recordingOffset = nextRecordingDescriptorOffset;
final long targetCapacity = recordingOffset + frameLength;
if (targetCapacity > maxCatalogCapacity) {
if (maxCatalogCapacity == oldCapacity) {
throw new ArchiveException("catalog is full, max capacity reached: " + maxCatalogCapacity);
} else {
throw new ArchiveException("recording is too big: total recording length is " + frameLength + " bytes," + " available space is " + (maxCatalogCapacity - recordingOffset) + " bytes");
}
}
long newCapacity = oldCapacity;
while (newCapacity < targetCapacity) {
newCapacity = min(newCapacity + (newCapacity >> 1), maxCatalogCapacity);
}
final MappedByteBuffer mappedByteBuffer;
try {
unmapAndCloseChannel();
catalogChannel = FileChannel.open(catalogFile.toPath(), READ, WRITE, SPARSE);
mappedByteBuffer = catalogChannel.map(READ_WRITE, 0, newCapacity);
} catch (final Exception ex) {
close();
LangUtil.rethrowUnchecked(ex);
return;
}
capacity = newCapacity;
initBuffers(mappedByteBuffer);
final UnsafeBuffer catalogHeaderBuffer = new UnsafeBuffer(catalogByteBuffer);
catalogHeaderDecoder.wrap(catalogHeaderBuffer, 0, CatalogHeaderDecoder.BLOCK_LENGTH, CatalogHeaderDecoder.SCHEMA_VERSION);
catalogHeaderEncoder.wrap(catalogHeaderBuffer, 0);
catalogResized(oldCapacity, newCapacity);
}
Aggregations