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);
}
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);
}
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));
}
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);
}
}
}
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);
}
Aggregations