Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-15762 Error on Join Query with sync cache

Mike Drob2d395989017c
diff --git a/solr/core/src/java/org/apache/solr/search/CaffeineCache.java b/solr/core/src/java/org/apache/solr/search/CaffeineCache.java
index 06d36b6d149..bf98a7efaad 100644
--- a/solr/core/src/java/org/apache/solr/search/CaffeineCache.java
+++ b/solr/core/src/java/org/apache/solr/search/CaffeineCache.java
@@ -418,6 +418,11 @@ public class CaffeineCache<K, V> extends SolrCacheBase implements SolrCache<K, V
limit, initialSize, isAutowarmingOn() ? (", " + getAutowarmDescription()) : "");
}
+ @Override
+ public boolean isRecursionSupported() {
+ return async;
+ }
+
//////////////////////// SolrInfoBean methods //////////////////////
@Override
diff --git a/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java
index 8a0a193bcbd..54f05b0897c 100644
--- a/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java
@@ -246,4 +246,4 @@ public class JoinQParserPlugin extends QParserPlugin {
}
}
-}
\ No newline at end of file
+}
diff --git a/solr/core/src/java/org/apache/solr/search/JoinQuery.java b/solr/core/src/java/org/apache/solr/search/JoinQuery.java
index 55b72cae52d..3a12f375db3 100644
--- a/solr/core/src/java/org/apache/solr/search/JoinQuery.java
+++ b/solr/core/src/java/org/apache/solr/search/JoinQuery.java
@@ -358,6 +358,11 @@ class JoinQuery extends Query {
// use the filterCache to get a DocSet
if (toTermsEnum.docFreq() >= minDocFreqTo || resultBits == null) {
// use filter cache
+ SolrCache<?, ?> filterCache = toSearcher.getFilterCache();
+ if (filterCache != null && !filterCache.isRecursionSupported()) {
+ throw new SolrException(SolrException.ErrorCode.INVALID_STATE,
+ "Using join queries with synchronous filterCache is not supported! Details can be found in Solr Reference Guide under 'query-settings-in-solrconfig'.");
+ }
DocSet toTermSet = toSearcher.getDocSet(toDeState);
resultListDocs += toTermSet.size();
if (resultBits != null) {
diff --git a/solr/core/src/java/org/apache/solr/search/SolrCache.java b/solr/core/src/java/org/apache/solr/search/SolrCache.java
index 999559ed321..67e375b8769 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrCache.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrCache.java
@@ -21,6 +21,7 @@ import org.apache.solr.util.IOFunction;
import java.io.IOException;
import java.util.Map;
+import java.util.function.Function;
/**
@@ -173,4 +174,14 @@ public interface SolrCache<K,V> extends SolrInfoBean {
* only on implementations that support it, it's a no-op otherwise.
*/
void setMaxRamMB(int maxRamMB);
+
+ /**
+ * Check if this SolrCache supports recursive calls to {@link #computeIfAbsent(Object, IOFunction)}.
+ * Caches backed by {@link java.util.concurrent.ConcurrentHashMap#computeIfAbsent(Object, Function)} explicitly do
+ * not support that, but other caches might.
+ * @return whether this cache allows recursive computations
+ */
+ default boolean isRecursionSupported() {
+ return false;
+ }
}
diff --git a/solr/core/src/test/org/apache/solr/search/join/InvalidConfigJoinQueryTest.java b/solr/core/src/test/org/apache/solr/search/join/InvalidConfigJoinQueryTest.java
new file mode 100644
index 00000000000..d8021f7404d
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/search/join/InvalidConfigJoinQueryTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search.join;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrInputDocument;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class InvalidConfigJoinQueryTest extends SolrTestCaseJ4 {
+
+ @BeforeClass
+ public static void before() throws Exception {
+ System.setProperty("solr.filterCache.async", "false");
+ initCore("solrconfig.xml", "schema.xml");
+ }
+
+ @Test
+ public void testInvalidFilterConfig() throws Exception {
+ UpdateRequest req = new UpdateRequest();
+ req.add(new SolrInputDocument("id", "0", "type_s", "org", "locid_s", "1"));
+ req.add(new SolrInputDocument("id", "1", "type_s", "loc", "orgid_s", "0"));
+
+ SolrClient client = new EmbeddedSolrServer(h.getCore());
+ req.commit(client, null);
+
+ assertThrows(SolrException.class, () -> assertJQ(req("q", "{!join from=id to=locid_s v=$q1}", "q1", "type_s:loc", "fl", "id", "sort", "id asc")));
+ }
+}