use of io.aeron.cluster.service.Cluster.Role.LEADER 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