use of io.aeron.cluster.RecordingLog.RECORDING_LOG_FILE_NAME 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.cluster.RecordingLog.RECORDING_LOG_FILE_NAME 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);
}
}
Aggregations