Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-6119: make sure minPauseCheckBytes is set on init of MergeRateLimiter

Michael McCandlessd492a3b1b498
diff --git a/lucene/core/src/java/org/apache/lucene/index/MergeRateLimiter.java b/lucene/core/src/java/org/apache/lucene/index/MergeRateLimiter.java
index c98040503a7..9b19560129b 100644
--- a/lucene/core/src/java/org/apache/lucene/index/MergeRateLimiter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/MergeRateLimiter.java
@@ -36,8 +36,7 @@ public class MergeRateLimiter extends RateLimiter {
private final static int MIN_PAUSE_CHECK_MSEC = 25;
volatile long totalBytesWritten;
- // By default no IO limit:
- double mbPerSec = Double.POSITIVE_INFINITY;
+ double mbPerSec;
private long lastNS;
private long minPauseCheckBytes;
private boolean abort;
@@ -51,6 +50,9 @@ public class MergeRateLimiter extends RateLimiter {
/** Sole constructor. */
public MergeRateLimiter(MergePolicy.OneMerge merge) {
this.merge = merge;
+
+ // Initially no IO limit; use setter here so minPauseCheckBytes is set:
+ setMBPerSec(Double.POSITIVE_INFINITY);
}
@Override
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestMergeRateLimiter.java b/lucene/core/src/test/org/apache/lucene/index/TestMergeRateLimiter.java
new file mode 100644
index 00000000000..fa2f4b0b0d0
--- /dev/null
+++ b/lucene/core/src/test/org/apache/lucene/index/TestMergeRateLimiter.java
@@ -0,0 +1,38 @@
+package org.apache.lucene.index;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Collections;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestMergeRateLimiter extends LuceneTestCase {
+ public void testInitDefaults() throws Exception {
+ Directory dir = newDirectory();
+ RandomIndexWriter w = new RandomIndexWriter(random(), dir);
+ w.addDocument(new Document());
+ w.close();
+ MergePolicy.OneMerge merge = new MergePolicy.OneMerge(SegmentInfos.readLatestCommit(dir).asList());
+ MergeRateLimiter rateLimiter = new MergeRateLimiter(merge);
+ assertEquals(Double.POSITIVE_INFINITY, rateLimiter.getMBPerSec(), 0.0);
+ assertTrue(rateLimiter.getMinPauseCheckBytes() > 0);
+ dir.close();
+ }
+}