public class CheckIndex extends Object implements Closeable
As this tool checks every byte in the index, on a large index it can take quite a long time to run.
Modifier and Type | Class and Description |
---|---|
static class |
CheckIndex.Status
Returned from
checkIndex() detailing the health and status of the index. |
Constructor and Description |
---|
CheckIndex(Directory dir)
Create a new CheckIndex on the directory.
|
CheckIndex(Directory dir,
Lock writeLock)
Expert: create a directory with the specified lock.
|
Modifier and Type | Method and Description |
---|---|
CheckIndex.Status |
checkIndex()
Returns a
CheckIndex.Status instance detailing
the state of the index. |
CheckIndex.Status |
checkIndex(List<String> onlySegments)
Returns a
CheckIndex.Status instance detailing
the state of the index. |
void |
close() |
void |
exorciseIndex(CheckIndex.Status result)
Repairs the index using previously returned result
from
checkIndex() . |
boolean |
getChecksumsOnly()
See
getChecksumsOnly() . |
boolean |
getCrossCheckTermVectors()
|
boolean |
getFailFast()
See
setFailFast(boolean) . |
static void |
main(String[] args)
Command-line interface to check and exorcise corrupt segments from an index.
|
void |
setChecksumsOnly(boolean v)
If true, only validate physical integrity for all files.
|
void |
setCrossCheckTermVectors(boolean v)
If true, term vectors are compared against postings to
make sure they are the same.
|
void |
setFailFast(boolean v)
If true, just throw the original exception immediately when
corruption is detected, rather than continuing to iterate to other
segments looking for more corruption.
|
void |
setInfoStream(PrintStream out)
Set infoStream where messages should go.
|
void |
setInfoStream(PrintStream out,
boolean verbose)
Set infoStream where messages should go.
|
static CheckIndex.Status.DocValuesStatus |
testDocValues(CodecReader reader,
PrintStream infoStream,
boolean failFast)
Test docvalues.
|
static CheckIndex.Status.FieldInfoStatus |
testFieldInfos(CodecReader reader,
PrintStream infoStream,
boolean failFast)
Test field infos.
|
static CheckIndex.Status.FieldNormStatus |
testFieldNorms(CodecReader reader,
PrintStream infoStream,
boolean failFast)
Test field norms.
|
static CheckIndex.Status.LiveDocStatus |
testLiveDocs(CodecReader reader,
PrintStream infoStream,
boolean failFast)
Test live docs.
|
static CheckIndex.Status.TermIndexStatus |
testPostings(CodecReader reader,
PrintStream infoStream)
Test the term index.
|
static CheckIndex.Status.TermIndexStatus |
testPostings(CodecReader reader,
PrintStream infoStream,
boolean verbose,
boolean failFast)
Test the term index.
|
static CheckIndex.Status.StoredFieldStatus |
testStoredFields(CodecReader reader,
PrintStream infoStream,
boolean failFast)
Test stored fields.
|
static CheckIndex.Status.TermVectorStatus |
testTermVectors(CodecReader reader,
PrintStream infoStream)
Test term vectors.
|
static CheckIndex.Status.TermVectorStatus |
testTermVectors(CodecReader reader,
PrintStream infoStream,
boolean verbose,
boolean crossCheckTermVectors,
boolean failFast)
Test term vectors.
|
public CheckIndex(Directory dir) throws IOException
IOException
public CheckIndex(Directory dir, Lock writeLock) throws IOException
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void setCrossCheckTermVectors(boolean v)
public boolean getCrossCheckTermVectors()
public void setFailFast(boolean v)
public boolean getFailFast()
setFailFast(boolean)
.public boolean getChecksumsOnly()
getChecksumsOnly()
.public void setChecksumsOnly(boolean v)
public void setInfoStream(PrintStream out, boolean verbose)
public void setInfoStream(PrintStream out)
setInfoStream(PrintStream,boolean)
.public CheckIndex.Status checkIndex() throws IOException
CheckIndex.Status
instance detailing
the state of the index.
As this method checks every byte in the index, on a large index it can take quite a long time to run.
WARNING: make sure you only call this when the index is not opened by any writer.
IOException
public CheckIndex.Status checkIndex(List<String> onlySegments) throws IOException
CheckIndex.Status
instance detailing
the state of the index.onlySegments
- list of specific segment names to check
As this method checks every byte in the specified segments, on a large index it can take quite a long time to run.
IOException
public static CheckIndex.Status.LiveDocStatus testLiveDocs(CodecReader reader, PrintStream infoStream, boolean failFast) throws IOException
IOException
public static CheckIndex.Status.FieldInfoStatus testFieldInfos(CodecReader reader, PrintStream infoStream, boolean failFast) throws IOException
IOException
public static CheckIndex.Status.FieldNormStatus testFieldNorms(CodecReader reader, PrintStream infoStream, boolean failFast) throws IOException
IOException
public static CheckIndex.Status.TermIndexStatus testPostings(CodecReader reader, PrintStream infoStream) throws IOException
IOException
public static CheckIndex.Status.TermIndexStatus testPostings(CodecReader reader, PrintStream infoStream, boolean verbose, boolean failFast) throws IOException
IOException
public static CheckIndex.Status.StoredFieldStatus testStoredFields(CodecReader reader, PrintStream infoStream, boolean failFast) throws IOException
IOException
public static CheckIndex.Status.DocValuesStatus testDocValues(CodecReader reader, PrintStream infoStream, boolean failFast) throws IOException
IOException
public static CheckIndex.Status.TermVectorStatus testTermVectors(CodecReader reader, PrintStream infoStream) throws IOException
IOException
public static CheckIndex.Status.TermVectorStatus testTermVectors(CodecReader reader, PrintStream infoStream, boolean verbose, boolean crossCheckTermVectors, boolean failFast) throws IOException
IOException
public void exorciseIndex(CheckIndex.Status result) throws IOException
checkIndex()
. Note that this does not
remove any of the unreferenced files after it's done;
you must separately open an IndexWriter
, which
deletes unreferenced files when it's created.
WARNING: this writes a new segments file into the index, effectively removing all documents in broken segments from the index. BE CAREFUL.
IOException
public static void main(String[] args) throws IOException, InterruptedException
Run it like this:
java -ea:org.apache.lucene... org.apache.lucene.index.CheckIndex pathToIndex [-exorcise] [-verbose] [-segment X] [-segment Y]
-exorcise
: actually write a new segments_N file, removing any problematic segments. *LOSES DATA*
-segment X
: only check the specified
segment(s). This can be specified multiple times,
to check more than one segment, eg -segment _2
-segment _a
. You can't use this with the -exorcise
option.
WARNING: -exorcise
should only be used on an emergency basis as it will cause
documents (perhaps many) to be permanently removed from the index. Always make
a backup copy of your index before running this! Do not run this tool on an index
that is actively being written to. You have been warned!
Run without -exorcise, this tool will open the index, report version information and report any exceptions it hits and what action it would take if -exorcise were specified. With -exorcise, this tool will remove any segments that have issues and write a new segments_N file. This means all documents contained in the affected segments will be removed.
This tool exits with exit code 1 if the index cannot be opened or has any corruption, else 0.
IOException
InterruptedException
Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.