This is an automated email from the ASF dual-hosted git repository.
mlbiscoc pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new a9655f7bdcf SOLR-18176: HttpShardHandler query throughput bottleneck
from ZooKeeper (#4237)
a9655f7bdcf is described below
commit a9655f7bdcf62708f292c87ec7bfdb565084a14d
Author: Matthew Biscocho <[email protected]>
AuthorDate: Thu Apr 9 15:31:05 2026 -0400
SOLR-18176: HttpShardHandler query throughput bottleneck from ZooKeeper
(#4237)
CloudReplicaSource was making a clusterstate call to ZooKeeper for every
distributed request if you search over multiple collections, and when the
coordinator has no local replica for some of them. This is because the get call
was bypassing state cache. This created a severe bottleneck in query throughput
so small fix made to just enable cached state lookups.
---
.../SOLR-18176-shardhandler-bottleneck.yml | 9 +++
.../solr/handler/component/CloudReplicaSource.java | 20 +++---
.../DistributedQueryComponentOptimizationTest.java | 73 ++++++++++++++++++++++
3 files changed, 95 insertions(+), 7 deletions(-)
diff --git a/changelog/unreleased/SOLR-18176-shardhandler-bottleneck.yml
b/changelog/unreleased/SOLR-18176-shardhandler-bottleneck.yml
new file mode 100644
index 00000000000..7ce9084e0ca
--- /dev/null
+++ b/changelog/unreleased/SOLR-18176-shardhandler-bottleneck.yml
@@ -0,0 +1,9 @@
+title: Increased query throughput by removing a call to ZooKeeper for cluster
state that should have been cached. Happens when Solr does distributed search
over multiple collections, and when the coordinator has no local replica for
some of them.
+type: changed
+authors:
+ - name: Matthew Biscocho
+links:
+ - name: SOLR-18176
+ url: https://issues.apache.org/jira/browse/SOLR-18176
+ - name: SOLR-15352
+ url: https://issues.apache.org/jira/browse/SOLR-15352
diff --git
a/solr/core/src/java/org/apache/solr/handler/component/CloudReplicaSource.java
b/solr/core/src/java/org/apache/solr/handler/component/CloudReplicaSource.java
index 5e333c8e6d3..e340821743c 100644
---
a/solr/core/src/java/org/apache/solr/handler/component/CloudReplicaSource.java
+++
b/solr/core/src/java/org/apache/solr/handler/component/CloudReplicaSource.java
@@ -109,12 +109,13 @@ class CloudReplicaSource implements ReplicaSource {
if (sliceOrUrl.indexOf('/') < 0) {
// this is a logical shard
this.slices[i] = sliceOrUrl;
- replicas[i] =
- findReplicas(
- builder,
- shardsParam,
- clusterState,
-
clusterState.getCollection(builder.collection).getSlice(sliceOrUrl));
+ DocCollection coll =
clusterState.getCollectionOrNull(builder.collection, true);
+ if (coll == null) {
+ throw new SolrException(
+ SolrException.ErrorCode.BAD_REQUEST,
+ "Could not find collection to resolve replicas: " +
builder.collection);
+ }
+ replicas[i] = findReplicas(builder, shardsParam, clusterState,
coll.getSlice(sliceOrUrl));
} else {
// this has urls
this.replicas[i] = StrUtils.splitSmart(sliceOrUrl, "|", true);
@@ -189,7 +190,12 @@ class CloudReplicaSource implements ReplicaSource {
String collectionName,
String shardKeys,
boolean multiCollection) {
- DocCollection coll = state.getCollection(collectionName);
+ DocCollection coll = state.getCollectionOrNull(collectionName, true);
+ if (coll == null) {
+ throw new SolrException(
+ SolrException.ErrorCode.BAD_REQUEST,
+ "Could not find collection to add slices: " + collectionName);
+ }
Collection<Slice> slices = coll.getRouter().getSearchSlices(shardKeys,
params, coll);
ClientUtils.addSlices(target, collectionName, slices, multiCollection);
}
diff --git
a/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryComponentOptimizationTest.java
b/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryComponentOptimizationTest.java
index 8df32f40837..7b65c88caac 100644
---
a/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryComponentOptimizationTest.java
+++
b/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryComponentOptimizationTest.java
@@ -24,16 +24,23 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.solr.BaseDistributedSearchTestCase;
+import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.cloud.SolrCloudTestCase;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.ShardParams;
+import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.StrUtils;
+import org.apache.solr.embedded.JettySolrRunner;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -708,6 +715,72 @@ public class DistributedQueryComponentOptimizationTest
extends SolrCloudTestCase
return response;
}
+ /**
+ * When a node resolves collection state for a collection it doesn't host,
queries should use
+ * cached state and not make ZK calls on every query.
+ */
+ @Test
+ public void testDistributedQueryDoesNotReadFromZk() throws Exception {
+ final String secondColl = "secondColl";
+
+ // Create a collection on only 1 node so the other node uses
LazyCollectionRef for state
+ List<JettySolrRunner> jettys = cluster.getJettySolrRunners();
+ CollectionAdminRequest.createCollection(secondColl, "conf", 1, 1)
+ .setCreateNodeSet(jettys.get(0).getNodeName())
+ .processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);
+ cluster
+ .getZkStateReader()
+ .waitForState(
+ secondColl,
+ DEFAULT_TIMEOUT,
+ TimeUnit.SECONDS,
+ (n, c) -> DocCollection.isFullyActive(n, c, 1, 1));
+
+ try {
+ // Node 1 hosts COLLECTION but not secondColl.
+ // Send a multi-collection query to trigger LazyCollectionRef get call
+ JettySolrRunner nodeWithoutSecondColl = jettys.get(1);
+ try (SolrClient client =
+ new
Http2SolrClient.Builder(nodeWithoutSecondColl.getBaseUrl().toString()).build())
{
+
+ String collectionsParameter = COLLECTION + "," + secondColl;
+
+ // Warm up LazyCollectionRef state cache with query
+ client.query(COLLECTION, new SolrQuery("q", "*:*", "collection",
collectionsParameter));
+
+ // Get ZK metrics from the coordinator node (the one we're querying)
+ long existsBefore = getZkExistsChecks(client);
+
+ // Query again and assert that exists call is not made
+ client.query(COLLECTION, new SolrQuery("q", "*:*", "collection",
collectionsParameter));
+
+ long existsAfter = getZkExistsChecks(client);
+
+ assertEquals(
+ "Query should not cause ZK exists checks as collection state
should be cached",
+ existsBefore,
+ existsAfter);
+ }
+ } finally {
+ CollectionAdminRequest.deleteCollection(secondColl)
+ .processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private long getZkExistsChecks(SolrClient client) throws Exception {
+ NamedList<Object> response =
+ client.request(
+ new GenericSolrRequest(
+ SolrRequest.METHOD.GET,
+ "/admin/metrics",
+ new MapSolrParams(Map.of("key",
"solr.node:CONTAINER.zkClient"))));
+ NamedList<Object> metrics = (NamedList<Object>) response.get("metrics");
+ Map<String, Object> zkMetrics =
+ (Map<String, Object>) metrics.get("solr.node:CONTAINER.zkClient");
+ return ((Number) zkMetrics.get("existsChecks")).longValue();
+ }
+
private int getNumRequests(
Map<String, List<TrackingShardHandlerFactory.ShardRequestAndParams>>
requests) {
int beforeNumRequests = 0;