add slowcloser

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/slowclosing@1393533 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-10-03 15:18:00 +00:00
parent d15303d9d6
commit bbbe0a62ef
4 changed files with 65 additions and 7 deletions

View File

@ -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 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);

View File

@ -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 before

View File

@ -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;
}

View File

@ -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();
}
}
}