SOLR-3392: fix search leak when openSearcher=false

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1328890 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2012-04-22 15:01:55 +00:00
parent d5d8fef91e
commit ab0099f652
2 changed files with 31 additions and 1 deletions

View File

@ -440,7 +440,8 @@ public class DirectUpdateHandler2 extends UpdateHandler implements SolrCoreState
core.getSearcher(true, false, waitSearcher);
} else {
// force open a new realtime searcher so realtime-get and versioning code can see the latest
core.openNewSearcher(true,true);
RefCounted<SolrIndexSearcher> searchHolder = core.openNewSearcher(true, true);
searchHolder.decref();
}
if (ulog != null) ulog.postSoftCommit(cmd);
}

View File

@ -129,4 +129,33 @@ public class TestIndexSearcher extends SolrTestCaseJ4 {
sr5.close();
sr6.close();
}
// make sure we don't leak searchers (SOLR-3391)
public void testCloses() {
assertU(adoc("id","1"));
assertU(commit("openSearcher","false")); // this was enough to trigger SOLR-3391
int maxDoc = random().nextInt(20) + 1;
// test different combinations of commits
for (int i=0; i<100; i++) {
if (random().nextInt(100) < 50) {
String id = Integer.toString(random().nextInt(maxDoc));
assertU(adoc("id",id));
} else {
boolean soft = random().nextBoolean();
boolean optimize = random().nextBoolean();
boolean openSearcher = random().nextBoolean();
if (optimize) {
assertU(optimize("openSearcher",""+openSearcher, "softCommit",""+soft));
} else {
assertU(commit("openSearcher",""+openSearcher, "softCommit",""+soft));
}
}
}
}
}