本文整理汇总了Java中org.apache.lucene.store.Directory.sync方法的典型用法代码示例。如果您正苦于以下问题:Java Directory.sync方法的具体用法?Java Directory.sync怎么用?Java Directory.sync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.store.Directory
的用法示例。
在下文中一共展示了Directory.sync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeSegmentsGen
import org.apache.lucene.store.Directory; //导入方法依赖的package包/类
/**
* A utility for writing the {@link IndexFileNames#SEGMENTS_GEN} file to a
* {@link Directory}.
*
* <p>
* <b>NOTE:</b> this is an internal utility which is kept public so that it's
* accessible by code from other packages. You should avoid calling this
* method unless you're absolutely sure what you're doing!
*
* @lucene.internal
*/
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.close();
dir.sync(Collections.singleton(IndexFileNames.SEGMENTS_GEN));
}
} catch (Throwable t) {
// It's OK if we fail to write this file since it's
// used only as one of the retry fallbacks.
IOUtils.deleteFilesIgnoringExceptions(dir, IndexFileNames.SEGMENTS_GEN);
}
}
示例2: finishCommit
import org.apache.lucene.store.Directory; //导入方法依赖的package包/类
/** Returns the committed segments_N filename. */
final String finishCommit(Directory dir) throws IOException {
if (pendingSegnOutput == null) {
throw new IllegalStateException("prepareCommit was not called");
}
boolean success = false;
final String dest;
try {
CodecUtil.writeFooter(pendingSegnOutput);
success = true;
} finally {
if (!success) {
// Closes pendingSegnOutput & deletes partial segments_N:
rollbackCommit(dir);
} else {
success = false;
try {
pendingSegnOutput.close();
success = true;
} finally {
if (!success) {
// Closes pendingSegnOutput & deletes partial segments_N:
rollbackCommit(dir);
} else {
pendingSegnOutput = null;
}
}
}
}
// NOTE: if we crash here, we have left a segments_N
// file in the directory in a possibly corrupt state (if
// some bytes made it to stable storage and others
// didn't). But, the segments_N file includes checksum
// at the end, which should catch this case. So when a
// reader tries to read it, it will throw a
// CorruptIndexException, which should cause the retry
// logic in SegmentInfos to kick in and load the last
// good (previous) segments_N-1 file.
final String fileName = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS, "", generation);
success = false;
try {
dir.sync(Collections.singleton(fileName));
success = true;
} finally {
if (!success) {
IOUtils.deleteFilesIgnoringExceptions(dir, fileName);
}
}
lastGeneration = generation;
writeSegmentsGen(dir, generation);
return fileName;
}