use of io.aeron.archive.Archive in project Aeron by real-logic.
the class ArchiveLoggingAgentTest method testArchiveLogging.
@SuppressWarnings("try")
private void testArchiveLogging(final String enabledEvents, final EnumSet<ArchiveEventCode> expectedEvents) {
before(enabledEvents, expectedEvents);
final MediaDriver.Context mediaDriverCtx = new MediaDriver.Context().errorHandler(Tests::onError).dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().controlRequestChannel("aeron:udp?term-length=64k|endpoint=localhost:8010").controlRequestStreamId(100).controlResponseChannel("aeron:udp?term-length=64k|endpoint=localhost:0").controlResponseStreamId(101);
final Archive.Context archiveCtx = new Archive.Context().errorHandler(Tests::onError).archiveDir(new File(testDir, "archive")).deleteArchiveOnStart(true).recordingEventsEnabled(false).controlChannel(aeronArchiveContext.controlRequestChannel()).controlStreamId(aeronArchiveContext.controlRequestStreamId()).localControlStreamId(aeronArchiveContext.controlRequestStreamId()).recordingEventsChannel(aeronArchiveContext.recordingEventsChannel()).threadingMode(ArchiveThreadingMode.SHARED);
try (ArchivingMediaDriver ignore1 = ArchivingMediaDriver.launch(mediaDriverCtx, archiveCtx)) {
try (AeronArchive ignore2 = AeronArchive.connect(aeronArchiveContext)) {
Tests.await(WAIT_LIST::isEmpty);
}
}
}
use of io.aeron.archive.Archive in project Aeron by real-logic.
the class ClusteredMediaDriver method launch.
/**
* Launch a new {@link ClusteredMediaDriver} with provided contexts.
*
* @param driverCtx for configuring the {@link MediaDriver}.
* @param archiveCtx for configuring the {@link Archive}.
* @param consensusModuleCtx for the configuration of the {@link ConsensusModule}.
* @return a new {@link ClusteredMediaDriver} with the provided contexts.
*/
public static ClusteredMediaDriver launch(final MediaDriver.Context driverCtx, final Archive.Context archiveCtx, final ConsensusModule.Context consensusModuleCtx) {
MediaDriver driver = null;
Archive archive = null;
ConsensusModule consensusModule = null;
try {
driver = MediaDriver.launch(driverCtx);
final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId);
final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? archiveCtx.errorHandler() : driverCtx.errorHandler();
archive = Archive.launch(archiveCtx.mediaDriverAgentInvoker(driver.sharedAgentInvoker()).aeronDirectoryName(driver.aeronDirectoryName()).errorHandler(errorHandler).errorCounter(errorCounter));
consensusModule = ConsensusModule.launch(consensusModuleCtx.aeronDirectoryName(driverCtx.aeronDirectoryName()));
return new ClusteredMediaDriver(driver, archive, consensusModule);
} catch (final Exception ex) {
CloseHelper.quietCloseAll(consensusModule, archive, driver);
throw ex;
}
}
use of io.aeron.archive.Archive in project Aeron by real-logic.
the class ClusterBackupMediaDriver method launch.
/**
* Launch a new {@link ClusterBackupMediaDriver} with provided contexts.
*
* @param driverCtx for configuring the {@link MediaDriver}.
* @param archiveCtx for configuring the {@link Archive}.
* @param clusterBackupCtx for the configuration of the {@link ClusterBackup}.
* @return a new {@link ClusterBackupMediaDriver} with the provided contexts.
*/
public static ClusterBackupMediaDriver launch(final MediaDriver.Context driverCtx, final Archive.Context archiveCtx, final ClusterBackup.Context clusterBackupCtx) {
MediaDriver driver = null;
Archive archive = null;
ClusterBackup clusterBackup = null;
try {
driver = MediaDriver.launch(driverCtx.spiesSimulateConnection(true));
final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId);
final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? archiveCtx.errorHandler() : driverCtx.errorHandler();
archive = Archive.launch(archiveCtx.aeronDirectoryName(driverCtx.aeronDirectoryName()).mediaDriverAgentInvoker(driver.sharedAgentInvoker()).errorHandler(errorHandler).errorCounter(errorCounter));
clusterBackup = ClusterBackup.launch(clusterBackupCtx.aeronDirectoryName(driverCtx.aeronDirectoryName()));
return new ClusterBackupMediaDriver(driver, archive, clusterBackup);
} catch (final Exception ex) {
CloseHelper.quietCloseAll(clusterBackup, archive, driver);
throw ex;
}
}
use of io.aeron.archive.Archive in project Aeron by real-logic.
the class StartFromTruncatedRecordingLogTest method truncateRecordingLogAndDeleteMarkFiles.
private void truncateRecordingLogAndDeleteMarkFiles(final int index) throws IOException {
final String baseDirName = baseDirName(index);
final File consensusModuleDataDir = new File(baseDirName, "consensus-module");
final File archiveDataDir = new File(baseDirName, "archive");
final File tmpRecordingFile = new File(baseDirName, RECORDING_LOG_FILE_NAME);
deleteFile(tmpRecordingFile);
deleteFile(new File(archiveDataDir, ArchiveMarkFile.FILENAME));
deleteFile(new File(consensusModuleDataDir, ClusterMarkFile.FILENAME));
try (RecordingLog recordingLog = new RecordingLog(consensusModuleDataDir, false)) {
final RecordingLog.Entry lastTermEntry = recordingLog.findLastTerm();
if (null == lastTermEntry) {
throw new IllegalStateException("no term found in recording log");
}
try (RecordingLog newRecordingLog = new RecordingLog(new File(baseDirName), true)) {
newRecordingLog.appendTerm(lastTermEntry.recordingId, lastTermEntry.leadershipTermId, lastTermEntry.termBaseLogPosition, lastTermEntry.timestamp);
newRecordingLog.commitLogPosition(lastTermEntry.leadershipTermId, lastTermEntry.logPosition);
appendServiceSnapshot(recordingLog, newRecordingLog, 0);
appendServiceSnapshot(recordingLog, newRecordingLog, ConsensusModule.Configuration.SERVICE_ID);
}
}
Files.copy(new File(baseDirName).toPath().resolve(RECORDING_LOG_FILE_NAME), consensusModuleDataDir.toPath().resolve(RECORDING_LOG_FILE_NAME), StandardCopyOption.REPLACE_EXISTING);
try (RecordingLog copiedRecordingLog = new RecordingLog(consensusModuleDataDir, false)) {
final LongHashSet recordingIds = new LongHashSet();
copiedRecordingLog.entries().stream().mapToLong((e) -> e.recordingId).forEach(recordingIds::add);
final Predicate<Path> filterPredicate = (p) -> p.getFileName().toString().endsWith(".rec");
try (Stream<Path> segments = Files.list(archiveDataDir.toPath()).filter(filterPredicate)) {
segments.filter((p) -> {
final String fileName = p.getFileName().toString();
final long recordingId = Long.parseLong(fileName.split("-")[0]);
return !recordingIds.contains(recordingId);
}).map(Path::toFile).forEach(StartFromTruncatedRecordingLogTest::deleteFile);
}
assertTrue(copiedRecordingLog.entries().size() <= 3);
}
}
use of io.aeron.archive.Archive in project Aeron by real-logic.
the class ClusteredArchive method launch.
/**
* Launch a new {@link ClusteredArchive} with provided contexts.
*
* @param aeronDirectoryName for connecting to the {@link MediaDriver}.
* @param archiveCtx for configuring the {@link Archive}.
* @param consensusModuleCtx for the configuration of the {@link ConsensusModule}.
* @return a new {@link ClusteredArchive} with the provided contexts.
*/
public static ClusteredArchive launch(final String aeronDirectoryName, final Archive.Context archiveCtx, final ConsensusModule.Context consensusModuleCtx) {
Archive archive = null;
ConsensusModule consensusModule = null;
try {
archive = Archive.launch(archiveCtx.aeronDirectoryName(aeronDirectoryName));
consensusModule = ConsensusModule.launch(consensusModuleCtx.aeronDirectoryName(aeronDirectoryName));
return new ClusteredArchive(archive, consensusModule);
} catch (final Exception ex) {
CloseHelper.quietCloseAll(consensusModule, archive);
throw ex;
}
}
Aggregations