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 // Get the current (fresh) searcher for this node
public ShardIndexSearcher acquire() { public ShardIndexSearcher acquire() {
final ShardIndexSearcher s = currentShardSearcher; while(true) {
// TODO: this isn't thread safe.... in theory the final ShardIndexSearcher s = currentShardSearcher;
// reader could get decRef'd to 0 before we have a // In theory the reader could get decRef'd to 0
// chance to incRef, ie if a reopen happens right // before we have a chance to incRef, ie if a reopen
// after the above line, this thread gets stalled, and // happens right after the above line, this thread
// the old IR is closed. But because we use SLM in // gets stalled, and the old IR is closed. So we
// this test, this will be exceptionally rare: // must try/retry until incRef succeeds:
s.getIndexReader().incRef(); if (s.getIndexReader().tryIncRef()) {
return s; return s;
}
}
} }
public void release(ShardIndexSearcher s) throws IOException { public void release(ShardIndexSearcher s) throws IOException {