本文整理汇总了C#中Lucene.Net.Store.Directory.Sync方法的典型用法代码示例。如果您正苦于以下问题:C# Directory.Sync方法的具体用法?C# Directory.Sync怎么用?C# Directory.Sync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Store.Directory
的用法示例。
在下文中一共展示了Directory.Sync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteSegmentsGen
/// <summary>
/// A utility for writing the <seealso cref="IndexFileNames#SEGMENTS_GEN"/> file to a
/// <seealso cref="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
/// </summary>
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.
}
}
}
示例2: Write
private void Write(Directory directory)
{
string segmentsFileName = NextSegmentFileName;
// Always advance the generation on write:
if (_generation == -1)
{
_generation = 1;
}
else
{
_generation++;
}
IndexOutput segnOutput = null;
bool success = false;
var upgradedSIFiles = new HashSet<string>();
try
{
segnOutput = directory.CreateOutput(segmentsFileName, IOContext.DEFAULT);
CodecUtil.WriteHeader(segnOutput, "segments", VERSION_48);
segnOutput.WriteLong(Version);
segnOutput.WriteInt(Counter); // write counter
segnOutput.WriteInt(Size()); // write infos
foreach (SegmentCommitInfo siPerCommit in segments)
{
SegmentInfo si = siPerCommit.Info;
segnOutput.WriteString(si.Name);
segnOutput.WriteString(si.Codec.Name);
segnOutput.WriteLong(siPerCommit.DelGen);
int delCount = siPerCommit.DelCount;
if (delCount < 0 || delCount > si.DocCount)
{
throw new InvalidOperationException("cannot write segment: invalid docCount segment=" + si.Name + " docCount=" + si.DocCount + " delCount=" + delCount);
}
segnOutput.WriteInt(delCount);
segnOutput.WriteLong(siPerCommit.FieldInfosGen);
IDictionary<long, ISet<string>> genUpdatesFiles = siPerCommit.UpdatesFiles;
segnOutput.WriteInt(genUpdatesFiles.Count);
foreach (KeyValuePair<long, ISet<string>> e in genUpdatesFiles)
{
segnOutput.WriteLong(e.Key);
segnOutput.WriteStringSet(e.Value);
}
Debug.Assert(si.Dir == directory);
// If this segment is pre-4.x, perform a one-time
// "ugprade" to write the .si file for it:
string version = si.Version;
if (version == null || StringHelper.VersionComparator.Compare(version, "4.0") < 0)
{
if (!SegmentWasUpgraded(directory, si))
{
string markerFileName = IndexFileNames.SegmentFileName(si.Name, "upgraded", Lucene3xSegmentInfoFormat.UPGRADED_SI_EXTENSION);
si.AddFile(markerFileName);
string segmentFileName = Write3xInfo(directory, si, IOContext.DEFAULT);
upgradedSIFiles.Add(segmentFileName);
directory.Sync(/*Collections.singletonList(*/new[] { segmentFileName }/*)*/);
// Write separate marker file indicating upgrade
// is completed. this way, if there is a JVM
// kill/crash, OS crash, power loss, etc. while
// writing the upgraded file, the marker file
// will be missing:
IndexOutput @out = directory.CreateOutput(markerFileName, IOContext.DEFAULT);
try
{
CodecUtil.WriteHeader(@out, SEGMENT_INFO_UPGRADE_CODEC, SEGMENT_INFO_UPGRADE_VERSION);
}
finally
{
@out.Dispose();
}
upgradedSIFiles.Add(markerFileName);
directory.Sync(/*Collections.SingletonList(*/new[] { markerFileName }/*)*/);
}
}
}
segnOutput.WriteStringStringMap(_userData);
PendingSegnOutput = segnOutput;
success = true;
}
finally
{
if (!success)
{
// We hit an exception above; try to close the file
// but suppress any exception:
IOUtils.CloseWhileHandlingException(segnOutput);
foreach (string fileName in upgradedSIFiles)
{
try
{
directory.DeleteFile(fileName);
}
catch (Exception)
//.........这里部分代码省略.........
示例3: FinishCommit
internal void FinishCommit(Directory dir)
{
if (PendingSegnOutput == null)
{
throw new InvalidOperationException("prepareCommit was not called");
}
bool success = false;
try
{
CodecUtil.WriteFooter(PendingSegnOutput);
success = true;
}
finally
{
if (!success)
{
// Closes pendingSegnOutput & deletes partial segments_N:
RollbackCommit(dir);
}
else
{
success = false;
try
{
PendingSegnOutput.Dispose();
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.
var fileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", _generation);
success = false;
try
{
dir.Sync(Collections.Singleton(fileName));
success = true;
}
finally
{
if (!success)
{
try
{
dir.DeleteFile(fileName);
}
catch (Exception)
{
// Suppress so we keep throwing the original exception
}
}
}
_lastGeneration = _generation;
WriteSegmentsGen(dir, _generation);
}