Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-6097: make abort/waitForMerges private

Michael McCandless0c28951031d0
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 82dda0d093b..782cdfeb51c 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -295,6 +295,10 @@ API Changes
won't be trappy if codec tries to use them during docvalues updates.
(Robert Muir)
+* LUCENE-6097: Remove dangerous / overly expert
+ IndexWriter.abortMerges and waitForMerges methods. (Robert Muir,
+ Mike McCandless)
+
Bug Fixes
* LUCENE-5650: Enforce read-only access to any path outside the temporary
diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CloseIndexTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CloseIndexTask.java
index 701908ec337..8bd1750ffc7 100644
--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CloseIndexTask.java
+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CloseIndexTask.java
@@ -46,9 +46,11 @@ public class CloseIndexTask extends PerfTask {
infoStream.close();
}
if (doWait == false) {
- iw.abortMerges();
+ iw.commit();
+ iw.rollback();
+ } else {
+ iw.close();
}
- iw.close();
getRunData().setIndexWriter(null);
}
return 1;
diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WaitForMergesTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WaitForMergesTask.java
deleted file mode 100644
index e74adbb47df..00000000000
--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WaitForMergesTask.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.apache.lucene.benchmark.byTask.tasks;
-/*
- * 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.HashMap;
-import java.util.Map;
-
-import org.apache.lucene.benchmark.byTask.PerfRunData;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexReader;
-
-/**
- * Waits for merges to finish.
- */
-public class WaitForMergesTask extends PerfTask {
-
- public WaitForMergesTask(PerfRunData runData) {
- super(runData);
- }
-
- @Override
- public int doLogic() throws Exception {
- getRunData().getIndexWriter().waitForMerges();
- return 1;
- }
-}
diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
index 61ed62a91d6..d89a6708962 100644
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
@@ -532,7 +532,6 @@ public class TestPerfTasksLogic extends BenchmarkTestCase {
"{ [ AddDoc]: 4} : * ",
"ResetInputs ",
"{ [ AddDoc]: 4} : * ",
- "WaitForMerges",
"CloseIndex",
};
@@ -568,7 +567,6 @@ public class TestPerfTasksLogic extends BenchmarkTestCase {
" ResetSystemErase",
" CreateIndex",
" { \"AddDocs\" AddDoc > : * ",
- " WaitForMerges",
" CloseIndex",
"} : 2",
};
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
index 48741b83346..11a52619464 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
@@ -1624,11 +1624,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
* newly created segments will not be merged unless you
* call forceMerge again.</p>
*
- * <p><b>NOTE</b>: if you call {@link #abortMerges}, which
- * aborts all running merges, then any thread still
- * running this method might hit a {@link
- * MergePolicy.MergeAbortedException}.
- *
* @param maxNumSegments maximum number of segments left
* in the index after merging finishes
*
@@ -1741,12 +1736,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
* specify whether the call should block until the
* operation completes. This is only meaningful with a
* {@link MergeScheduler} that is able to run merges in
- * background threads.
- *
- * <p><b>NOTE</b>: if you call {@link #abortMerges}, which
- * aborts all running merges, then any thread still
- * running this method might hit a {@link
- * MergePolicy.MergeAbortedException}. */
+ * background threads. */
public void forceMergeDeletes(boolean doWait)
throws IOException {
ensureOpen();
@@ -2154,7 +2144,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
/** Aborts running merges. Be careful when using this
* method: when you abort a long-running merge, you lose
* a lot of work that must later be redone. */
- public synchronized void abortMerges() {
+ private synchronized void abortMerges() {
stopMerges = true;
// Abort all pending & running merges:
@@ -2202,7 +2192,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
* <p>It is guaranteed that any merges started prior to calling this method
* will have completed once this method completes.</p>
*/
- public void waitForMerges() throws IOException {
+ void waitForMerges() throws IOException {
// Give merge scheduler last chance to run, in case
// any pending merges are waiting. We can't hold IW's lock
@@ -2495,11 +2485,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
* {@code maxMergeAtOnce} parameter, you should pass that many readers in one
* call.
*
- * <p>
- * <b>NOTE</b>: if you call {@link #abortMerges}, which
- * aborts all running merges, then any thread still running this method might
- * hit a {@link MergePolicy.MergeAbortedException}.
- *
* @throws CorruptIndexException
* if the index is corrupt
* @throws IOException
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java b/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java
index 5c517970617..1d3fb706730 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java
@@ -715,10 +715,10 @@ public class TestAddIndexes extends LuceneTestCase {
void close(boolean doWait) throws Throwable {
didClose = true;
if (doWait == false) {
- writer2.abortMerges();
+ writer2.rollback();
+ } else {
+ writer2.close();
}
- //writer2.close();
- writer2.rollback();
}
void closeDir() throws Throwable {
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java
index da088607fb0..bf8c28ca559 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java
@@ -435,16 +435,16 @@ public class TestIndexWriterReader extends LuceneTestCase {
void close(boolean doWait) throws Throwable {
didClose = true;
if (doWait) {
- mainWriter.waitForMerges();
+ mainWriter.close();
} else {
- mainWriter.abortMerges();
+ mainWriter.rollback();
}
- mainWriter.close();
}
void closeDir() throws Throwable {
- for (int i = 0; i < numDirs; i++)
+ for (int i = 0; i < numDirs; i++) {
readers[i].close();
+ }
addDir.close();
}
diff --git a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
index ae668871677..37da5409a2e 100644
--- a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
+++ b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
@@ -793,11 +793,7 @@ public class DirectUpdateHandler2 extends UpdateHandler implements SolrCoreState
}
if (writer != null) {
- try {
- if (indexWriterCloseWaitsForMerges) writer.waitForMerges();
- } finally {
- writer.close();
- }
+ writer.close();
}
} finally {