diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 59779ded566..2a8397c1224 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -91,6 +91,9 @@ API Changes incorrect results for Numeric fields using precisionStep (hossman, Robert Muir) +* LUCENE-6511: Add missing ConcurrentMergeScheduler.getAutoIOThrottle + getter (Simon Willnauer, Mike McCandless) + Bug fixes * LUCENE-6500: ParallelCompositeReader did not always call diff --git a/lucene/core/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java b/lucene/core/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java index 641598323df..edbacd53303 100644 --- a/lucene/core/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java +++ b/lucene/core/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java @@ -214,6 +214,11 @@ public class ConcurrentMergeScheduler extends MergeScheduler { updateMergeThreads(); } + /** Returns true if auto IO throttling is currently enabled. */ + public synchronized boolean getAutoIOThrottle() { + return doAutoIOThrottle; + } + /** Returns the currently set per-merge IO writes rate limit, if {@link #enableAutoIOThrottle} * was called, else {@code Double.POSITIVE_INFINITY}. */ public synchronized double getIORateLimitMBPerSec() { diff --git a/lucene/core/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java b/lucene/core/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java index ba8c8b746b0..083e4269ac0 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java @@ -635,6 +635,14 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase { assertEquals(6, cms.getMaxMergeCount()); } + public void testAutoIOThrottleGetter() throws Exception { + ConcurrentMergeScheduler cms = new ConcurrentMergeScheduler(); + cms.disableAutoIOThrottle(); + assertFalse(cms.getAutoIOThrottle()); + cms.enableAutoIOThrottle(); + assertTrue(cms.getAutoIOThrottle()); + } + public void testNonSpinningDefaults() throws Exception { ConcurrentMergeScheduler cms = new ConcurrentMergeScheduler(); cms.setDefaultMaxMergesAndThreads(false); diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java index 51306dbb350..5463dcec191 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java @@ -915,6 +915,7 @@ public abstract class LuceneTestCase extends Assert { cms.setMaxMergesAndThreads(maxMergeCount, maxThreadCount); if (random().nextBoolean()) { cms.disableAutoIOThrottle(); + assertFalse(cms.getAutoIOThrottle()); } cms.setForceMergeMBPerSec(10 + 10*random().nextDouble()); c.setMergeScheduler(cms); @@ -1180,11 +1181,18 @@ public abstract class LuceneTestCase extends Assert { // change CMS merge parameters MergeScheduler ms = c.getMergeScheduler(); if (ms instanceof ConcurrentMergeScheduler) { + ConcurrentMergeScheduler cms = (ConcurrentMergeScheduler) ms; int maxThreadCount = TestUtil.nextInt(r, 1, 4); int maxMergeCount = TestUtil.nextInt(r, maxThreadCount, maxThreadCount + 4); - ((ConcurrentMergeScheduler)ms).setMaxMergesAndThreads(maxMergeCount, maxThreadCount); + boolean enableAutoIOThrottle = random().nextBoolean(); + if (enableAutoIOThrottle) { + cms.enableAutoIOThrottle(); + } else { + cms.disableAutoIOThrottle(); + } + cms.setMaxMergesAndThreads(maxMergeCount, maxThreadCount); + didChange = true; } - didChange = true; } if (rarely(r)) {