Search in sources :

Example 36 with ChecksumIndexInput

use of org.apache.lucene.store.ChecksumIndexInput in project zm-mailbox by Zimbra.

the class LuceneIndexRepair method repair.

/**
 * Repair the index data.
 *
 * @return number of repairs conducted, or 0 if nothing was repaired
 * @throws IOException error on accessing the index data
 */
int repair() throws IOException {
    String segsFilename = SegmentInfos.getCurrentSegmentFileName(directory);
    long gen = SegmentInfos.generationFromSegmentsFileName(segsFilename);
    String nextSegsFilename = getSegmentsFilename(++gen);
    ChecksumIndexInput input = new ChecksumIndexInput(directory.openInput(segsFilename));
    try {
        ChecksumIndexOutput output = new ChecksumIndexOutput(directory.createOutput(nextSegsFilename));
        try {
            convert(input, output);
        } finally {
            output.close();
        }
    } finally {
        input.close();
    }
    if (repaired == 0) {
        directory.deleteFile(nextSegsFilename);
        return repaired;
    }
    directory.sync(Collections.singleton(nextSegsFilename));
    try {
        commit(gen);
    } catch (IOException e) {
        directory.deleteFile(nextSegsFilename);
        throw e;
    }
    String backupFilename = "REPAIR_" + DateTools.dateToString(new Date(), DateTools.Resolution.SECOND) + "." + segsFilename;
    rename(segsFilename, backupFilename);
    return repaired;
}
Also used : ChecksumIndexInput(org.apache.lucene.store.ChecksumIndexInput) IOException(java.io.IOException) ChecksumIndexOutput(org.apache.lucene.store.ChecksumIndexOutput) Date(java.util.Date)

Aggregations

ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)36 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)19 BufferedChecksumIndexInput (org.apache.lucene.store.BufferedChecksumIndexInput)11 IndexOutput (org.apache.lucene.store.IndexOutput)10 IndexInput (org.apache.lucene.store.IndexInput)9 IOException (java.io.IOException)8 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)6 SegmentInfo (org.apache.lucene.index.SegmentInfo)5 Directory (org.apache.lucene.store.Directory)5 Path (java.nio.file.Path)4 RAMFile (org.apache.lucene.store.RAMFile)4 RAMInputStream (org.apache.lucene.store.RAMInputStream)4 RAMOutputStream (org.apache.lucene.store.RAMOutputStream)4 BytesRef (org.apache.lucene.util.BytesRef)4 Version (org.apache.lucene.util.Version)4 FileChannel (java.nio.channels.FileChannel)3 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)3 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)3 Sort (org.apache.lucene.search.Sort)3 SortField (org.apache.lucene.search.SortField)3