io.aeron.archive.client.AeronArchive Java Examples

The following examples show how to use io.aeron.archive.client.AeronArchive. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmbeddedReplayThroughput.java    From aeron with Apache License 2.0 6 votes vote down vote up
public EmbeddedReplayThroughput()
{
    final String archiveDirName = Archive.Configuration.archiveDirName();
    final File archiveDir = ARCHIVE_DIR_DEFAULT.equals(archiveDirName) ?
        Samples.createTempDir() : new File(archiveDirName);

    archivingMediaDriver = ArchivingMediaDriver.launch(
        new MediaDriver.Context()
            .dirDeleteOnStart(true),
        new Archive.Context()
            .archiveDir(archiveDir)
            .recordingEventsEnabled(false));

    aeron = Aeron.connect();

    aeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .aeron(aeron));
}
 
Example #2
Source File: SequenceNumberIndexTest.java    From artio with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp()
{
    mediaDriver = launchMediaDriver();
    aeronArchive = AeronArchive.connect();
    final Aeron aeron = aeronArchive.context().aeron();

    aeronArchive.startRecording(IPC_CHANNEL, STREAM_ID, SourceLocation.LOCAL);

    publication = aeron.addPublication(IPC_CHANNEL, STREAM_ID);
    subscription = aeron.addSubscription(IPC_CHANNEL, STREAM_ID);

    buffer = new UnsafeBuffer(new byte[512]);

    deleteFiles();

    recordingIdLookup = new RecordingIdLookup(new YieldingIdleStrategy(), aeron.countersReader());
    writer = newWriter(inMemoryBuffer);
    reader = new SequenceNumberIndexReader(inMemoryBuffer, errorHandler, recordingIdLookup, null);
}
 
Example #3
Source File: ClusteredServiceAgent.java    From aeron with Apache License 2.0 6 votes vote down vote up
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);
            service.onStart(this, image);
        }
    }
}
 
Example #4
Source File: ControlResponseProxy.java    From aeron with Apache License 2.0 6 votes vote down vote up
boolean sendResponse(
    final long controlSessionId,
    final long correlationId,
    final long relevantId,
    final ControlResponseCode code,
    final String errorMessage,
    final ControlSession session)
{
    responseEncoder
        .wrapAndApplyHeader(buffer, 0, messageHeaderEncoder)
        .controlSessionId(controlSessionId)
        .correlationId(correlationId)
        .relevantId(relevantId)
        .code(code)
        .version(AeronArchive.Configuration.PROTOCOL_SEMANTIC_VERSION)
        .errorMessage(errorMessage);

    return sendResponseHook(session, buffer, MESSAGE_HEADER_LENGTH + responseEncoder.encodedLength());
}
 
Example #5
Source File: ClusteredServiceAgent.java    From aeron with Apache License 2.0 6 votes vote down vote up
private long onTakeSnapshot(final long logPosition, final long leadershipTermId)
{
    final long recordingId;

    try (AeronArchive archive = AeronArchive.connect(ctx.archiveContext().clone());
        ExclusivePublication publication = aeron.addExclusivePublication(
            ctx.snapshotChannel(), ctx.snapshotStreamId()))
    {
        final String channel = ChannelUri.addSessionId(ctx.snapshotChannel(), publication.sessionId());
        archive.startRecording(channel, ctx.snapshotStreamId(), LOCAL, true);
        final CountersReader counters = aeron.countersReader();
        final int counterId = awaitRecordingCounter(publication.sessionId(), counters);
        recordingId = RecordingPos.getRecordingId(counters, counterId);

        snapshotState(publication, logPosition, leadershipTermId);
        checkForClockTick();
        service.onTakeSnapshot(publication);

        awaitRecordingComplete(recordingId, publication.position(), counters, counterId, archive);
    }

    return recordingId;
}
 
Example #6
Source File: ReplayOperation.java    From artio with Apache License 2.0 6 votes vote down vote up
ReplayOperation(
    final List<RecordingRange> ranges,
    final AeronArchive aeronArchive,
    final ErrorHandler errorHandler,
    final Subscription subscription,
    final int archiveReplayStream,
    final LogTag logTag,
    final MessageTracker messageTracker)
{
    this.messageTracker = messageTracker;
    assembler = new ControlledFragmentAssembler(this.messageTracker);

    this.ranges = ranges;
    this.aeronArchive = aeronArchive;
    this.errorHandler = errorHandler;
    this.archiveReplayStream = archiveReplayStream;
    this.logTag = logTag;

    final Aeron aeron = aeronArchive.context().aeron();
    countersReader = aeron.countersReader();
    this.subscription = subscription;
}
 
Example #7
Source File: ReplayQuery.java    From artio with Apache License 2.0 6 votes vote down vote up
public ReplayQuery(
    final String logFileDir,
    final int cacheNumSets,
    final int cacheSetSize,
    final ExistingBufferFactory indexBufferFactory,
    final int requiredStreamId,
    final IdleStrategy idleStrategy,
    final AeronArchive aeronArchive,
    final ErrorHandler errorHandler,
    final int archiveReplayStream)
{
    this.logFileDir = logFileDir;
    this.indexBufferFactory = indexBufferFactory;
    this.requiredStreamId = requiredStreamId;
    this.idleStrategy = idleStrategy;
    this.aeronArchive = aeronArchive;
    this.errorHandler = errorHandler;
    this.archiveReplayStream = archiveReplayStream;

    logFileDirFile = new File(logFileDir);
    fixSessionToIndex = new Long2ObjectCache<>(cacheNumSets, cacheSetSize, SessionQuery::close);
}
 
Example #8
Source File: ClusteredServiceAgent.java    From aeron with Apache License 2.0 6 votes vote down vote up
private void awaitRecordingComplete(
    final long recordingId,
    final long position,
    final CountersReader counters,
    final int counterId,
    final AeronArchive archive)
{
    idleStrategy.reset();
    do
    {
        idle();

        if (!RecordingPos.isActive(counters, counterId, recordingId))
        {
            throw new ClusterException("recording has stopped unexpectedly: " + recordingId);
        }

        archive.checkForErrorResponse();
    }
    while (counters.getCounterValue(counterId) < position);
}
 
Example #9
Source File: Indexer.java    From artio with Apache License 2.0 6 votes vote down vote up
public Indexer(
    final List<Index> indices,
    final Subscription subscription,
    final String agentNamePrefix,
    final CompletionPosition completionPosition,
    final AeronArchive aeronArchive,
    final ErrorHandler errorHandler,
    final int archiveReplayStream,
    final boolean gracefulShutdown)
{
    this.indices = indices;
    this.subscription = subscription;
    this.agentNamePrefix = agentNamePrefix;
    this.completionPosition = completionPosition;
    this.archiveReplayStream = archiveReplayStream;
    this.gracefulShutdown = gracefulShutdown;
    catchIndexUp(aeronArchive, errorHandler);
}
 
Example #10
Source File: LogReplay.java    From aeron with Apache License 2.0 6 votes vote down vote up
LogReplay(
    final AeronArchive archive,
    final long recordingId,
    final long startPosition,
    final long stopPosition,
    final long leadershipTermId,
    final int logSessionId,
    final LogAdapter logAdapter,
    final ConsensusModule.Context ctx)
{
    this.archive = archive;
    this.recordingId = recordingId;
    this.startPosition = startPosition;
    this.stopPosition = stopPosition;
    this.leadershipTermId = leadershipTermId;
    this.logSessionId = logSessionId;
    this.logAdapter = logAdapter;
    this.consensusModuleAgent = logAdapter.consensusModuleAgent();
    this.ctx = ctx;
    this.replayStreamId = ctx.replayStreamId();

    final ChannelUri channelUri = ChannelUri.parse(ctx.replayChannel());
    channelUri.put(CommonContext.SESSION_ID_PARAM_NAME, Integer.toString(logSessionId));
    logSubscription = ctx.aeron().addSubscription(channelUri.toString(), replayStreamId);
}
 
Example #11
Source File: RecordingLogTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIgnoreIncompleteSnapshotInRecoveryPlan()
{
    final int serviceCount = 1;

    try (RecordingLog recordingLog = new RecordingLog(TEMP_DIR))
    {
        recordingLog.appendSnapshot(1L, 1L, 0, 777L, 0, 0);
        recordingLog.appendSnapshot(2L, 1L, 0, 777L, 0, SERVICE_ID);
        recordingLog.appendSnapshot(3L, 1L, 0, 777L, 0, 0);
    }

    try (RecordingLog recordingLog = new RecordingLog(TEMP_DIR))
    {
        assertEquals(3, recordingLog.entries().size());

        final AeronArchive mockArchive = mock(AeronArchive.class);
        final RecordingLog.RecoveryPlan recoveryPlan = recordingLog.createRecoveryPlan(mockArchive, serviceCount);
        assertEquals(2, recoveryPlan.snapshots.size());
        assertEquals(SERVICE_ID, recoveryPlan.snapshots.get(0).serviceId);
        assertEquals(2L, recoveryPlan.snapshots.get(0).recordingId);
        assertEquals(0, recoveryPlan.snapshots.get(1).serviceId);
        assertEquals(1L, recoveryPlan.snapshots.get(1).recordingId);
    }
}
 
Example #12
Source File: PruneOperation.java    From artio with Apache License 2.0 6 votes vote down vote up
public PruneOperation(
    final Formatters formatters,
    final Long2LongHashMap minimumPrunePositions,
    final ReplayQuery outboundReplayQuery,
    final ReplayQuery inboundReplayQuery,
    final AeronArchive aeronArchive,
    final ReplayerCommandQueue replayerCommandQueue,
    final RecordingCoordinator recordingCoordinator)
{
    this.formatters = formatters;
    this.outboundReplayQuery = outboundReplayQuery;
    this.inboundReplayQuery = inboundReplayQuery;
    this.minimumPrunePositions = minimumPrunePositions;
    this.aeronArchive = aeronArchive;
    this.replayerCommandQueue = replayerCommandQueue;
    this.recordingCoordinator = recordingCoordinator;
    replyState = State.EXECUTING;
}
 
Example #13
Source File: EmbeddedRecordingThroughput.java    From aeron with Apache License 2.0 6 votes vote down vote up
public EmbeddedRecordingThroughput()
{
    final String archiveDirName = Archive.Configuration.archiveDirName();
    final File archiveDir = ARCHIVE_DIR_DEFAULT.equals(archiveDirName) ?
        Samples.createTempDir() : new File(archiveDirName);

    archivingMediaDriver = ArchivingMediaDriver.launch(
        new MediaDriver.Context()
            .spiesSimulateConnection(true)
            .dirDeleteOnStart(true),
        new Archive.Context()
            .recordingEventsEnabled(false)
            .archiveDir(archiveDir));

    aeron = Aeron.connect();

    aeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .aeron(aeron));
}
 
Example #14
Source File: RecordingLogTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIgnoreInvalidLastSnapshotInRecoveryPlan()
{
    final int serviceCount = 1;

    try (RecordingLog recordingLog = new RecordingLog(TEMP_DIR))
    {
        recordingLog.appendSnapshot(1L, 1L, 0, 777L, 0, 0);
        recordingLog.appendSnapshot(2L, 1L, 0, 777L, 0, SERVICE_ID);
        recordingLog.appendSnapshot(3L, 1L, 0, 888L, 0, 0);
        recordingLog.appendSnapshot(4L, 1L, 0, 888L, 0, SERVICE_ID);

        recordingLog.invalidateLatestSnapshot();
    }

    try (RecordingLog recordingLog = new RecordingLog(TEMP_DIR))
    {
        final AeronArchive mockArchive = mock(AeronArchive.class);
        final RecordingLog.RecoveryPlan recoveryPlan = recordingLog.createRecoveryPlan(mockArchive, serviceCount);
        assertEquals(2, recoveryPlan.snapshots.size());
        assertEquals(SERVICE_ID, recoveryPlan.snapshots.get(0).serviceId);
        assertEquals(2L, recoveryPlan.snapshots.get(0).recordingId);
        assertEquals(0, recoveryPlan.snapshots.get(1).serviceId);
        assertEquals(1L, recoveryPlan.snapshots.get(1).recordingId);
    }
}
 
Example #15
Source File: Backup.java    From artio with Apache License 2.0 6 votes vote down vote up
public void assertRecordingsTruncated()
{
    try (AeronArchive archive = AeronArchive.connect())
    {
        archive.listRecording(0,
            (controlSessionId,
            correlationId,
            recordingId,
            startTimestamp,
            stopTimestamp,
            startPosition,
            stopPosition,
            initialTermId,
            segmentFileLength,
            termBufferLength,
            mtuLength,
            sessionId,
            streamId,
            strippedChannel,
            originalChannel,
            sourceIdentity) ->
            {
                assertEquals(0, stopPosition);
            });
    }
}
 
Example #16
Source File: ManageRecordingHistoryTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@Test
@Timeout(10)
public void shouldPurgeForLateJoinedStream()
{
    final String messagePrefix = "Message-Prefix-";
    final int initialTermId = 7;
    final long targetPosition = (SEGMENT_LENGTH * 3L) + 1;
    final long startPosition = (TERM_LENGTH * 2L) + (FRAME_ALIGNMENT * 2L);
    uriBuilder.initialPosition(startPosition, initialTermId, TERM_LENGTH);

    try (Publication publication = aeronArchive.addRecordedExclusivePublication(uriBuilder.build(), STREAM_ID))
    {
        assertEquals(startPosition, publication.position());

        final CountersReader counters = aeron.countersReader();
        final int counterId = Common.awaitRecordingCounterId(counters, publication.sessionId());
        final long recordingId = RecordingPos.getRecordingId(counters, counterId);

        offerToPosition(publication, messagePrefix, targetPosition);
        awaitPosition(counters, counterId, publication.position());

        final long segmentFileBasePosition = AeronArchive.segmentFileBasePosition(
            startPosition, startPosition + (SEGMENT_LENGTH * 2L), TERM_LENGTH, SEGMENT_LENGTH);

        final long purgeSegments = aeronArchive.purgeSegments(recordingId, segmentFileBasePosition);
        assertEquals(2L, purgeSegments);
        assertEquals(segmentFileBasePosition, aeronArchive.getStartPosition(recordingId));

        aeronArchive.stopRecording(publication);
    }
}
 
Example #17
Source File: ArchiveNode.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
ArchiveNode(
    final AtomicBoolean running,
    final ArchivingMediaDriver archivingMediaDriver,
    final AeronArchive aeronArchive,
    final boolean ownsArchiveClient)
{
    this.running = running;
    this.archivingMediaDriver = archivingMediaDriver;
    this.aeronArchive = aeronArchive;
    this.ownsArchiveClient = ownsArchiveClient;

    final Aeron aeron = aeronArchive.context().aeron();

    subscription = aeron.addSubscription(sendChannel(), sendStreamId());

    final String archiveChannel = archiveChannel();
    final int archiveStreamId = archiveStreamId();
    publication = aeron.addExclusivePublication(archiveChannel, archiveStreamId);

    final int publicationSessionId = publication.sessionId();
    final String channel = addSessionId(archiveChannel, publicationSessionId);
    aeronArchive.startRecording(channel, archiveStreamId, LOCAL, true);

    while (!subscription.isConnected() || !publication.isConnected())
    {
        yieldUninterruptedly();
    }

    awaitRecordingStart(aeron, publicationSessionId);
}
 
Example #18
Source File: ManageRecordingHistoryTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@Test
@Timeout(10)
public void shouldPurgeForStreamJoinedAtTheBeginning()
{
    final String messagePrefix = "Message-Prefix-";
    final long targetPosition = (SEGMENT_LENGTH * 3L) + 1;

    try (Publication publication = aeronArchive.addRecordedPublication(uriBuilder.build(), STREAM_ID))
    {
        final CountersReader counters = aeron.countersReader();
        final int counterId = Common.awaitRecordingCounterId(counters, publication.sessionId());
        final long recordingId = RecordingPos.getRecordingId(counters, counterId);

        offerToPosition(publication, messagePrefix, targetPosition);
        awaitPosition(counters, counterId, publication.position());

        final long startPosition = 0L;
        final long segmentFileBasePosition = AeronArchive.segmentFileBasePosition(
            startPosition, SEGMENT_LENGTH * 2L, TERM_LENGTH, SEGMENT_LENGTH);

        final long count = aeronArchive.purgeSegments(recordingId, segmentFileBasePosition);
        assertEquals(2L, count);
        assertEquals(segmentFileBasePosition, aeronArchive.getStartPosition(recordingId));

        aeronArchive.stopRecording(publication);
    }
}
 
Example #19
Source File: BasicArchiveTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@Test
@Timeout(10)
public void shouldReplayRecordingFromLateJoinPosition()
{
    final String messagePrefix = "Message-Prefix-";
    final int messageCount = 10;

    final long subscriptionId = aeronArchive.startRecording(RECORDED_CHANNEL, RECORDED_STREAM_ID, LOCAL);

    try (Subscription subscription = aeron.addSubscription(RECORDED_CHANNEL, RECORDED_STREAM_ID);
        Publication publication = aeron.addPublication(RECORDED_CHANNEL, RECORDED_STREAM_ID))
    {
        final CountersReader counters = aeron.countersReader();
        final int counterId = Common.awaitRecordingCounterId(counters, publication.sessionId());
        final long recordingId = RecordingPos.getRecordingId(counters, counterId);

        offer(publication, messageCount, messagePrefix);
        consume(subscription, messageCount, messagePrefix);

        final long currentPosition = publication.position();
        awaitPosition(counters, counterId, currentPosition);

        try (Subscription replaySubscription = aeronArchive.replay(
            recordingId, currentPosition, AeronArchive.NULL_LENGTH, REPLAY_CHANNEL, REPLAY_STREAM_ID))
        {
            offer(publication, messageCount, messagePrefix);
            consume(subscription, messageCount, messagePrefix);
            consume(replaySubscription, messageCount, messagePrefix);

            final long endPosition = publication.position();
            assertEquals(endPosition, replaySubscription.imageAtIndex(0).position());
        }
    }

    aeronArchive.stopRecording(subscriptionId);
}
 
Example #20
Source File: ReplayMergeTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void before()
{
    final File archiveDir = new File(SystemUtil.tmpDirName(), "archive");

    mediaDriver = TestMediaDriver.launch(
        mediaDriverContext
            .termBufferSparseFile(true)
            .publicationTermBufferLength(TERM_LENGTH)
            .threadingMode(ThreadingMode.SHARED)
            .errorHandler(Tests::onError)
            .spiesSimulateConnection(false)
            .dirDeleteOnStart(true),
        testWatcher);

    archive = Archive.launch(
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .aeronDirectoryName(mediaDriverContext.aeronDirectoryName())
            .errorHandler(Tests::onError)
            .archiveDir(archiveDir)
            .recordingEventsEnabled(false)
            .threadingMode(ArchiveThreadingMode.SHARED)
            .deleteArchiveOnStart(true));

    aeron = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(mediaDriverContext.aeronDirectoryName()));

    aeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .errorHandler(Tests::onError)
            .aeron(aeron));
}
 
Example #21
Source File: ArchiveAuthenticationTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
private void connectClient(final CredentialsSupplier credentialsSupplier)
{
    aeron = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(aeronDirectoryName));

    aeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .credentialsSupplier(credentialsSupplier)
            .aeron(aeron));
}
 
Example #22
Source File: ClusterTool.java    From aeron with Apache License 2.0 5 votes vote down vote up
public static void recoveryPlan(final PrintStream out, final File clusterDir, final int serviceCount)
{
    try (AeronArchive archive = AeronArchive.connect();
        RecordingLog recordingLog = new RecordingLog(clusterDir))
    {
        out.println(recordingLog.createRecoveryPlan(archive, serviceCount));
    }
}
 
Example #23
Source File: BasicArchiveTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void before()
{
    final String aeronDirectoryName = CommonContext.generateRandomDirName();

    mediaDriver = TestMediaDriver.launch(
        new MediaDriver.Context()
            .aeronDirectoryName(aeronDirectoryName)
            .termBufferSparseFile(true)
            .threadingMode(ThreadingMode.SHARED)
            .errorHandler(Tests::onError)
            .spiesSimulateConnection(false)
            .dirDeleteOnStart(true),
        testWatcher);

    archive = Archive.launch(
        new Archive.Context()
            .maxCatalogEntries(Common.MAX_CATALOG_ENTRIES)
            .aeronDirectoryName(aeronDirectoryName)
            .deleteArchiveOnStart(true)
            .archiveDir(new File(SystemUtil.tmpDirName(), "archive"))
            .fileSyncLevel(0)
            .threadingMode(ArchiveThreadingMode.SHARED));

    aeron = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(aeronDirectoryName));

    aeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .aeron(aeron));
}
 
Example #24
Source File: ManageRecordingHistoryTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@Test
@Timeout(10)
public void shouldDetachThenAttachFullSegments()
{
    final String messagePrefix = "Message-Prefix-";
    final long targetPosition = (SEGMENT_LENGTH * 3L) + 1;

    try (Publication publication = aeronArchive.addRecordedPublication(uriBuilder.build(), STREAM_ID))
    {
        final CountersReader counters = aeron.countersReader();
        final int counterId = Common.awaitRecordingCounterId(counters, publication.sessionId());
        final long recordingId = RecordingPos.getRecordingId(counters, counterId);

        offerToPosition(publication, messagePrefix, targetPosition);
        awaitPosition(counters, counterId, publication.position());
        aeronArchive.stopRecording(publication);

        final long startPosition = 0L;
        final long segmentFileBasePosition = AeronArchive.segmentFileBasePosition(
            startPosition, SEGMENT_LENGTH * 2L, TERM_LENGTH, SEGMENT_LENGTH);

        aeronArchive.detachSegments(recordingId, segmentFileBasePosition);
        assertEquals(segmentFileBasePosition, aeronArchive.getStartPosition(recordingId));

        final long attachSegments = aeronArchive.attachSegments(recordingId);
        assertEquals(2L, attachSegments);
        assertEquals(startPosition, aeronArchive.getStartPosition(recordingId));
    }
}
 
Example #25
Source File: ManageRecordingHistoryTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@Test
@Timeout(10)
public void shouldDetachThenAttachWhenStartNotSegmentAligned()
{
    final String messagePrefix = "Message-Prefix-";
    final int initialTermId = 7;
    final long targetPosition = (SEGMENT_LENGTH * 3L) + 1;
    final long startPosition = (TERM_LENGTH * 2L) + (FRAME_ALIGNMENT * 2L);
    uriBuilder.initialPosition(startPosition, initialTermId, TERM_LENGTH);

    try (Publication publication = aeronArchive.addRecordedExclusivePublication(uriBuilder.build(), STREAM_ID))
    {
        assertEquals(startPosition, publication.position());

        final CountersReader counters = aeron.countersReader();
        final int counterId = Common.awaitRecordingCounterId(counters, publication.sessionId());
        final long recordingId = RecordingPos.getRecordingId(counters, counterId);

        offerToPosition(publication, messagePrefix, targetPosition);
        awaitPosition(counters, counterId, publication.position());
        aeronArchive.stopRecording(publication);

        final long segmentFileBasePosition = AeronArchive.segmentFileBasePosition(
            startPosition, startPosition + (SEGMENT_LENGTH * 2L), TERM_LENGTH, SEGMENT_LENGTH);

        aeronArchive.detachSegments(recordingId, segmentFileBasePosition);
        assertEquals(segmentFileBasePosition, aeronArchive.getStartPosition(recordingId));

        final long attachSegments = aeronArchive.attachSegments(recordingId);
        assertEquals(2L, attachSegments);
        assertEquals(startPosition, aeronArchive.getStartPosition(recordingId));
    }
}
 
Example #26
Source File: ArchiveTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
private void validateArchiveFile(final int messageCount, final long recordingId)
{
    final File archiveDir = archive.context().archiveDir();
    final Catalog catalog = archive.context().catalog();
    remaining = totalDataLength;
    this.messageCount = 0;

    while (catalog.stopPosition(recordingId) != stopPosition)
    {
        Tests.yield();
    }

    try (RecordingReader recordingReader = new RecordingReader(
        catalog.recordingSummary(recordingId, new RecordingSummary()),
        archiveDir,
        NULL_POSITION,
        AeronArchive.NULL_LENGTH))
    {
        while (!recordingReader.isDone())
        {
            if (0 == recordingReader.poll(this::validateRecordingFragment, messageCount))
            {
                Tests.yield();
            }
        }
    }

    assertEquals(0L, remaining);
    assertEquals(messageCount, this.messageCount);
}
 
Example #27
Source File: ManageRecordingHistoryTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void before()
{
    archivingMediaDriver = TestMediaDriver.launch(
        new MediaDriver.Context()
            .publicationTermBufferLength(Common.TERM_LENGTH)
            .termBufferSparseFile(true)
            .threadingMode(ThreadingMode.SHARED)
            .errorHandler(Tests::onError)
            .spiesSimulateConnection(true)
            .dirDeleteOnStart(true),
        testWatcher);

    archive = Archive.launch(
        new Archive.Context()
            .maxCatalogEntries(Common.MAX_CATALOG_ENTRIES)
            .segmentFileLength(SEGMENT_LENGTH)
            .deleteArchiveOnStart(true)
            .archiveDir(new File(SystemUtil.tmpDirName(), "archive"))
            .fileSyncLevel(0)
            .threadingMode(ArchiveThreadingMode.SHARED));

    aeron = Aeron.connect();

    aeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .aeron(aeron));
}
 
Example #28
Source File: LiveReplayRemoteArchiveTest.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
protected LiveReplayMessageTransceiver createMessageTransceiver(
    final ArchivingMediaDriver archivingMediaDriver,
    final AeronArchive aeronArchive,
    final MessageRecorder messageRecorder)
{
    return new LiveReplayMessageTransceiver(null, aeronArchive, false, messageRecorder);
}
 
Example #29
Source File: LiveRecordingTest.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
protected LiveRecordingMessageTransceiver createMessageTransceiver(
    final ArchivingMediaDriver archivingMediaDriver,
    final AeronArchive aeronArchive,
    final MessageRecorder messageRecorder)
{
    return new LiveRecordingMessageTransceiver(archivingMediaDriver, aeronArchive, false, messageRecorder);
}
 
Example #30
Source File: RecordingLogTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldIgnoreInvalidMidSnapshotInRecoveryPlan()
{
    final int serviceCount = 1;

    try (RecordingLog recordingLog = new RecordingLog(TEMP_DIR))
    {
        recordingLog.appendSnapshot(1L, 1L, 0, 777L, 0, 0);
        recordingLog.appendSnapshot(2L, 1L, 0, 777L, 0, SERVICE_ID);
        recordingLog.appendSnapshot(3L, 1L, 0, 888L, 0, 0);
        recordingLog.appendSnapshot(4L, 1L, 0, 888L, 0, SERVICE_ID);
        recordingLog.appendSnapshot(5L, 1L, 0, 999L, 0, 0);
        recordingLog.appendSnapshot(6L, 1L, 0, 999L, 0, SERVICE_ID);

        recordingLog.invalidateEntry(1L, 2);
        recordingLog.invalidateEntry(1L, 3);
    }

    try (RecordingLog recordingLog = new RecordingLog(TEMP_DIR))
    {
        final AeronArchive mockArchive = mock(AeronArchive.class);
        final RecordingLog.RecoveryPlan recoveryPlan = recordingLog.createRecoveryPlan(mockArchive, serviceCount);
        assertEquals(2, recoveryPlan.snapshots.size());
        assertEquals(SERVICE_ID, recoveryPlan.snapshots.get(0).serviceId);
        assertEquals(6L, recoveryPlan.snapshots.get(0).recordingId);
        assertEquals(0, recoveryPlan.snapshots.get(1).serviceId);
        assertEquals(5L, recoveryPlan.snapshots.get(1).recordingId);
    }
}