Apache Lucene open-source search software
LUCENE-6209: IndexWriter now logs (to infoStream) how much time flushing threads were stalled because of > 2X IW's RAM buffer in flush backlog
Michael McCandless669e9cf617c5
diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.javaindex 8c0b93af132..bdf8195327a 100644--- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java+++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java@@ -75,7 +75,7 @@ final class DocumentsWriterFlushControl implements Accountable {DocumentsWriterFlushControl(DocumentsWriter documentsWriter, LiveIndexWriterConfig config, BufferedUpdatesStream bufferedUpdatesStream) {this.infoStream = config.getInfoStream();- this.stallControl = new DocumentsWriterStallControl();+ this.stallControl = new DocumentsWriterStallControl(config);this.perThreadPool = documentsWriter.perThreadPool;this.flushPolicy = documentsWriter.flushPolicy;this.config = config;diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterStallControl.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterStallControl.javaindex a799fbf58ec..c83813bafcb 100644--- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterStallControl.java+++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterStallControl.java@@ -20,6 +20,7 @@ import java.util.IdentityHashMap;import java.util.Map;import org.apache.lucene.index.DocumentsWriterPerThreadPool.ThreadState;+import org.apache.lucene.util.InfoStream;import org.apache.lucene.util.ThreadInterruptedException;/**@@ -43,6 +44,11 @@ final class DocumentsWriterStallControl {private int numWaiting; // only with assertprivate boolean wasStalled; // only with assertprivate final Map<Thread, Boolean> waiting = new IdentityHashMap<>(); // only with assert+ private final InfoStream infoStream;++ DocumentsWriterStallControl(LiveIndexWriterConfig iwc) {+ infoStream = iwc.getInfoStream();+ }/*** Update the stalled flag status. This method will set the stalled flag to@@ -85,8 +91,13 @@ final class DocumentsWriterStallControl {return stalled;}-+ long stallStartNS;+private void incWaiters() {+ stallStartNS = System.nanoTime();+ if (infoStream.isEnabled("DW") && numWaiting == 0) {+ infoStream.message("DW", "now stalling flushes");+ }numWaiting++;assert waiting.put(Thread.currentThread(), Boolean.TRUE) == null;assert numWaiting > 0;@@ -96,6 +107,10 @@ final class DocumentsWriterStallControl {numWaiting--;assert waiting.remove(Thread.currentThread()) != null;assert numWaiting >= 0;+ if (infoStream.isEnabled("DW") && numWaiting == 0) {+ long stallEndNS = System.nanoTime();+ infoStream.message("DW", "done stalling flushes for " + ((stallEndNS - stallStartNS)/1000000.0) + " ms");+ }}synchronized boolean hasBlocked() { // for testsdiff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocumentsWriterStallControl.java b/lucene/core/src/test/org/apache/lucene/index/TestDocumentsWriterStallControl.javaindex 319d7bc61d4..c656965848a 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestDocumentsWriterStallControl.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestDocumentsWriterStallControl.java@@ -33,7 +33,7 @@ import org.apache.lucene.util.ThreadInterruptedException;public class TestDocumentsWriterStallControl extends LuceneTestCase {public void testSimpleStall() throws InterruptedException {- DocumentsWriterStallControl ctrl = new DocumentsWriterStallControl();+ DocumentsWriterStallControl ctrl = new DocumentsWriterStallControl(newIndexWriterConfig());ctrl.updateStalled(false);Thread[] waitThreads = waitThreads(atLeast(1), ctrl);@@ -55,7 +55,7 @@ public class TestDocumentsWriterStallControl extends LuceneTestCase {}public void testRandom() throws InterruptedException {- final DocumentsWriterStallControl ctrl = new DocumentsWriterStallControl();+ final DocumentsWriterStallControl ctrl = new DocumentsWriterStallControl(newIndexWriterConfig());ctrl.updateStalled(false);Thread[] stallThreads = new Thread[atLeast(3)];@@ -96,7 +96,7 @@ public class TestDocumentsWriterStallControl extends LuceneTestCase {}public void testAccquireReleaseRace() throws InterruptedException {- final DocumentsWriterStallControl ctrl = new DocumentsWriterStallControl();+ final DocumentsWriterStallControl ctrl = new DocumentsWriterStallControl(newIndexWriterConfig());ctrl.updateStalled(false);final AtomicBoolean stop = new AtomicBoolean(false);final AtomicBoolean checkPoint = new AtomicBoolean(true);