Search in sources :

Example 1 with JournalFile

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;
}
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)

Example 2 with JournalFile

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;
}
Also used : LocalJournalFile(org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile) JournalFile(org.apache.jackrabbit.oak.segment.spi.persistence.JournalFile) IOException(java.io.IOException) LocalJournalFile(org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile) JournalEntry(org.apache.jackrabbit.oak.segment.file.JournalEntry) Nullable(javax.annotation.Nullable) JournalReader(org.apache.jackrabbit.oak.segment.file.JournalReader)

Aggregations

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