Search in sources :

Example 1 with ChecksumIndexOutput

use of org.apache.lucene.store.ChecksumIndexOutput 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

IOException (java.io.IOException)1 Date (java.util.Date)1 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)1 ChecksumIndexOutput (org.apache.lucene.store.ChecksumIndexOutput)1