use of org.apache.jackrabbit.oak.segment.spi.persistence.JournalFile in project jackrabbit-oak by apache.
the class Compact method run.
public int run() {
System.out.printf("Compacting %s with %s\n", path, fileAccessMode.description);
System.out.printf(" before\n");
Set<File> beforeFiles = listFiles(path);
printFiles(System.out, beforeFiles);
System.out.printf(" size %s\n", printableSize(sizeOfDirectory(path)));
System.out.printf(" -> compacting\n");
Stopwatch watch = Stopwatch.createStarted();
try (FileStore store = newFileStore()) {
if (!store.compactFull()) {
System.out.printf("Compaction cancelled after %s.\n", printableStopwatch(watch));
return 1;
}
System.out.printf(" -> cleaning up\n");
store.cleanup();
JournalFile journal = new LocalJournalFile(path, "journal.log");
String head;
try (JournalReader journalReader = new JournalReader(journal)) {
head = String.format("%s root %s\n", journalReader.next().getRevision(), System.currentTimeMillis());
}
try (JournalFileWriter journalWriter = journal.openJournalWriter()) {
System.out.printf(" -> writing new %s: %s\n", journal.getName(), head);
journalWriter.truncate();
journalWriter.writeLine(head);
}
} catch (Exception e) {
watch.stop();
e.printStackTrace(System.err);
System.out.printf("Compaction failed after %s.\n", printableStopwatch(watch));
return 1;
}
watch.stop();
System.out.printf(" after\n");
Set<File> afterFiles = listFiles(path);
printFiles(System.out, afterFiles);
System.out.printf(" size %s\n", printableSize(sizeOfDirectory(path)));
System.out.printf(" removed files %s\n", fileNames(difference(beforeFiles, afterFiles)));
System.out.printf(" added files %s\n", fileNames(difference(afterFiles, beforeFiles)));
System.out.printf("Compaction succeeded in %s.\n", printableStopwatch(watch));
return 0;
}
use of org.apache.jackrabbit.oak.segment.spi.persistence.JournalFile in project jackrabbit-oak by apache.
the class SegmentTarExplorerBackend method readRevisions.
@Override
public List<String> readRevisions() {
JournalFile journal = new LocalJournalFile(path, "journal.log");
if (!journal.exists()) {
return newArrayList();
}
List<String> revs = newArrayList();
JournalReader journalReader = null;
try {
journalReader = new JournalReader(journal);
Iterator<String> revisionIterator = Iterators.transform(journalReader, new Function<JournalEntry, String>() {
@Nullable
@Override
public String apply(JournalEntry entry) {
return entry.getRevision();
}
});
try {
revs = newArrayList(revisionIterator);
} finally {
journalReader.close();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (journalReader != null) {
journalReader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return revs;
}
Aggregations