Skip to content

Apache Lucene open-source search software

maxWarmingSearchers: SOLR-91

Yonik Seeley6e43239634cf
diff --git a/CHANGES.txt b/CHANGES.txt
index 35243496bfe..1298bd52b0a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -42,6 +42,11 @@ New Features
* PatternReplaceFilter - applies a Pattern to each token in the
stream, replacing match occurances with a specified replacement.
(hossman)
+ 3. SOLR-91: allow configuration of a limit of the number of searchers
+ that can be warming in the background. This can be used to avoid
+ out-of-memory errors, or contention caused by more and more searchers
+ warming in the background. An error is thrown if the limit specified
+ by maxWarmingSearchers in solrconfig.xml is exceeded. (yonik)
Changes in runtime behavior
1. Highlighting using DisMax will only pick up terms from the main
diff --git a/example/solr/conf/solrconfig.xml b/example/solr/conf/solrconfig.xml
index b41581b6d57..18dfc0a6082 100755
--- a/example/solr/conf/solrconfig.xml
+++ b/example/solr/conf/solrconfig.xml
@@ -215,6 +215,11 @@
warming. -->
<useColdSearcher>false</useColdSearcher>
+ <!-- Maximum number of searchers that may be warming in the background
+ concurrently. An error is returned if this limit is exceeded. Recommend
+ 1-2 for read-only slaves, higher for masters w/o cache warming. -->
+ <maxWarmingSearchers>4</maxWarmingSearchers>
+
</query>
diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.java
index b8a3682c0ce..f9ca9df412b 100644
--- a/src/java/org/apache/solr/core/SolrCore.java
+++ b/src/java/org/apache/solr/core/SolrCore.java
@@ -182,7 +182,7 @@ public final class SolrCore {
core = this; // set singleton
if (dataDir ==null) {
- dataDir =SolrConfig.config.get("dataDir",Config.getInstanceDir()+"data");
+ dataDir = SolrConfig.config.get("dataDir",Config.getInstanceDir()+"data");
}
log.info("Opening new SolrCore at " + Config.getInstanceDir() + ", dataDir="+dataDir);
@@ -195,6 +195,8 @@ public final class SolrCore {
this.dataDir = dataDir;
this.index_path = dataDir + "/" + "index";
+ this.maxWarmingSearchers = SolrConfig.config.getInt("query/maxWarmingSearchers",Integer.MAX_VALUE);
+
parseListeners();
initIndex();
@@ -252,6 +254,7 @@ public final class SolrCore {
final ExecutorService searcherExecutor = Executors.newSingleThreadExecutor();
private int onDeckSearchers; // number of searchers preparing
private Object searcherLock = new Object(); // the sync object for the searcher
+ private final int maxWarmingSearchers; // max number of on-deck searchers allowed
public RefCounted<SolrIndexSearcher> getSearcher() {
@@ -337,20 +340,25 @@ public final class SolrCore {
// first: increment count to signal other threads that we are
// opening a new searcher.
onDeckSearchers++;
- }
-
- // open the index synchronously
- // if this fails, we need to decrement onDeckSearchers again.
- SolrIndexSearcher tmp;
- try {
if (onDeckSearchers < 1) {
// should never happen... just a sanity check
log.severe("ERROR!!! onDeckSearchers is " + onDeckSearchers);
- // reset to 1 (don't bother synchronizing)
- onDeckSearchers=1;
+ onDeckSearchers=1; // reset
+ } else if (onDeckSearchers > maxWarmingSearchers) {
+ onDeckSearchers--;
+ String msg="Error opening new searcher. exceeded limit of maxWarmingSearchers="+maxWarmingSearchers + ", try again later.";
+ log.warning(msg);
+ // HTTP 503==service unavailable, or 409==Conflict
+ throw new SolrException(503,msg,true);
} else if (onDeckSearchers > 1) {
log.info("PERFORMANCE WARNING: Overlapping onDeckSearchers=" + onDeckSearchers);
}
+ }
+
+ // open the index synchronously
+ // if this fails, we need to decrement onDeckSearchers again.
+ SolrIndexSearcher tmp;
+ try {
tmp = new SolrIndexSearcher(schema, "main", index_path, true);
} catch (Throwable th) {
synchronized(searcherLock) {