Search in sources :

Example 21 with AeronArchive

use of io.aeron.archive.client.AeronArchive in project aeron by real-logic.

the class ClusterTest method shouldEnterElectionWhenRecordingStopsOnLeader.

@Test
@InterruptAfter(30)
public void shouldEnterElectionWhenRecordingStopsOnLeader() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    cluster.connectClient();
    final AeronArchive.Context archiveCtx = new AeronArchive.Context().controlRequestChannel(leader.archive().context().localControlChannel()).controlResponseChannel(leader.archive().context().localControlChannel()).controlRequestStreamId(leader.archive().context().localControlStreamId()).aeronDirectoryName(leader.mediaDriver().aeronDirectoryName());
    try (AeronArchive archive = AeronArchive.connect(archiveCtx)) {
        final int firstRecordingIdIsTheClusterLog = 0;
        assertTrue(archive.tryStopRecordingByIdentity(firstRecordingIdIsTheClusterLog));
    }
    cluster.awaitNewLeadershipEvent(1);
    cluster.followers(2);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) AeronArchive(io.aeron.archive.client.AeronArchive) Test(org.junit.jupiter.api.Test)

Example 22 with AeronArchive

use of io.aeron.archive.client.AeronArchive in project aeron by real-logic.

the class ClusterTest method shouldRecoverFollowerWhenRecordingStops.

@Test
@InterruptAfter(30)
public void shouldRecoverFollowerWhenRecordingStops() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    cluster.awaitLeader();
    final TestNode follower = cluster.followers().get(0);
    final AeronArchive.Context archiveCtx = new AeronArchive.Context().controlRequestChannel(follower.archive().context().localControlChannel()).controlResponseChannel(follower.archive().context().localControlChannel()).controlRequestStreamId(follower.archive().context().localControlStreamId()).aeronDirectoryName(follower.mediaDriver().aeronDirectoryName());
    try (AeronArchive archive = AeronArchive.connect(archiveCtx)) {
        final int firstRecordingIdIsTheClusterLog = 0;
        assertTrue(archive.tryStopRecordingByIdentity(firstRecordingIdIsTheClusterLog));
    }
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServiceMessageCount(follower, messageCount);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) AeronArchive(io.aeron.archive.client.AeronArchive) Test(org.junit.jupiter.api.Test)

Example 23 with AeronArchive

use of io.aeron.archive.client.AeronArchive in project aeron by real-logic.

the class ExtendRecordingTest method before.

@BeforeEach
void before() {
    final String aeronDirectoryName = CommonContext.generateRandomDirName();
    if (null == archiveDir) {
        archiveDir = new File(SystemUtil.tmpDirName(), "archive");
    }
    final MediaDriver.Context driverCtx = new MediaDriver.Context().aeronDirectoryName(aeronDirectoryName).termBufferSparseFile(true).threadingMode(ThreadingMode.SHARED).spiesSimulateConnection(false).dirDeleteOnStart(true);
    final Archive.Context archiveCtx = new Archive.Context().catalogCapacity(ArchiveSystemTests.CATALOG_CAPACITY).aeronDirectoryName(aeronDirectoryName).archiveDir(archiveDir).fileSyncLevel(0).threadingMode(ArchiveThreadingMode.SHARED);
    try {
        driver = TestMediaDriver.launch(driverCtx, systemTestWatcher);
        archive = Archive.launch(archiveCtx);
    } finally {
        systemTestWatcher.dataCollector().add(driverCtx.aeronDirectory());
        systemTestWatcher.dataCollector().add(archiveCtx.archiveDir());
    }
    aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(aeronDirectoryName));
    aeronArchive = AeronArchive.connect(new AeronArchive.Context().recordingSignalConsumer(mockRecordingSignalConsumer).aeron(aeron));
}
Also used : AeronArchive(io.aeron.archive.client.AeronArchive) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MediaDriver(io.aeron.driver.MediaDriver) File(java.io.File) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 24 with AeronArchive

use of io.aeron.archive.client.AeronArchive in project aeron by real-logic.

the class ClusteredServiceAgent method loadSnapshot.

private void loadSnapshot(final long recordingId) {
    try (AeronArchive archive = AeronArchive.connect(ctx.archiveContext().clone())) {
        final String channel = ctx.replayChannel();
        final int streamId = ctx.replayStreamId();
        final int sessionId = (int) archive.startReplay(recordingId, 0, NULL_VALUE, channel, streamId);
        final String replaySessionChannel = ChannelUri.addSessionId(channel, sessionId);
        try (Subscription subscription = aeron.addSubscription(replaySessionChannel, streamId)) {
            final Image image = awaitImage(sessionId, subscription);
            loadState(image, archive);
            service.onStart(this, image);
        }
    }
}
Also used : AeronArchive(io.aeron.archive.client.AeronArchive)

Example 25 with AeronArchive

use of io.aeron.archive.client.AeronArchive 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)

Aggregations

AeronArchive (io.aeron.archive.client.AeronArchive)54 Test (org.junit.jupiter.api.Test)28 MediaDriver (io.aeron.driver.MediaDriver)26 File (java.io.File)17 Aeron (io.aeron.Aeron)14 CommonContext (io.aeron.CommonContext)12 Context (io.aeron.archive.Archive.Context)12 InterruptAfter (io.aeron.test.InterruptAfter)12 Tests (io.aeron.test.Tests)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Archive (io.aeron.archive.Archive)10 ArchiveException (io.aeron.archive.client.ArchiveException)10 CountersReader (org.agrona.concurrent.status.CountersReader)10 Publication (io.aeron.Publication)8 FileStore (java.nio.file.FileStore)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)8 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)8 ChannelUriStringBuilder (io.aeron.ChannelUriStringBuilder)7 DEDICATED (io.aeron.archive.ArchiveThreadingMode.DEDICATED)6