Example usage for org.apache.lucene.index SegmentInfos generationFromSegmentsFileName

List of usage examples for org.apache.lucene.index SegmentInfos generationFromSegmentsFileName

Introduction

In this page you can find the example usage for org.apache.lucene.index SegmentInfos generationFromSegmentsFileName.

Prototype

public static long generationFromSegmentsFileName(String fileName) 

Source Link

Document

Parse the generation off the segments file name and return it.

Usage

From source file:com.zimbra.cs.index.LuceneIndexRepair.java

License:Open Source License

/**
 * Repair the index data./*from   w  ww .  j a  v a  2 s.c om*/
 *
 * @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;
}