use of java.nio.ByteOrder.LITTLE_ENDIAN in project Aeron by real-logic.
the class ArchiveTool method createVerifyEntryProcessor.
private static CatalogEntryProcessor createVerifyEntryProcessor(final PrintStream out, final File archiveDir, final Set<VerifyOption> options, final Catalog catalog, final Checksum checksum, final EpochClock epochClock, final MutableInteger errorCount, final ActionConfirmation<File> truncateOnPageStraddle) {
final ByteBuffer buffer = BufferUtil.allocateDirectAligned(FILE_IO_MAX_LENGTH_DEFAULT, CACHE_LINE_LENGTH);
buffer.order(LITTLE_ENDIAN);
final DataHeaderFlyweight headerFlyweight = new DataHeaderFlyweight(buffer);
return (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> verifyRecording(out, archiveDir, options, catalog, checksum, epochClock, errorCount, truncateOnPageStraddle, headerFlyweight, recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder);
}
use of java.nio.ByteOrder.LITTLE_ENDIAN in project Aeron by real-logic.
the class ClusterTest method shouldAllowChangingTermBufferLengthAndMtuAfterRecordingLogIsTruncatedToTheLatestSnapshot.
@SuppressWarnings("MethodLength")
@Test
@InterruptAfter(30)
public void shouldAllowChangingTermBufferLengthAndMtuAfterRecordingLogIsTruncatedToTheLatestSnapshot() {
final int originalTermLength = 256 * 1024;
final int originalMtu = 1408;
final int newTermLength = 2 * 1024 * 1024;
final int newMtu = 8992;
final CRC32 crc32 = new CRC32();
cluster = aCluster().withStaticNodes(3).withLogChannel("aeron:udp?term-length=" + originalTermLength + "|mtu=" + originalMtu).withIngressChannel("aeron:udp?term-length=" + originalTermLength + "|mtu=" + originalMtu).withEgressChannel("aeron:udp?endpoint=localhost:0|term-length=" + originalTermLength + "|mtu=" + originalMtu).withServiceSupplier((i) -> new TestNode.TestService[] { new TestNode.TestService(), new TestNode.ChecksumService() }).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
for (int i = 0; i < 3; i++) {
assertEquals(2, cluster.node(i).services().length);
}
cluster.connectClient();
final int firstBatch = 9;
int messageLength = computeMaxMessageLength(originalTermLength) - AeronCluster.SESSION_HEADER_LENGTH;
int payloadLength = messageLength - SIZE_OF_INT;
cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'x');
crc32.reset();
crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
int msgChecksum = (int) crc32.getValue();
cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
long checksum = 0;
for (int i = 0; i < firstBatch; i++) {
cluster.pollUntilMessageSent(messageLength);
checksum = Hashing.hash(checksum ^ msgChecksum);
}
cluster.awaitResponseMessageCount(firstBatch);
cluster.takeSnapshot(leader);
cluster.awaitSnapshotCount(1);
cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'y');
crc32.reset();
crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
msgChecksum = (int) crc32.getValue();
cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
final int secondBatch = 11;
for (int i = 0; i < secondBatch; i++) {
cluster.pollUntilMessageSent(messageLength);
}
cluster.awaitResponseMessageCount(firstBatch + secondBatch);
cluster.stopAllNodes();
// seed all recording logs from the latest snapshot
for (int i = 0; i < 3; i++) {
ClusterTool.seedRecordingLogFromSnapshot(cluster.node(i).consensusModule().context().clusterDir());
}
cluster.logChannel("aeron:udp?term-length=" + newTermLength + "|mtu=" + newMtu);
cluster.ingressChannel("aeron:udp?term-length=" + newTermLength + "|mtu=" + newMtu);
cluster.egressChannel("aeron:udp?endpoint=localhost:0|term-length=" + newTermLength + "|mtu=" + newMtu);
cluster.restartAllNodes(false);
cluster.awaitLeader();
assertEquals(2, cluster.followers().size());
for (int i = 0; i < 3; i++) {
assertEquals(2, cluster.node(i).services().length);
}
cluster.awaitSnapshotsLoaded();
cluster.reconnectClient();
messageLength = computeMaxMessageLength(newTermLength) - AeronCluster.SESSION_HEADER_LENGTH;
payloadLength = messageLength - SIZE_OF_INT;
cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'z');
crc32.reset();
crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
msgChecksum = (int) crc32.getValue();
cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
final int thirdBatch = 5;
for (int i = 0; i < thirdBatch; i++) {
cluster.pollUntilMessageSent(messageLength);
checksum = Hashing.hash(checksum ^ msgChecksum);
}
cluster.awaitResponseMessageCount(firstBatch + secondBatch + thirdBatch);
final int finalMessageCount = firstBatch + thirdBatch;
final long finalChecksum = checksum;
final Predicate<TestNode> finalServiceState = node -> {
final TestNode.TestService[] services = node.services();
return finalMessageCount == services[0].messageCount() && finalChecksum == ((TestNode.ChecksumService) services[1]).checksum();
};
for (int i = 0; i < 3; i++) {
final TestNode node = cluster.node(i);
cluster.awaitServiceState(node, finalServiceState);
}
}
use of java.nio.ByteOrder.LITTLE_ENDIAN in project aeron by real-logic.
the class ExclusivePublicationTest method offerBlockAcceptsUpToAnEntireTermOfData.
@Test
@InterruptAfter(10)
void offerBlockAcceptsUpToAnEntireTermOfData() {
final String channel = "aeron:ipc?term-length=64k";
try (Subscription subscription = aeron.addSubscription(channel, STREAM_ID);
ExclusivePublication publication = aeron.addExclusivePublication(channel, STREAM_ID)) {
final int sessionId = publication.sessionId();
final int streamId = publication.streamId();
final int currentTermId = publication.termId();
final int termBufferLength = publication.termBufferLength();
final int offset = 1024;
final RawBlockHandler rawBlockHandler = (fileChannel, fileOffset, termBuffer, termOffset, length, pollSessionId, termId) -> {
assertEquals(HDR_TYPE_DATA, frameType(termBuffer, termOffset));
assertEquals(termBufferLength, frameLength(termBuffer, termOffset));
assertEquals(sessionId, frameSessionId(termBuffer, termOffset));
assertEquals(streamId, termBuffer.getInt(termOffset + STREAM_ID_FIELD_OFFSET, LITTLE_ENDIAN));
};
frameType(srcBuffer, offset, HDR_TYPE_DATA);
frameLengthOrdered(srcBuffer, offset, termBufferLength);
frameSessionId(srcBuffer, offset, sessionId);
srcBuffer.putInt(offset + STREAM_ID_FIELD_OFFSET, streamId, LITTLE_ENDIAN);
srcBuffer.putInt(offset + TERM_ID_FIELD_OFFSET, currentTermId, LITTLE_ENDIAN);
srcBuffer.setMemory(offset + DATA_OFFSET, termBufferLength - HEADER_LENGTH, (byte) 13);
Tests.awaitConnections(subscription, 1);
while (publication.availableWindow() <= 0) {
Tests.yield();
}
final long position = publication.position();
final long result = publication.offerBlock(srcBuffer, offset, termBufferLength);
assertEquals(position + termBufferLength, result);
final long pollBytes = subscription.rawPoll(rawBlockHandler, termBufferLength);
assertEquals(termBufferLength, pollBytes);
assertEquals(publication.termBufferLength(), publication.termOffset());
assertEquals(currentTermId, publication.termId());
}
}
use of java.nio.ByteOrder.LITTLE_ENDIAN in project Aeron by real-logic.
the class ExclusivePublicationTest method offerBlockAcceptsUpToAnEntireTermOfData.
@Test
@InterruptAfter(10)
void offerBlockAcceptsUpToAnEntireTermOfData() {
final String channel = "aeron:ipc?term-length=64k";
try (Subscription subscription = aeron.addSubscription(channel, STREAM_ID);
ExclusivePublication publication = aeron.addExclusivePublication(channel, STREAM_ID)) {
final int sessionId = publication.sessionId();
final int streamId = publication.streamId();
final int currentTermId = publication.termId();
final int termBufferLength = publication.termBufferLength();
final int offset = 1024;
final RawBlockHandler rawBlockHandler = (fileChannel, fileOffset, termBuffer, termOffset, length, pollSessionId, termId) -> {
assertEquals(HDR_TYPE_DATA, frameType(termBuffer, termOffset));
assertEquals(termBufferLength, frameLength(termBuffer, termOffset));
assertEquals(sessionId, frameSessionId(termBuffer, termOffset));
assertEquals(streamId, termBuffer.getInt(termOffset + STREAM_ID_FIELD_OFFSET, LITTLE_ENDIAN));
};
frameType(srcBuffer, offset, HDR_TYPE_DATA);
frameLengthOrdered(srcBuffer, offset, termBufferLength);
frameSessionId(srcBuffer, offset, sessionId);
srcBuffer.putInt(offset + STREAM_ID_FIELD_OFFSET, streamId, LITTLE_ENDIAN);
srcBuffer.putInt(offset + TERM_ID_FIELD_OFFSET, currentTermId, LITTLE_ENDIAN);
srcBuffer.setMemory(offset + DATA_OFFSET, termBufferLength - HEADER_LENGTH, (byte) 13);
Tests.awaitConnections(subscription, 1);
while (publication.availableWindow() <= 0) {
Tests.yield();
}
final long position = publication.position();
final long result = publication.offerBlock(srcBuffer, offset, termBufferLength);
assertEquals(position + termBufferLength, result);
final long pollBytes = subscription.rawPoll(rawBlockHandler, termBufferLength);
assertEquals(termBufferLength, pollBytes);
assertEquals(publication.termBufferLength(), publication.termOffset());
assertEquals(currentTermId, publication.termId());
}
}
use of java.nio.ByteOrder.LITTLE_ENDIAN in project aeron by real-logic.
the class ClusterTest method shouldAllowChangingTermBufferLengthAndMtuAfterRecordingLogIsTruncatedToTheLatestSnapshot.
@SuppressWarnings("MethodLength")
@Test
@InterruptAfter(30)
public void shouldAllowChangingTermBufferLengthAndMtuAfterRecordingLogIsTruncatedToTheLatestSnapshot() {
final int originalTermLength = 256 * 1024;
final int originalMtu = 1408;
final int newTermLength = 2 * 1024 * 1024;
final int newMtu = 8992;
final CRC32 crc32 = new CRC32();
cluster = aCluster().withStaticNodes(3).withLogChannel("aeron:udp?term-length=" + originalTermLength + "|mtu=" + originalMtu).withIngressChannel("aeron:udp?term-length=" + originalTermLength + "|mtu=" + originalMtu).withEgressChannel("aeron:udp?endpoint=localhost:0|term-length=" + originalTermLength + "|mtu=" + originalMtu).withServiceSupplier((i) -> new TestNode.TestService[] { new TestNode.TestService(), new TestNode.ChecksumService() }).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
for (int i = 0; i < 3; i++) {
assertEquals(2, cluster.node(i).services().length);
}
cluster.connectClient();
final int firstBatch = 9;
int messageLength = computeMaxMessageLength(originalTermLength) - AeronCluster.SESSION_HEADER_LENGTH;
int payloadLength = messageLength - SIZE_OF_INT;
cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'x');
crc32.reset();
crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
int msgChecksum = (int) crc32.getValue();
cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
long checksum = 0;
for (int i = 0; i < firstBatch; i++) {
cluster.pollUntilMessageSent(messageLength);
checksum = Hashing.hash(checksum ^ msgChecksum);
}
cluster.awaitResponseMessageCount(firstBatch);
cluster.takeSnapshot(leader);
cluster.awaitSnapshotCount(1);
cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'y');
crc32.reset();
crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
msgChecksum = (int) crc32.getValue();
cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
final int secondBatch = 11;
for (int i = 0; i < secondBatch; i++) {
cluster.pollUntilMessageSent(messageLength);
}
cluster.awaitResponseMessageCount(firstBatch + secondBatch);
cluster.stopAllNodes();
// seed all recording logs from the latest snapshot
for (int i = 0; i < 3; i++) {
ClusterTool.seedRecordingLogFromSnapshot(cluster.node(i).consensusModule().context().clusterDir());
}
cluster.logChannel("aeron:udp?term-length=" + newTermLength + "|mtu=" + newMtu);
cluster.ingressChannel("aeron:udp?term-length=" + newTermLength + "|mtu=" + newMtu);
cluster.egressChannel("aeron:udp?endpoint=localhost:0|term-length=" + newTermLength + "|mtu=" + newMtu);
cluster.restartAllNodes(false);
cluster.awaitLeader();
assertEquals(2, cluster.followers().size());
for (int i = 0; i < 3; i++) {
assertEquals(2, cluster.node(i).services().length);
}
cluster.awaitSnapshotsLoaded();
cluster.reconnectClient();
messageLength = computeMaxMessageLength(newTermLength) - AeronCluster.SESSION_HEADER_LENGTH;
payloadLength = messageLength - SIZE_OF_INT;
cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'z');
crc32.reset();
crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
msgChecksum = (int) crc32.getValue();
cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
final int thirdBatch = 5;
for (int i = 0; i < thirdBatch; i++) {
cluster.pollUntilMessageSent(messageLength);
checksum = Hashing.hash(checksum ^ msgChecksum);
}
cluster.awaitResponseMessageCount(firstBatch + secondBatch + thirdBatch);
final int finalMessageCount = firstBatch + thirdBatch;
final long finalChecksum = checksum;
final Predicate<TestNode> finalServiceState = node -> {
final TestNode.TestService[] services = node.services();
return finalMessageCount == services[0].messageCount() && finalChecksum == ((TestNode.ChecksumService) services[1]).checksum();
};
for (int i = 0; i < 3; i++) {
final TestNode node = cluster.node(i);
cluster.awaitServiceState(node, finalServiceState);
}
}
Aggregations