You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "dsmiley (via GitHub)" <gi...@apache.org> on 2026/09/22 20:56:31 UTC

[PR] SOLR-18474: Internal solr client cache [solr]

dsmiley opened a new pull request, #4934:
URL: https://github.com/apache/solr/pull/4934

   https://issues.apache.org/jira/browse/SOLR-18474
   
   # Description
   
   `SolrClientCache` is a SolrJ class meant for client use, yet Solr uses it server-side for streaming expressions, `/export`, `/graph`, `/sql` and the cross-collection join. Inside Solr its ownership was diffuse: `CoreContainer` held one, and several streams quietly created their own when their `StreamContext` had none. Those instances differ in configuration and none of them knows which cluster is the local one.
   
   # Solution
   
   Add `InternalSolrClientCache` (in `org.apache.solr.cloud`), the only `SolrClientCache` permitted inside a Solr server:
   
   * `ZkController` owns it and closes it. `CoreContainer` no longer holds one. `StreamHandler`, `ExportHandler`, `GraphHandler` and `CrossCollectionJoinQuery` get it from there.
   * The local cluster's `CloudSolrClient` is created once, reusing the node's HTTP client and its ZooKeeper ACLs. Connections to any other cluster get a separate client and must be permitted by `allowZkHosts` (ZooKeeper) or `allowUrls` (HTTP), via `ZkController.validateSolrConnection`. This replaces the all-or-nothing `solr.cloud.external.enabled` flag from the earlier revision of this branch.
   * Constructing a plain `SolrClientCache` on a Solr server thread now fails fast, so future server-side code uses the internal one. Client JVMs, including SolrJ applications and `bin/solr stream --execution local`, are unaffected.
   * Fallouts of that guard, each its own commit: `CloudSolrStream` now creates one cache on the calling thread and shares it with the `SolrStream`s it opens on pool threads, rather than each opening its own; and the Solr JDBC driver can accept a supplied cache.
   * Cross-collection join now requires SolrCloud. Its `zkHost`/`solrConnection` forms build a `CloudSolrClient`, which standalone should not do; its `solrUrl` form could work locally, but the remote end has to be SolrCloud anyway, and nothing tested it. A note to the dev list asks whether anyone relies on standalone reaching a cluster this way.
   
   Developed with AI assistance (Claude Code): merge-conflict resolution against `main`, the validation wiring, and the `CloudSolrStream` cache sharing, all reviewed by me.
   
   # Checklist
   
   - [x] I have reviewed the guidelines for [How to Contribute](https://github.com/apache/solr/blob/main/CONTRIBUTING.md) and my code conforms to the standards described there to the best of my ability.
   - [x] I have created a Jira issue and added the issue ID to my pull request title.
   - [x] I have developed this patch against the `main` branch.
   - [ ] I have run `./gradlew check`.
   - [x] I have added tests for my changes.
   - [x] I have added documentation for the [Reference Guide](https://github.com/apache/solr/tree/main/solr/solr-ref-guide)
   - [x] I have added a [changelog entry](https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc) for my change
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] SOLR-18474: InternalSolrClientCache separate from SolrClientCache [solr]

Posted by "sigram (via GitHub)" <gi...@apache.org>.
sigram commented on code in PR #4934:
URL: https://github.com/apache/solr/pull/4934#discussion_r4092315624


##########
solr/core/src/java/org/apache/solr/cloud/ZkController.java:
##########
@@ -1022,6 +1044,35 @@ public AllowListZkHostChecker getAllowListZkHostChecker() {
     return allowListZkHostChecker;
   }
 
+  /**
+   * Validates a connection to a SolrCloud cluster: ZooKeeper via {@link
+   * #getAllowListZkHostChecker()}, HTTP via {@link AllowListUrlChecker} (live nodes of this cluster
+   * are allowed).
+   *
+   * @throws SolrException FORBIDDEN if not allowed
+   */
+  public void validateSolrConnection(CloudSolrClient.CloudSolrClientConnection solrConnection) {
+    if (solrConnection.isZookeeper()) {
+      String zkHost = solrConnection.toString();
+      if (!allowListZkHostChecker.isAllowed(zkHost)) {

Review Comment:
   It's awkward that the two checkers behave differently for the same "check urls" operation... `AllowListZkHostChecker.isAllowed` returns a boolean and then you have to make it into an exception and remember to use the same error code, while `AllowListUrlChecker.checkAllowList` simply throws an exception for you, with the right code.



##########
solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQuery.java:
##########
@@ -244,22 +243,20 @@ private TupleStream createCloudSolrStream(SolrClientCache solrClientCache) throw
       params.set(CommonParams.WT, CommonParams.JAVABIN);
 
       StreamContext streamContext = new StreamContext();
-      streamContext.setSolrClientCache(solrClientCache);
+      streamContext.setSolrClientCache(zkController.getSolrClientCache());

Review Comment:
   Previously the check for zkController != null prevented NPE just when building the transformer. There's no check here so if it's null we will get an NPE both here and in the transformer construction below.



##########
solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java:
##########
@@ -39,74 +37,44 @@ public class SolrClientCache implements Closeable {
   // Set the floor for timeouts to 60 seconds.
   // Timeouts can be increased by setting the system properties defined below.
   private static final int MIN_TIMEOUT = 60000;
-  private static final int minConnTimeout =
+  protected static final int minConnTimeout =
       Math.max(
           Integer.getInteger(SolrHttpConstants.PROP_CONNECTION_TIMEOUT, MIN_TIMEOUT), MIN_TIMEOUT);
-  private static final int minSocketTimeout =
+  protected static final int minSocketTimeout =
       Math.max(Integer.getInteger(SolrHttpConstants.PROP_SO_TIMEOUT, MIN_TIMEOUT), MIN_TIMEOUT);
 
-  protected String basicAuthCredentials = null; // Only support with the httpJettySolrClient
+  /** The only permitted subclass when running inside a Solr server (solr.solr.home is set). */
+  protected static final String INTERNAL_IMPL_CLASS =

Review Comment:
   I'm not sure I like depending on such magic strings ... why not add a `boolean isInternal()` to each implementation?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] SOLR-18474: InternalSolrClientCache separate from SolrClientCache [solr]

Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley merged PR #4934:
URL: https://github.com/apache/solr/pull/4934


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] SOLR-18474: InternalSolrClientCache separate from SolrClientCache [solr]

Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on PR #4934:
URL: https://github.com/apache/solr/pull/4934#issuecomment-5817149801

   Planning to merge tonight.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org