You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2012/10/03 17:18:01 UTC
svn commit: r1393533 - in /lucene/dev/branches/slowclosing/lucene:
core/src/java/org/apache/lucene/index/ core/src/test/org/apache/lucene/index/
test-framework/src/java/org/apache/lucene/store/
Author: mikemccand
Date: Wed Oct 3 15:18:00 2012
New Revision: 1393533
URL: http://svn.apache.org/viewvc?rev=1393533&view=rev
Log:
add slowcloser
Added:
lucene/dev/branches/slowclosing/lucene/test-framework/src/java/org/apache/lucene/store/SlowClosingMockIndexInputWrapper.java (with props)
Modified:
lucene/dev/branches/slowclosing/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java
lucene/dev/branches/slowclosing/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
lucene/dev/branches/slowclosing/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
Modified: lucene/dev/branches/slowclosing/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/slowclosing/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java?rev=1393533&r1=1393532&r2=1393533&view=diff
==============================================================================
--- lucene/dev/branches/slowclosing/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java (original)
+++ lucene/dev/branches/slowclosing/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java Wed Oct 3 15:18:00 2012
@@ -151,7 +151,7 @@ final class StandardDirectoryReader exte
}
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 exte
}
}
success = true;
- } catch (IOException ex) {
+ } catch (Throwable ex) {
prior = ex;
} finally {
if (!success) {
@@ -192,14 +192,19 @@ final class StandardDirectoryReader exte
// closing we must decRef it
newReaders[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);
Modified: lucene/dev/branches/slowclosing/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/slowclosing/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=1393533&r1=1393532&r2=1393533&view=diff
==============================================================================
--- lucene/dev/branches/slowclosing/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/dev/branches/slowclosing/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java Wed Oct 3 15:18:00 2012
@@ -1025,7 +1025,6 @@ public class TestIndexWriter extends Luc
}
w.close();
w = null;
- _TestUtil.checkIndex(dir);
DirectoryReader.open(dir).close();
// Strangely, if we interrupt a thread before
Modified: lucene/dev/branches/slowclosing/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/slowclosing/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java?rev=1393533&r1=1393532&r2=1393533&view=diff
==============================================================================
--- lucene/dev/branches/slowclosing/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java (original)
+++ lucene/dev/branches/slowclosing/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java Wed Oct 3 15:18:00 2012
@@ -498,7 +498,14 @@ public class MockDirectoryWrapper extend
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;
}
Added: lucene/dev/branches/slowclosing/lucene/test-framework/src/java/org/apache/lucene/store/SlowClosingMockIndexInputWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/slowclosing/lucene/test-framework/src/java/org/apache/lucene/store/SlowClosingMockIndexInputWrapper.java?rev=1393533&view=auto
==============================================================================
--- lucene/dev/branches/slowclosing/lucene/test-framework/src/java/org/apache/lucene/store/SlowClosingMockIndexInputWrapper.java (added)
+++ lucene/dev/branches/slowclosing/lucene/test-framework/src/java/org/apache/lucene/store/SlowClosingMockIndexInputWrapper.java Wed Oct 3 15:18:00 2012
@@ -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();
+ }
+ }
+}