private void RollbackTransaction()
{
lock (this)
{
if (infoStream != null)
Message("now rollback transaction");
if (docWriter != null)
{
docWriter.SetFlushedDocCount(localFlushedDocCount);
}
// Must finish merges before rolling back segmentInfos
// so merges don't hit exceptions on trying to commit
// themselves, don't get files deleted out from under
// them, etc:
FinishMerges(false);
// Keep the same segmentInfos instance but replace all
// of its SegmentInfo instances. This is so the next
// attempt to commit using this instance of IndexWriter
// will always write to a new generation ("write once").
segmentInfos.Clear();
segmentInfos.AddRange(localRollbackSegmentInfos);
localRollbackSegmentInfos = null;
// This must come after we rollback segmentInfos, so
// that if a commit() kicks off it does not see the
// segmentInfos with external segments
FinishAddIndexes();
// Ask deleter to locate unreferenced files we had
// created & remove them:
deleter.Checkpoint(segmentInfos, false);
// Remove the incRef we did in startTransaction:
deleter.DecRef(segmentInfos);
// Also ask deleter to remove any newly created files
// that were never incref'd; this "garbage" is created
// when a merge kicks off but aborts part way through
// before it had a chance to incRef the files it had
// partially created
deleter.Refresh();
System.Threading.Monitor.PulseAll(this);
System.Diagnostics.Debug.Assert(!HasExternalSegments());
}
}