You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by tf...@apache.org on 2023/03/17 22:10:21 UTC
[solr] branch branch_9x updated: SOLR-16692: Let users set the CookieStore implementation in Http2SolrClient (#1445)
This is an automated email from the ASF dual-hosted git repository.
tflobbe 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 1ba732b6483 SOLR-16692: Let users set the CookieStore implementation in Http2SolrClient (#1445)
1ba732b6483 is described below
commit 1ba732b648312c6eb751d5bef261af9aa7d44b2b
Author: Tomas Eduardo Fernandez Lobbe <tf...@apache.org>
AuthorDate: Fri Mar 17 11:13:19 2023 -0700
SOLR-16692: Let users set the CookieStore implementation in Http2SolrClient (#1445)
---
solr/CHANGES.txt | 5 ++++
solr/bin/solr.in.sh | 6 ++++-
.../solr/client/solrj/impl/Http2SolrClient.java | 29 ++++++++++++++++++++++
.../src/java/org/apache/solr/SolrTestCaseJ4.java | 1 +
4 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index af56692b123..4f0cbbe4fb9 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -21,6 +21,11 @@ Optimizations
* SOLR-16694: Shortcut Http2SolrClient mimeType check for default response parse (Tomás Fernández Löbbe, Alex Deparvu)
+* SOLR-16692: Allow setting the a CookieStore implementation in Http2SolrClient. When Cookies are not needed, this can be set to
+ `org.eclipse.jetty.util.HttpCookieStore.Empty`, which avoids some of the processing that happens in the default `java.net.InMemoryCookieStore`.
+ Solr can also be started with the system property `solr.http.disableCookies` set to `true`, so that the internal clients
+ that Solr uses to communicate between nodes use `HttpCookieStore.Empty`. (Tomás Fernández Löbbe)
+
Other Changes
---------------------
diff --git a/solr/bin/solr.in.sh b/solr/bin/solr.in.sh
index 84d85981c69..9a87144a0bc 100644
--- a/solr/bin/solr.in.sh
+++ b/solr/bin/solr.in.sh
@@ -284,4 +284,8 @@
# Configure the default replica placement plugin to use if one is not configured in cluster properties
# See https://solr.apache.org/guide/solr/latest/configuration-guide/replica-placement-plugins.html for details
-#SOLR_PLACEMENTPLUGIN_DEFAULT=simple
\ No newline at end of file
+#SOLR_PLACEMENTPLUGIN_DEFAULT=simple
+
+# Solr internally doesn't use cookies other than for modules such as Kerberos/Hadoop Auth. If you don't need any of those
+# And you don't need them for an external system (such as a load balancer), you can disable the use of a CookieStore with:
+# SOLR_OPTS="$SOLR_OPTS -Dsolr.http.disableCookies=true"
\ No newline at end of file
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
index 7101c041949..1c2fe209ef0 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
@@ -27,6 +27,7 @@ import java.io.InputStream;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.InvocationTargetException;
import java.net.ConnectException;
+import java.net.CookieStore;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.ByteBuffer;
@@ -101,6 +102,7 @@ import org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2;
import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.Fields;
+import org.eclipse.jetty.util.HttpCookieStore;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -272,6 +274,10 @@ public class Http2SolrClient extends SolrClient {
httpClient.setUserAgentField(new HttpField(HttpHeader.USER_AGENT, AGENT));
httpClient.setIdleTimeout(idleTimeoutMillis);
+ if (builder.cookieStore != null) {
+ httpClient.setCookieStore(builder.cookieStore);
+ }
+
this.authenticationStore = new AuthenticationStoreHolder();
httpClient.setAuthenticationStore(this.authenticationStore);
@@ -1037,6 +1043,7 @@ public class Http2SolrClient extends SolrClient {
protected RequestWriter requestWriter;
protected ResponseParser responseParser;
private Set<String> urlParamNames = Set.of();
+ private CookieStore cookieStore = getDefaultCookieStore();
public Builder() {}
@@ -1080,6 +1087,17 @@ public class Http2SolrClient extends SolrClient {
}
}
+ private static CookieStore getDefaultCookieStore() {
+ if (Boolean.getBoolean("solr.http.disableCookies")) {
+ return new HttpCookieStore.Empty();
+ }
+ /*
+ * We could potentially have a Supplier<CookieStore> if we ever need further customization support,
+ * but for now it's only either Empty or default (in-memory).
+ */
+ return null;
+ }
+
/** Reuse {@code httpClient} connections pool */
public Builder withHttpClient(Http2SolrClient httpClient) {
this.http2SolrClient = httpClient;
@@ -1214,6 +1232,17 @@ public class Http2SolrClient extends SolrClient {
this.requestTimeoutMillis = TimeUnit.MILLISECONDS.convert(requestTimeout, unit);
return this;
}
+
+ /**
+ * Set a cookieStore other than the default ({@code java.net.InMemoryCookieStore})
+ *
+ * @param cookieStore The CookieStore to set. {@code null} will set the default.
+ * @return this Builder
+ */
+ public Builder withCookieStore(CookieStore cookieStore) {
+ this.cookieStore = cookieStore;
+ return this;
+ }
}
/**
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index b56ece570e9..c52297677a3 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -302,6 +302,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
System.setProperty("solr.clustering.enabled", "false");
System.setProperty("solr.cloud.wait-for-updates-with-stale-state-pause", "500");
System.setProperty("solr.filterCache.async", String.valueOf(random().nextBoolean()));
+ System.setProperty("solr.http.disableCookies", Boolean.toString(rarely()));
System.setProperty(ZK_WHITELIST_PROPERTY, "*");
startTrackingSearchers();