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:
Michael McCandless 2012-08-27 15:20:17 +00:00
parent 458fcb4446
commit 64549e4332
1 changed files with 11 additions and 9 deletions

View File

@ -468,15 +468,17 @@ public abstract class ShardSearchingTestBase extends LuceneTestCase {
// Get the current (fresh) searcher for this node
public ShardIndexSearcher acquire() {
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();
return s;
while(true) {
final ShardIndexSearcher s = currentShardSearcher;
// 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 {