From 957814c276e069cb0d4dd0c0b03082fc2c372d9c Mon Sep 17 00:00:00 2001 From: Chatzipavlidisch Date: Mon, 8 Jun 2026 19:47:40 +0200 Subject: [PATCH] Refactor: solrj-streaming shouldn't call SolrClientCache.getHttpSolrClient. Reuse shared cloud http client engine --- .../solr/client/solrj/io/SolrClientCache.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java index 3503bdb90793..213f2d3c51dc 100644 --- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java +++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java @@ -31,6 +31,7 @@ import org.apache.solr.common.AlreadyClosedException; import org.apache.solr.common.util.IOUtils; import org.apache.solr.common.util.URLUtil; +import org.apache.solr.client.solrj.impl.CloudHttp2SolrClient; /** The SolrClientCache caches SolrClients, so they can be reused by different TupleStreams. */ public class SolrClientCache implements Closeable { @@ -136,7 +137,22 @@ public synchronized SolrClient getHttpSolrClient(String baseUrl) { ensureOpen(); Objects.requireNonNull(baseUrl, "Url cannot be null!"); return httpSolrClients.computeIfAbsent( - baseUrl, url -> newHttpSolrClientBuilder(url, httpSolrClient).build()); + baseUrl, + url -> { + // Find an existing Cloud Client connection + HttpSolrClient sharedEngine = this.httpSolrClient; + + if (sharedEngine == null && !cloudSolClients.isEmpty()) { + // Get first available active Cloud client connection + CloudSolrClient firstCloudClient = cloudSolClients.values().iterator().next(); + if (firstCloudClient instanceof CloudHttp2SolrClient) { + sharedEngine = ((CloudHttp2SolrClient) firstCloudClient).getHttpClient(); + } + } + + // Build the client using the shared engine if found one + return newHttpSolrClientBuilder(url, sharedEngine).build(); + }); } @SuppressWarnings({"unchecked", "rawtypes"})