Search in sources :

Example 1 with IndexConsistencyChecker

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker in project jackrabbit-oak by apache.

the class LuceneIndexMBeanImpl method getConsistencyCheckResult.

private Result getConsistencyCheckResult(String indexPath, boolean fullCheck) throws IOException {
    NodeState root = nodeStore.getRoot();
    Level level = fullCheck ? Level.FULL : Level.BLOBS_ONLY;
    IndexConsistencyChecker checker = new IndexConsistencyChecker(root, indexPath, workDir);
    return checker.check(level);
}
Also used : IndexConsistencyChecker(org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Level(org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker.Level)

Example 2 with IndexConsistencyChecker

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker in project jackrabbit-oak by apache.

the class IndexConsistencyCheckPrinter method print.

@Override
public void print(PrintWriter pw, Format format, boolean isZip) {
    Stopwatch watch = Stopwatch.createStarted();
    NodeState root = indexHelper.getNodeStore().getRoot();
    List<String> validIndexes = new ArrayList<>();
    List<String> invalidIndexes = new ArrayList<>();
    List<String> ignoredIndexes = new ArrayList<>();
    for (String indexPath : indexHelper.getIndexPathService().getIndexPaths()) {
        NodeState indexState = NodeStateUtils.getNode(root, indexPath);
        if (!TYPE_LUCENE.equals(indexState.getString(TYPE_PROPERTY_NAME))) {
            ignoredIndexes.add(indexPath);
            continue;
        }
        IndexConsistencyChecker checker = new IndexConsistencyChecker(root, indexPath, indexHelper.getWorkDir());
        checker.setPrintStream(new PrintStream(new WriterOutputStream(pw, Charsets.UTF_8)));
        try {
            IndexConsistencyChecker.Result result = checker.check(level);
            result.dump(pw);
            if (result.clean) {
                validIndexes.add(indexPath);
            } else {
                invalidIndexes.add(indexPath);
            }
            System.out.printf("%s => %s%n", indexPath, result.clean ? "valid" : "invalid <==");
        } catch (IOException e) {
            pw.printf("Error occurred while performing consistency check for index [%s]%n", indexPath);
            e.printStackTrace(pw);
        }
        pw.println();
    }
    print(validIndexes, "Valid indexes :", pw);
    print(invalidIndexes, "Invalid indexes :", pw);
    print(ignoredIndexes, "Ignored indexes as these are not of type lucene:", pw);
    pw.printf("Time taken %s%n", watch);
}
Also used : PrintStream(java.io.PrintStream) IndexConsistencyChecker(org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) IOException(java.io.IOException) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream)

Aggregations

IndexConsistencyChecker (org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker)2 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)2 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)1 Level (org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker.Level)1