Search in sources :

Example 1 with ChannelUriStringBuilder

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();
    }
}
Also used : Context(io.aeron.archive.Archive.Context) CommonContext(io.aeron.CommonContext) RecordingSubscriptionDescriptorConsumer(io.aeron.archive.client.RecordingSubscriptionDescriptorConsumer) IntConsumer(java.util.function.IntConsumer) LOCAL(io.aeron.archive.codecs.SourceLocation.LOCAL) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ChannelUriStringBuilder(io.aeron.ChannelUriStringBuilder) AeronArchive(io.aeron.archive.client.AeronArchive) DEDICATED(io.aeron.archive.ArchiveThreadingMode.DEDICATED) Publication(io.aeron.Publication) MediaDriver(io.aeron.driver.MediaDriver) ManyToOneConcurrentLinkedQueue(org.agrona.concurrent.ManyToOneConcurrentLinkedQueue) AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) CountDownLatch(java.util.concurrent.CountDownLatch) TruncateRecordingRequestDecoder(io.aeron.archive.codecs.TruncateRecordingRequestDecoder) EXCLUDE(org.junit.jupiter.params.provider.EnumSource.Mode.EXCLUDE) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) DirectBuffer(org.agrona.DirectBuffer) Mockito.mock(org.mockito.Mockito.mock) Tests(io.aeron.test.Tests) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CountersReader(org.agrona.concurrent.status.CountersReader) EnumSource(org.junit.jupiter.params.provider.EnumSource) ArrayList(java.util.ArrayList) SystemEpochClock(org.agrona.concurrent.SystemEpochClock) Context(io.aeron.archive.Archive.Context) FrameDescriptor(io.aeron.logbuffer.FrameDescriptor) ValueSource(org.junit.jupiter.params.provider.ValueSource) RecordingPos(io.aeron.archive.status.RecordingPos) Aeron(io.aeron.Aeron) FileStore(java.nio.file.FileStore) SHARED(io.aeron.archive.ArchiveThreadingMode.SHARED) AeronArchive.segmentFileBasePosition(io.aeron.archive.client.AeronArchive.segmentFileBasePosition) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) CommonContext(io.aeron.CommonContext) Checksum(io.aeron.archive.checksum.Checksum) LogBufferDescriptor(io.aeron.logbuffer.LogBufferDescriptor) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MIN_CAPACITY(io.aeron.archive.Catalog.MIN_CAPACITY) ArchiveException(io.aeron.archive.client.ArchiveException) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions(org.junit.jupiter.api.Assertions) AeronArchive(io.aeron.archive.client.AeronArchive) ChannelUriStringBuilder(io.aeron.ChannelUriStringBuilder) Publication(io.aeron.Publication) AeronArchive(io.aeron.archive.client.AeronArchive) Aeron(io.aeron.Aeron) CountersReader(org.agrona.concurrent.status.CountersReader) DirectBuffer(org.agrona.DirectBuffer) MediaDriver(io.aeron.driver.MediaDriver) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Context(io.aeron.archive.Archive.Context) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ChannelUriStringBuilder

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));
}
Also used : ChannelUriStringBuilder(io.aeron.ChannelUriStringBuilder) UdpChannel(io.aeron.driver.media.UdpChannel) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ChannelUriStringBuilder

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);
    }
}
Also used : ChannelUriStringBuilder(io.aeron.ChannelUriStringBuilder) Publication(io.aeron.Publication) CountersReader(org.agrona.concurrent.status.CountersReader)

Example 4 with ChannelUriStringBuilder

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);
}
Also used : ChannelUriStringBuilder(io.aeron.ChannelUriStringBuilder) AeronCluster(io.aeron.cluster.client.AeronCluster) RecordingLog(io.aeron.cluster.client.RecordingLog) AeronArchive(io.aeron.archive.client.AeronArchive)

Example 5 with ChannelUriStringBuilder

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);
    }
}
Also used : ChannelUriStringBuilder(io.aeron.ChannelUriStringBuilder) Publication(io.aeron.Publication) CountersReader(org.agrona.concurrent.status.CountersReader)

Aggregations

ChannelUriStringBuilder (io.aeron.ChannelUriStringBuilder)7 Publication (io.aeron.Publication)4 CountersReader (org.agrona.concurrent.status.CountersReader)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 AeronArchive (io.aeron.archive.client.AeronArchive)3 Aeron (io.aeron.Aeron)2 CommonContext (io.aeron.CommonContext)2 Context (io.aeron.archive.Archive.Context)2 DEDICATED (io.aeron.archive.ArchiveThreadingMode.DEDICATED)2 SHARED (io.aeron.archive.ArchiveThreadingMode.SHARED)2 MIN_CAPACITY (io.aeron.archive.Catalog.MIN_CAPACITY)2 Checksum (io.aeron.archive.checksum.Checksum)2 AeronArchive.segmentFileBasePosition (io.aeron.archive.client.AeronArchive.segmentFileBasePosition)2 ArchiveException (io.aeron.archive.client.ArchiveException)2 RecordingSubscriptionDescriptorConsumer (io.aeron.archive.client.RecordingSubscriptionDescriptorConsumer)2 LOCAL (io.aeron.archive.codecs.SourceLocation.LOCAL)2 TruncateRecordingRequestDecoder (io.aeron.archive.codecs.TruncateRecordingRequestDecoder)2 RecordingPos (io.aeron.archive.status.RecordingPos)2 MediaDriver (io.aeron.driver.MediaDriver)2 ThreadingMode (io.aeron.driver.ThreadingMode)2