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