mirror of https://github.com/apache/lucene.git
fix test thread safety issue
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1377711 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
458fcb4446
commit
64549e4332
|
@ -468,16 +468,18 @@ public abstract class ShardSearchingTestBase extends LuceneTestCase {
|
|||
|
||||
// Get the current (fresh) searcher for this node
|
||||
public ShardIndexSearcher acquire() {
|
||||
while(true) {
|
||||
final ShardIndexSearcher s = currentShardSearcher;
|
||||
// TODO: this isn't thread safe.... in theory the
|
||||
// reader could get decRef'd to 0 before we have a
|
||||
// chance to incRef, ie if a reopen happens right
|
||||
// after the above line, this thread gets stalled, and
|
||||
// the old IR is closed. But because we use SLM in
|
||||
// this test, this will be exceptionally rare:
|
||||
s.getIndexReader().incRef();
|
||||
// In theory the reader could get decRef'd to 0
|
||||
// before we have a chance to incRef, ie if a reopen
|
||||
// happens right after the above line, this thread
|
||||
// gets stalled, and the old IR is closed. So we
|
||||
// must try/retry until incRef succeeds:
|
||||
if (s.getIndexReader().tryIncRef()) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void release(ShardIndexSearcher s) throws IOException {
|
||||
s.getIndexReader().decRef();
|
||||
|
|
Loading…
Reference in New Issue