public static void WriteSegmentsGen(Directory dir, long generation)
{
try
{
IndexOutput genOutput = dir.CreateOutput(IndexFileNames.SEGMENTS_GEN, IOContext.READONCE);
try
{
genOutput.WriteInt(FORMAT_SEGMENTS_GEN_CURRENT);
genOutput.WriteLong(generation);
genOutput.WriteLong(generation);
CodecUtil.WriteFooter(genOutput);
}
finally
{
genOutput.Dispose();
dir.Sync(Collections.Singleton(IndexFileNames.SEGMENTS_GEN));
}
}
catch (Exception)
{
// It's OK if we fail to write this file since it's
// used only as one of the retry fallbacks.
try
{
dir.DeleteFile(IndexFileNames.SEGMENTS_GEN);
}
catch (Exception)
{
// Ignore; this file is only used in a retry
// fallback on init.
}
}
}