use of io.aeron.ChannelUriStringBuilder in project Aeron by real-logic.
the class ArchiveTest method shouldRecoverRecordingWithNonZeroStartPosition.
@Test
public void shouldRecoverRecordingWithNonZeroStartPosition() {
final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
final Archive.Context archiveCtx = new Archive.Context().threadingMode(SHARED);
long resultingPosition;
final int initialPosition = DataHeaderFlyweight.HEADER_LENGTH * 9;
final long recordingId;
try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx.clone(), archiveCtx.clone());
AeronArchive archive = AeronArchive.connect()) {
final int termLength = 128 * 1024;
final int initialTermId = 29;
final String channel = new ChannelUriStringBuilder().media(CommonContext.IPC_MEDIA).initialPosition(initialPosition, initialTermId, termLength).build();
final Publication publication = archive.addRecordedExclusivePublication(channel, 1);
final DirectBuffer buffer = new UnsafeBuffer("Hello World".getBytes(StandardCharsets.US_ASCII));
while ((resultingPosition = publication.offer(buffer)) <= 0) {
Tests.yield();
}
final Aeron aeron = archive.context().aeron();
int counterId;
final int sessionId = publication.sessionId();
final CountersReader countersReader = aeron.countersReader();
while (Aeron.NULL_VALUE == (counterId = RecordingPos.findCounterIdBySession(countersReader, sessionId))) {
Tests.yield();
}
recordingId = RecordingPos.getRecordingId(countersReader, counterId);
while (countersReader.getCounterValue(counterId) < resultingPosition) {
Tests.yield();
}
}
try (Catalog catalog = openCatalog(archiveCtx)) {
final Catalog.CatalogEntryProcessor catalogEntryProcessor = (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> descriptorEncoder.stopPosition(Aeron.NULL_VALUE);
assertTrue(catalog.forEntry(recordingId, catalogEntryProcessor));
}
final Archive.Context archiveCtxClone = archiveCtx.clone();
final MediaDriver.Context driverCtxClone = driverCtx.clone();
try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtxClone, archiveCtxClone);
AeronArchive archive = AeronArchive.connect()) {
assertEquals(initialPosition, archive.getStartPosition(recordingId));
assertEquals(resultingPosition, archive.getStopPosition(recordingId));
} finally {
archiveCtxClone.deleteDirectory();
driverCtxClone.deleteDirectory();
}
}
use of io.aeron.ChannelUriStringBuilder in project Aeron by real-logic.
the class UdpChannelTest method shouldParseWithNameResolver.
@ParameterizedTest
@CsvSource({ "NAME_ENDPOINT,192.168.1.1,,,UDP-127.0.0.1:0-NAME_ENDPOINT", "localhost:41024,127.0.0.1,,,UDP-127.0.0.1:0-localhost:41024", "[fe80::5246:5dff:fe73:df06]:40456,[fe80::5246:5dff:fe73:df06],,," + "UDP-127.0.0.1:0-[fe80::5246:5dff:fe73:df06]:40456", "NAME_ENDPOINT,224.0.1.1,,,UDP-127.0.0.1:0-224.0.1.1:40124", "NAME_ENDPOINT,192.168.1.1,NAME_CONTROL,192.168.1.2,UDP-NAME_CONTROL-NAME_ENDPOINT", "NAME_ENDPOINT,224.0.1.1,NAME_CONTROL,127.0.0.1,UDP-127.0.0.1:0-224.0.1.1:40124", "192.168.1.1:40124,192.168.1.1,NAME_CONTROL,192.168.1.2,UDP-NAME_CONTROL-192.168.1.1:40124", "192.168.1.1:40124,192.168.1.1,192.168.1.2:40192,192.168.1.2,UDP-192.168.1.2:40192-192.168.1.1:40124" })
void shouldParseWithNameResolver(final String endpointName, final String endpointAddress, final String controlName, final String controlAddress, final String canonicalForm) {
final int port = 40124;
final NameResolver resolver = new NameResolver() {
public InetAddress resolve(final String name, final String uriParamName, final boolean isReResolution) {
return DefaultNameResolver.INSTANCE.resolve(name, uriParamName, isReResolution);
}
public String lookup(final String name, final String uriParamName, final boolean isReLookup) {
if (endpointName.equals(name)) {
return endpointAddress + ":" + port;
} else if (controlName.equals(name)) {
return controlAddress + ":" + port;
}
return name;
}
};
final ChannelUriStringBuilder uriBuilder = new ChannelUriStringBuilder().media("udp").networkInterface("localhost");
if (!Strings.isEmpty(endpointName)) {
uriBuilder.endpoint(endpointName);
}
if (!Strings.isEmpty(controlName)) {
uriBuilder.controlEndpoint(controlName);
}
final UdpChannel udpChannel = UdpChannel.parse(uriBuilder.build(), resolver);
assertThat(udpChannel.canonicalForm(), is(canonicalForm));
}
use of io.aeron.ChannelUriStringBuilder in project aeron by real-logic.
the class ArchiveCreator method createRecording.
private static void createRecording(final Aeron aeron, final AeronArchive aeronArchive, final long startPosition, final long targetPosition) {
final int initialTermId = 7;
recordingNumber++;
final ChannelUriStringBuilder uriBuilder = new ChannelUriStringBuilder().media("udp").endpoint("localhost:" + recordingNumber).termLength(TERM_LENGTH);
if (startPosition > 0) {
uriBuilder.initialPosition(startPosition, initialTermId, TERM_LENGTH);
}
try (Publication publication = aeronArchive.addRecordedExclusivePublication(uriBuilder.build(), STREAM_ID)) {
final CountersReader counters = aeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
final long recordingId = RecordingPos.getRecordingId(counters, counterId);
System.out.println("recordingId=" + recordingId + " position " + publication.position() + " to " + targetPosition);
offerToPosition(publication, targetPosition);
awaitPosition(counters, counterId, publication.position());
aeronArchive.stopRecording(publication);
}
}
use of io.aeron.ChannelUriStringBuilder in project aeron by real-logic.
the class RecordingCatchUp method catchUp.
public static RecordingCatchUp catchUp(final AeronArchive.Context localArchiveContext, final RecordingLog.RecoveryPlan localRecoveryPlan, final ClusterMember leader, final CountersReader localCounters, final String replayChannel, final int replayStreamId) {
final AeronCluster.Context leaderContext = new AeronCluster.Context().clusterMemberEndpoints(leader.clientFacingEndpoint());
final RecordingLog.RecoveryPlan leaderRecoveryPlan;
try (AeronCluster aeronCluster = AeronCluster.connect(leaderContext)) {
leaderRecoveryPlan = new RecordingLog.RecoveryPlan(aeronCluster.getRecoveryPlan());
}
if (leaderRecoveryPlan.lastLeadershipTermId != localRecoveryPlan.lastLeadershipTermId) {
throw new IllegalStateException("lastLeadershipTermIds are not equal, can not catch up: leader=" + leaderRecoveryPlan.lastLeadershipTermId + " local=" + localRecoveryPlan.lastLeadershipTermId);
}
final RecordingLog.ReplayStep localLastStep = localRecoveryPlan.termSteps.get(localRecoveryPlan.termSteps.size() - 1);
final RecordingLog.ReplayStep leaderLastStep = leaderRecoveryPlan.termSteps.get(leaderRecoveryPlan.termSteps.size() - 1);
if (localLastStep.entry.leadershipTermId != leaderLastStep.entry.leadershipTermId) {
throw new IllegalStateException("last step leadershipTermIds are not equal, can not catch up: leader=" + leaderLastStep.entry.leadershipTermId + " local=" + localLastStep.entry.leadershipTermId);
}
if (localLastStep.recordingStartPosition != leaderLastStep.recordingStartPosition) {
throw new IllegalStateException("last step local start position does not match leader last step start position");
}
final long leaderRecordingId = leaderLastStep.entry.recordingId;
final long localRecordingId = localLastStep.entry.recordingId;
// TODO: probably needs to be queried
final long extendStartPosition = localLastStep.recordingStopPosition;
final long extendStopPosition = leaderLastStep.recordingStopPosition;
final ChannelUriStringBuilder archiveControlRequestChannel = new ChannelUriStringBuilder().media(CommonContext.UDP_MEDIA).endpoint(leader.archiveEndpoint());
final AeronArchive.Context leaderArchiveContext = new AeronArchive.Context().controlRequestChannel(archiveControlRequestChannel.build());
final AeronArchive localArchive = AeronArchive.connect(localArchiveContext.clone());
final AeronArchive leaderArchive = AeronArchive.connect(leaderArchiveContext);
return new RecordingCatchUp(localArchive, localCounters, localRecordingId, leaderArchive, leaderRecordingId, extendStartPosition, extendStopPosition, replayChannel, replayStreamId);
}
use of io.aeron.ChannelUriStringBuilder in project Aeron by real-logic.
the class ArchiveCreator method createRecording.
private static void createRecording(final Aeron aeron, final AeronArchive aeronArchive, final long startPosition, final long targetPosition) {
final int initialTermId = 7;
recordingNumber++;
final ChannelUriStringBuilder uriBuilder = new ChannelUriStringBuilder().media("udp").endpoint("localhost:" + recordingNumber).termLength(TERM_LENGTH);
if (startPosition > 0) {
uriBuilder.initialPosition(startPosition, initialTermId, TERM_LENGTH);
}
try (Publication publication = aeronArchive.addRecordedExclusivePublication(uriBuilder.build(), STREAM_ID)) {
final CountersReader counters = aeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
final long recordingId = RecordingPos.getRecordingId(counters, counterId);
System.out.println("recordingId=" + recordingId + " position " + publication.position() + " to " + targetPosition);
offerToPosition(publication, targetPosition);
awaitPosition(counters, counterId, publication.position());
aeronArchive.stopRecording(publication);
}
}
Aggregations