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;
}
Aggregations