Apache Solr open-source search software
add slowcloser
Michael McCandlessbbbe0a62ef16
diff --git a/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java b/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.javaindex 4bc42b3a462..3f144a8cbba 100644--- a/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java+++ b/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java@@ -151,7 +151,7 @@ final class StandardDirectoryReader extends DirectoryReader {}boolean success = false;- IOException prior = null;+ Throwable prior = null;try {SegmentReader newReader;if (newReaders[i] == null || infos.info(i).info.getUseCompoundFile() != newReaders[i].getSegmentInfo().info.getUseCompoundFile()) {@@ -176,7 +176,7 @@ final class StandardDirectoryReader extends DirectoryReader {}}success = true;- } catch (IOException ex) {+ } catch (Throwable ex) {prior = ex;} finally {if (!success) {@@ -192,14 +192,19 @@ final class StandardDirectoryReader extends DirectoryReader {// closing we must decRef itnewReaders[i].decRef();}- } catch (IOException ex) {- if (prior == null) prior = ex;+ } catch (Throwable t) {+ if (prior == null) prior = t;}}}}// throw the first exception- if (prior != null) throw prior;+ if (prior != null) {+ if (prior instanceof IOException) throw (IOException) prior;+ if (prior instanceof RuntimeException) throw (RuntimeException) prior;+ if (prior instanceof Error) throw (Error) prior;+ throw new RuntimeException(prior);+ }}}return new StandardDirectoryReader(directory, newReaders, writer, infos, termInfosIndexDivisor, false);diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.javaindex a7402fee9bf..3dc5d253c2b 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java@@ -1025,7 +1025,6 @@ public class TestIndexWriter extends LuceneTestCase {}w.close();w = null;- _TestUtil.checkIndex(dir);DirectoryReader.open(dir).close();// Strangely, if we interrupt a thread beforediff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.javaindex e124423a29b..fcb66de5e32 100644--- a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java+++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java@@ -498,7 +498,14 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {throw fillOpenTrace(new IOException("MockDirectoryWrapper: file \"" + name + "\" is still open for writing"), name, false);}- IndexInput ii = new MockIndexInputWrapper(this, name, delegate.openInput(name, LuceneTestCase.newIOContext(randomState, context)));+ IndexInput delegateInput = delegate.openInput(name, LuceneTestCase.newIOContext(randomState, context));++ final IndexInput ii;+ if (randomState.nextInt(500) == 0) {+ ii = new SlowClosingMockIndexInputWrapper(this, name, delegateInput);+ } else {+ ii = new MockIndexInputWrapper(this, name, delegateInput);+ }addFileHandle(ii, name, Handle.Input);return ii;}diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/SlowClosingMockIndexInputWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/SlowClosingMockIndexInputWrapper.javanew file mode 100644index 00000000000..bc2e1da8571--- /dev/null+++ b/lucene/test-framework/src/java/org/apache/lucene/store/SlowClosingMockIndexInputWrapper.java@@ -0,0 +1,47 @@+package org.apache.lucene.store;++/*+ * 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.io.IOException;++import org.apache.lucene.util.ThreadInterruptedException;++/**+ * hangs onto files a little bit longer (50ms in close).+ * MockDirectoryWrapper acts like windows: you can't delete files+ * open elsewhere. so the idea is to make race conditions for tiny+ * files (like segments) easier to reproduce.+ */+class SlowClosingMockIndexInputWrapper extends MockIndexInputWrapper {++ public SlowClosingMockIndexInputWrapper(MockDirectoryWrapper dir,+ String name, IndexInput delegate) {+ super(dir, name, delegate);+ }++ @Override+ public void close() throws IOException {+ try {+ Thread.sleep(50);+ } catch (InterruptedException ie) {+ throw new ThreadInterruptedException(ie);+ } finally {+ super.close();+ }+ }+}