Search in sources :

Example 1 with JournalFileWriter

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());
    }
}
Also used : JournalFileWriter(org.apache.jackrabbit.oak.segment.spi.persistence.JournalFileWriter) JournalFileReader(org.apache.jackrabbit.oak.segment.spi.persistence.JournalFileReader) Test(org.junit.Test)

Example 2 with JournalFileWriter

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;
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) JournalFileWriter(org.apache.jackrabbit.oak.segment.spi.persistence.JournalFileWriter) LocalJournalFile(org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile) JournalFile(org.apache.jackrabbit.oak.segment.spi.persistence.JournalFile) Stopwatch(com.google.common.base.Stopwatch) LocalJournalFile(org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile) LocalJournalFile(org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile) JournalFile(org.apache.jackrabbit.oak.segment.spi.persistence.JournalFile) File(java.io.File) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) IOException(java.io.IOException) JournalReader(org.apache.jackrabbit.oak.segment.file.JournalReader)

Aggregations

JournalFileWriter (org.apache.jackrabbit.oak.segment.spi.persistence.JournalFileWriter)2 Stopwatch (com.google.common.base.Stopwatch)1 File (java.io.File)1 IOException (java.io.IOException)1 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)1 InvalidFileStoreVersionException (org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException)1 JournalReader (org.apache.jackrabbit.oak.segment.file.JournalReader)1 LocalJournalFile (org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile)1 JournalFile (org.apache.jackrabbit.oak.segment.spi.persistence.JournalFile)1 JournalFileReader (org.apache.jackrabbit.oak.segment.spi.persistence.JournalFileReader)1 Test (org.junit.Test)1