use of org.apache.jackrabbit.oak.segment.spi.persistence.JournalFileWriter in project jackrabbit-oak by apache.
the class AzureJournalFileTest method testSplitJournalFiles.
@Test
public void testSplitJournalFiles() throws IOException {
assertFalse(journal.exists());
JournalFileWriter writer = journal.openJournalWriter();
for (int i = 0; i < 100; i++) {
writer.writeLine("line " + i);
}
assertTrue(journal.exists());
writer = journal.openJournalWriter();
for (int i = 100; i < 200; i++) {
writer.writeLine("line " + i);
}
JournalFileReader reader = journal.openJournalReader();
for (int i = 199; i >= 0; i--) {
assertEquals("line " + i, reader.readLine());
}
}
use of org.apache.jackrabbit.oak.segment.spi.persistence.JournalFileWriter 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;
}
Aggregations