Apache Lucene open-source search software
SOLR-2824: add fromSearcher open time to JoinQuery for caching
Yonik Seeleyca7df01ccf10
diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.javaindex 5940c42595d..59760fca001 100644--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java@@ -1006,11 +1006,23 @@ public final class SolrCore implements SolrInfoMBean {}/**- * Return the newest normal {@link RefCounted}<{@link SolrIndexSearcher}> with- * the reference count incremented. It <b>must</b> be decremented when no longer needed.- * If no searcher is currently open, then if openNew==true a new searcher will be opened,- * or null is returned if openNew==false.+ * Returns the current registered searcher with its reference count incremented, or null if none are registered.*/+ public RefCounted<SolrIndexSearcher> getRegisteredSearcher() {+ synchronized (searcherLock) {+ if (_searcher != null) {+ _searcher.incref();+ }+ return _searcher;+ }+ }++ /**+ * Return the newest normal {@link RefCounted}<{@link SolrIndexSearcher}> with+ * the reference count incremented. It <b>must</b> be decremented when no longer needed.+ * If no searcher is currently open, then if openNew==true a new searcher will be opened,+ * or null is returned if openNew==false.+ */public RefCounted<SolrIndexSearcher> getNewestSearcher(boolean openNew) {synchronized (searcherLock) {if (!_searchers.isEmpty()) {@@ -1023,7 +1035,6 @@ public final class SolrCore implements SolrInfoMBean {return openNew ? getRealtimeSearcher() : null;}-/** Gets the latest real-time searcher w/o forcing open a new searcher if one already exists.* The reference count will be incremented.*/diff --git a/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.javaindex 944ac2fed00..d687df91882 100644--- a/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java+++ b/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java@@ -59,11 +59,13 @@ public class JoinQParserPlugin extends QParserPlugin {String toField = getParam("to");String v = localParams.get("v");Query fromQuery;+ long fromCoreOpenTime = 0;- if (fromIndex != null) {+ if (fromIndex != null && !fromIndex.equals(req.getCore().getCoreDescriptor().getName()) ) {CoreContainer container = req.getCore().getCoreDescriptor().getCoreContainer();final SolrCore fromCore = container.getCore(fromIndex);+ RefCounted<SolrIndexSearcher> fromHolder = null;if (fromCore == null) {throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cross-core join: no such core " + fromIndex);@@ -73,9 +75,12 @@ public class JoinQParserPlugin extends QParserPlugin {try {QParser parser = QParser.getParser(v, "lucene", otherReq);fromQuery = parser.getQuery();+ fromHolder = fromCore.getRegisteredSearcher();+ if (fromHolder != null) fromCoreOpenTime = fromHolder.get().getOpenTime();} finally {otherReq.close();fromCore.close();+ if (fromHolder != null) fromHolder.decref();}} else {QParser fromQueryParser = subQuery(v, null);@@ -83,6 +88,7 @@ public class JoinQParserPlugin extends QParserPlugin {}JoinQuery jq = new JoinQuery(fromField, toField, fromIndex, fromQuery);+ jq.fromCoreOpenTime = fromCoreOpenTime;return jq;}};@@ -95,6 +101,7 @@ class JoinQuery extends Query {String toField;String fromIndex;Query q;+ long fromCoreOpenTime;public JoinQuery(String fromField, String toField, String fromIndex, Query subQuery) {this.fromField = fromField;@@ -548,12 +555,14 @@ class JoinQuery extends Query {&& this.toField.equals(other.toField)&& this.getBoost() == other.getBoost()&& this.q.equals(other.q)- && (this.fromIndex == other.fromIndex || this.fromIndex != null && this.fromIndex.equals(other.fromIndex));+ && (this.fromIndex == other.fromIndex || this.fromIndex != null && this.fromIndex.equals(other.fromIndex))+ && this.fromCoreOpenTime == other.fromCoreOpenTime+ ;}@Overridepublic int hashCode() {- int h = q.hashCode();+ int h = q.hashCode() + (int)fromCoreOpenTime;h = h * 31 + fromField.hashCode();h = h * 31 + toField.hashCode();return h;