Search in sources :

Example 1 with JournalReader

use of org.apache.jackrabbit.oak.segment.file.JournalReader in project jackrabbit-oak by apache.

the class ConsistencyChecker method checkConsistency.

/**
     * Run a full traversal consistency check.
     *
     * @param directory  directory containing the tar files
     * @param journalFileName  name of the journal file containing the revision history
     * @param debugInterval    number of seconds between printing progress information to
     *                         the console during the full traversal phase.
     * @param checkBinaries    if {@code true} full content of binary properties will be scanned
     * @param filterPaths      collection of repository paths to be checked                         
     * @param ioStatistics     if {@code true} prints I/O statistics gathered while consistency 
     *                         check was performed
     * @param outWriter        text output stream writer
     * @param errWriter        text error stream writer                        
     * @throws IOException
     */
public static void checkConsistency(File directory, String journalFileName, long debugInterval, boolean checkBinaries, Set<String> filterPaths, boolean ioStatistics, PrintWriter outWriter, PrintWriter errWriter) throws IOException, InvalidFileStoreVersionException {
    try (JournalReader journal = new JournalReader(new File(directory, journalFileName));
        ConsistencyChecker checker = new ConsistencyChecker(directory, debugInterval, ioStatistics, outWriter, errWriter)) {
        Map<String, JournalEntry> pathToJournalEntry = newHashMap();
        Map<String, Set<String>> pathToCorruptPaths = newHashMap();
        for (String path : filterPaths) {
            pathToCorruptPaths.put(path, new HashSet<String>());
        }
        int count = 0;
        int revisionCount = 0;
        while (journal.hasNext() && count < filterPaths.size()) {
            JournalEntry journalEntry = journal.next();
            checker.print("Checking revision {0}", journalEntry.getRevision());
            try {
                revisionCount++;
                for (String path : filterPaths) {
                    if (pathToJournalEntry.get(path) == null) {
                        Set<String> corruptPaths = pathToCorruptPaths.get(path);
                        String corruptPath = checker.checkPathAtRevision(journalEntry.getRevision(), corruptPaths, path, checkBinaries);
                        if (corruptPath == null) {
                            checker.print("Path {0} is consistent", path);
                            pathToJournalEntry.put(path, journalEntry);
                            count++;
                        } else {
                            corruptPaths.add(corruptPath);
                        }
                    }
                }
            } catch (IllegalArgumentException e) {
                checker.printError("Skipping invalid record id {0}", journalEntry.getRevision());
            }
        }
        checker.print("Searched through {0} revisions", revisionCount);
        if (count == 0) {
            checker.print("No good revision found");
        } else {
            for (String path : filterPaths) {
                JournalEntry journalEntry = pathToJournalEntry.get(path);
                String revision = journalEntry != null ? journalEntry.getRevision() : null;
                long timestamp = journalEntry != null ? journalEntry.getTimestamp() : -1L;
                checker.print("Latest good revision for path {0} is {1} from {2}", path, toString(revision), toString(timestamp));
            }
        }
        if (ioStatistics) {
            checker.print("[I/O] Segment read: Number of operations: {0}", checker.statisticsIOMonitor.ioOperations);
            checker.print("[I/O] Segment read: Total size: {0} ({1} bytes)", humanReadableByteCount(checker.statisticsIOMonitor.readBytes.get()), checker.statisticsIOMonitor.readBytes);
            checker.print("[I/O] Segment read: Total time: {0} ns", checker.statisticsIOMonitor.readTime);
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) JournalEntry(org.apache.jackrabbit.oak.segment.file.JournalEntry) File(java.io.File) JournalReader(org.apache.jackrabbit.oak.segment.file.JournalReader)

Example 2 with JournalReader

use of org.apache.jackrabbit.oak.segment.file.JournalReader in project jackrabbit-oak by apache.

the class SegmentTarExplorerBackend method readRevisions.

@Override
public List<String> readRevisions() {
    File journal = new File(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 : IOException(java.io.IOException) File(java.io.File) JournalEntry(org.apache.jackrabbit.oak.segment.file.JournalEntry) Nullable(javax.annotation.Nullable) JournalReader(org.apache.jackrabbit.oak.segment.file.JournalReader)

Example 3 with JournalReader

use of org.apache.jackrabbit.oak.segment.file.JournalReader in project jackrabbit-oak by apache.

the class Compact method compact.

private void compact() throws IOException, InvalidFileStoreVersionException {
    try (FileStore store = newFileStore()) {
        store.compact();
    }
    System.out.println("    -> cleaning up");
    try (FileStore store = newFileStore()) {
        store.cleanup();
        File journal = new File(path, "journal.log");
        String head;
        try (JournalReader journalReader = new JournalReader(journal)) {
            head = journalReader.next().getRevision() + " root " + System.currentTimeMillis() + "\n";
        }
        try (RandomAccessFile journalFile = new RandomAccessFile(journal, "rw")) {
            System.out.println("    -> writing new " + journal.getName() + ": " + head);
            journalFile.setLength(0);
            journalFile.writeBytes(head);
            journalFile.getChannel().force(false);
        }
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) RandomAccessFile(java.io.RandomAccessFile) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) JournalReader(org.apache.jackrabbit.oak.segment.file.JournalReader)

Aggregations

File (java.io.File)3 JournalReader (org.apache.jackrabbit.oak.segment.file.JournalReader)3 JournalEntry (org.apache.jackrabbit.oak.segment.file.JournalEntry)2 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)1