use of org.apache.cassandra.db.commitlog.CommitLogSegment.CommitLogSegmentFileComparator in project cassandra by apache.
the class CommitLog method recoverSegmentsOnDisk.
/**
* Perform recovery on commit logs located in the directory specified by the config file.
*
* @return the number of mutations replayed
* @throws IOException
*/
public int recoverSegmentsOnDisk() throws IOException {
BiPredicate<File, String> unmanagedFilesFilter = (dir, name) -> CommitLogDescriptor.isValid(name) && CommitLogSegment.shouldReplay(name);
// archiving pass, which we should not treat as serious.
for (File file : new File(segmentManager.storageDirectory).tryList(unmanagedFilesFilter)) {
archiver.maybeArchive(file.path(), file.name());
archiver.maybeWaitForArchiving(file.name());
}
assert archiver.archivePending.isEmpty() : "Not all commit log archive tasks were completed before restore";
archiver.maybeRestoreArchive();
// List the files again as archiver may have added segments.
File[] files = new File(segmentManager.storageDirectory).tryList(unmanagedFilesFilter);
int replayed = 0;
if (files.length == 0) {
logger.info("No commitlog files found; skipping replay");
} else {
Arrays.sort(files, new CommitLogSegmentFileComparator());
logger.info("Replaying {}", StringUtils.join(files, ", "));
replayed = recoverFiles(files);
logger.info("Log replay complete, {} replayed mutations", replayed);
for (File f : files) segmentManager.handleReplayedSegment(f);
}
return replayed;
}
Aggregations