Search in sources :

Example 11 with CheckIndex

use of org.apache.lucene.index.CheckIndex in project zm-mailbox by Zimbra.

the class LuceneIndex method verify.

/**
 * Run a sanity check for the index. Callers are responsible to make sure the index is not opened by any writer.
 *
 * @param out info stream where messages should go. If null, no messages are printed.
 * @return true if no problems were found, otherwise false
 * @throws IOException failed to verify, but it doesn't necessarily mean the index is corrupted.
 */
@Override
public boolean verify(PrintStream out) throws IOException {
    if (!IndexReader.indexExists(luceneDirectory)) {
        out.println("index does not exist or no segments file found: " + luceneDirectory.getDirectory());
        return true;
    }
    CheckIndex check = new CheckIndex(luceneDirectory);
    if (out != null) {
        check.setInfoStream(out);
    }
    CheckIndex.Status status = check.checkIndex();
    return status.clean;
}
Also used : CheckIndex(org.apache.lucene.index.CheckIndex)

Example 12 with CheckIndex

use of org.apache.lucene.index.CheckIndex in project zm-mailbox by Zimbra.

the class LuceneViewer method doCheck.

private static void doCheck(CommandLine cl) throws Exception {
    Console console = new Console(cl.hasOption(CLI.O_VERBOSE));
    String indexDir = cl.getOptionValue(CLI.O_INPUT);
    console.info("Checking index " + indexDir);
    Directory dir = null;
    try {
        dir = LuceneDirectory.open(new File(indexDir));
    } catch (Throwable t) {
        console.info("ERROR: could not open directory \"" + indexDir + "\"; exiting");
        t.printStackTrace(System.out);
        System.exit(1);
    }
    CheckIndex checker = new CheckIndex(dir);
    checker.setInfoStream(System.out);
    Status result = checker.checkIndex();
    console.info("Result:" + (result.clean ? "clean" : "not clean"));
}
Also used : Status(org.apache.lucene.index.CheckIndex.Status) File(java.io.File) CheckIndex(org.apache.lucene.index.CheckIndex) Directory(org.apache.lucene.store.Directory)

Example 13 with CheckIndex

use of org.apache.lucene.index.CheckIndex in project crate by crate.

the class IndexShard method doCheckIndex.

private void doCheckIndex() throws IOException {
    final long timeNS = System.nanoTime();
    if (!Lucene.indexExists(store.directory())) {
        return;
    }
    BytesStreamOutput os = new BytesStreamOutput();
    PrintStream out = new PrintStream(os, false, StandardCharsets.UTF_8.name());
    if ("checksum".equals(checkIndexOnStartup)) {
        // physical verification only: verify all checksums for the latest commit
        IOException corrupt = null;
        MetadataSnapshot metadata = snapshotStoreMetadata();
        for (Map.Entry<String, StoreFileMetadata> entry : metadata.asMap().entrySet()) {
            try {
                Store.checkIntegrity(entry.getValue(), store.directory());
                out.println("checksum passed: " + entry.getKey());
            } catch (IOException exc) {
                out.println("checksum failed: " + entry.getKey());
                exc.printStackTrace(out);
                corrupt = exc;
            }
        }
        out.flush();
        if (corrupt != null) {
            logger.warn("check index [failure]\n{}", os.bytes().utf8ToString());
            throw corrupt;
        }
    } else {
        // full checkindex
        final CheckIndex.Status status = store.checkIndex(out);
        out.flush();
        if (!status.clean) {
            if (state == IndexShardState.CLOSED) {
                // ignore if closed....
                return;
            }
            logger.warn("check index [failure]\n{}", os.bytes().utf8ToString());
            throw new IOException("index check failure");
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("check index [success]\n{}", os.bytes().utf8ToString());
    }
    recoveryState.getVerifyIndex().checkIndexTime(Math.max(0, TimeValue.nsecToMSec(System.nanoTime() - timeNS)));
}
Also used : PrintStream(java.io.PrintStream) IOException(java.io.IOException) StoreFileMetadata(org.elasticsearch.index.store.StoreFileMetadata) Map(java.util.Map) ObjectLongMap(com.carrotsearch.hppc.ObjectLongMap) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) CheckIndex(org.apache.lucene.index.CheckIndex) MetadataSnapshot(org.elasticsearch.index.store.Store.MetadataSnapshot)

Aggregations

CheckIndex (org.apache.lucene.index.CheckIndex)13 PrintStream (java.io.PrintStream)8 IOException (java.io.IOException)7 Directory (org.apache.lucene.store.Directory)7 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 DirectoryReader (org.apache.lucene.index.DirectoryReader)2 FSDirectory (org.apache.lucene.store.FSDirectory)2 LockObtainFailedException (org.apache.lucene.store.LockObtainFailedException)2 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)2 ShardId (org.elasticsearch.index.shard.ShardId)2 MetadataSnapshot (org.elasticsearch.index.store.Store.MetadataSnapshot)2 ObjectLongMap (com.carrotsearch.hppc.ObjectLongMap)1 NotStoredException (io.anserini.index.NotStoredException)1