List of usage examples for org.apache.lucene.index SegmentInfos generationFromSegmentsFileName
public static long generationFromSegmentsFileName(String fileName)
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; }