Skip to content

Commit 5d8a539

Browse files
authored
SOLR-17884: Don't depend on Apache HttpClient (#3792)
* ZkController. Unfortunately using longer connection timeout (30 not 8) but at least now we re-use an internal client; get listeners for observability & security. * SolrJ ConcurrentUpdateHttp2SolrClient (jetty). Used an inner class of a deprecated client. * solrj-streaming DatabaseMetaDataImpl
1 parent bb4682d commit 5d8a539

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

solr/core/src/java/org/apache/solr/cloud/ZkController.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
import org.apache.solr.client.solrj.cloud.SolrCloudManager;
6363
import org.apache.solr.client.solrj.impl.CloudHttp2SolrClient;
6464
import org.apache.solr.client.solrj.impl.CloudSolrClient;
65-
import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
65+
import org.apache.solr.client.solrj.impl.Http2SolrClient;
6666
import org.apache.solr.client.solrj.impl.SolrClientCloudManager;
6767
import org.apache.solr.client.solrj.impl.SolrZkClientTimeout;
6868
import org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider;
@@ -2306,12 +2306,13 @@ private ZkCoreNodeProps waitForLeaderToSeeDownState(
23062306
}
23072307

23082308
// short timeouts, we may be in a storm and this is just best effort, and maybe we should be
2309-
// the
2310-
// leader now
2309+
// the leader now
2310+
// TODO ideally want 8sec connection timeout but can't easily also share the client
2311+
// listeners
23112312
try (SolrClient client =
2312-
new Builder(leaderBaseUrl)
2313-
.withConnectionTimeout(8000, TimeUnit.MILLISECONDS)
2314-
.withSocketTimeout(30000, TimeUnit.MILLISECONDS)
2313+
new Http2SolrClient.Builder(leaderBaseUrl)
2314+
.withHttpClient(getCoreContainer().getDefaultHttpSolrClient())
2315+
.withIdleTimeout(30000, TimeUnit.MILLISECONDS)
23152316
.build()) {
23162317
WaitForState prepCmd = new WaitForState();
23172318
prepCmd.setCoreName(leaderCoreName);

solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/sql/DatabaseMetaDataImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.apache.solr.client.solrj.SolrQuery;
2929
import org.apache.solr.client.solrj.SolrServerException;
3030
import org.apache.solr.client.solrj.impl.CloudSolrClient;
31-
import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
31+
import org.apache.solr.client.solrj.impl.Http2SolrClient;
3232
import org.apache.solr.client.solrj.response.QueryResponse;
3333
import org.apache.solr.common.cloud.ClusterState;
3434
import org.apache.solr.common.util.SimpleOrderedMap;
@@ -124,7 +124,7 @@ public String getDatabaseProductVersion() throws SQLException {
124124
for (String node : liveNodes) {
125125
try {
126126
String nodeURL = Utils.getBaseUrlForNodeName(node, urlScheme);
127-
solrClient = new Builder(nodeURL).build();
127+
solrClient = new Http2SolrClient.Builder(nodeURL).build();
128128

129129
QueryResponse rsp = solrClient.query(sysQuery);
130130
return String.valueOf(

solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.apache.solr.client.solrj.SolrClient;
3333
import org.apache.solr.client.solrj.SolrRequest;
3434
import org.apache.solr.client.solrj.SolrServerException;
35-
import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient.Update;
3635
import org.apache.solr.client.solrj.request.UpdateRequest;
3736
import org.apache.solr.client.solrj.util.ClientUtils;
3837
import org.apache.solr.common.SolrException;
@@ -177,6 +176,9 @@ protected ConcurrentUpdateHttp2SolrClient(Builder builder) {
177176
// processedCount is now managed by StallDetection
178177
}
179178

179+
/** Class representing an UpdateRequest and an optional collection. */
180+
private record Update(UpdateRequest request, String collection) {}
181+
180182
/** Opens a connection and sends everything... */
181183
class Runner implements Runnable {
182184

@@ -237,16 +239,16 @@ void sendUpdateStream() throws Exception {
237239

238240
InputStreamResponseListener responseListener = null;
239241
try (Http2SolrClient.OutStream out =
240-
client.initOutStream(basePath, update.getRequest(), update.getCollection())) {
242+
client.initOutStream(basePath, update.request(), update.collection())) {
241243
Update upd = update;
242244
while (upd != null) {
243-
UpdateRequest req = upd.getRequest();
244-
if (!out.belongToThisStream(req, upd.getCollection())) {
245+
UpdateRequest req = upd.request();
246+
if (!out.belongToThisStream(req, upd.collection())) {
245247
// Request has different params or destination core/collection, return to queue
246248
queue.add(upd);
247249
break;
248250
}
249-
client.send(out, upd.getRequest(), upd.getCollection());
251+
client.send(out, upd.request(), upd.collection());
250252
out.flush();
251253

252254
notifyQueueAndRunnersIfEmptyQueue();

0 commit comments

Comments
 (0)