private bool PreUpdate() { EnsureOpen(); bool hasEvents = false; if (FlushControl.AnyStalledThreads() || FlushControl.NumQueuedFlushes() > 0) { // Help out flushing any queued DWPTs so we can un-stall: if (InfoStream.IsEnabled("DW")) { InfoStream.Message("DW", "DocumentsWriter has queued dwpt; will hijack this thread to flush pending segment(s)"); } do { // Try pick up pending threads here if possible DocumentsWriterPerThread flushingDWPT; while ((flushingDWPT = FlushControl.NextPendingFlush()) != null) { // Don't push the delete here since the update could fail! hasEvents |= DoFlush(flushingDWPT); } if (InfoStream.IsEnabled("DW")) { if (FlushControl.AnyStalledThreads()) { InfoStream.Message("DW", "WARNING DocumentsWriter has stalled threads; waiting"); } } FlushControl.WaitIfStalled(); // block if stalled } while (FlushControl.NumQueuedFlushes() != 0); // still queued DWPTs try help flushing if (InfoStream.IsEnabled("DW")) { InfoStream.Message("DW", "continue indexing after helping out flushing DocumentsWriter is healthy"); } } return(hasEvents); }