From 6e43239634cf7683fa43e5c8d86b77bb4b2c8347 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Fri, 12 Jan 2007 22:00:08 +0000 Subject: [PATCH] maxWarmingSearchers: SOLR-91 git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@495753 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 5 ++++ example/solr/conf/solrconfig.xml | 5 ++++ src/java/org/apache/solr/core/SolrCore.java | 26 ++++++++++++++------- 3 files changed, 27 insertions(+), 9 deletions(-) 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. --> false + + 4 + 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 getSearcher() { @@ -337,20 +340,25 @@ public final class SolrCore { // first: increment count to signal other threads that we are // opening a new searcher. onDeckSearchers++; + if (onDeckSearchers < 1) { + // should never happen... just a sanity check + log.severe("ERROR!!! onDeckSearchers is " + onDeckSearchers); + 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 { - 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; - } else if (onDeckSearchers > 1) { - log.info("PERFORMANCE WARNING: Overlapping onDeckSearchers=" + onDeckSearchers); - } tmp = new SolrIndexSearcher(schema, "main", index_path, true); } catch (Throwable th) { synchronized(searcherLock) {