Skip to content

Commit 2b28161

Browse files
iamsanjaySanjay Duttdsmiley
authored
SOLR-17290: Update SyncStrategy and PeerSyncWithLeader to use the recovery Http2SolrClient (#2460)
* Both SyncStrategy and PeerSyncWithLeader now utilize the recovery Http2SolrClient supplied by UpdateShardHandler. * In PeerSyncWithLeader, the unnecessary re-creation of the client has been removed. --------- Co-authored-by: Sanjay Dutt <[email protected]> Co-authored-by: David Smiley <[email protected]>
1 parent 281c77c commit 2b28161

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

solr/CHANGES.txt

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ Other Changes
155155

156156
* GITHUB#2454: Refactor preparePutOrPost method in HttpJdkSolrClient (Andy Webb)
157157

158+
* SOLR-16503: Use Jetty HTTP2 for SyncStrategy and PeerSyncWithLeader for "recovery" operations (Sanjay Dutt, David Smiley)
159+
158160
================== 9.6.1 ==================
159161
Bug Fixes
160162
---------------------

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

+6-8
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
import java.util.List;
2525
import java.util.concurrent.ExecutorService;
2626
import java.util.concurrent.TimeUnit;
27-
import org.apache.http.client.HttpClient;
2827
import org.apache.solr.client.solrj.SolrClient;
2928
import org.apache.solr.client.solrj.SolrServerException;
30-
import org.apache.solr.client.solrj.impl.HttpSolrClient;
29+
import org.apache.solr.client.solrj.impl.Http2SolrClient;
3130
import org.apache.solr.client.solrj.request.CoreAdminRequest.RequestRecovery;
3231
import org.apache.solr.common.cloud.ZkCoreNodeProps;
3332
import org.apache.solr.common.cloud.ZkNodeProps;
@@ -55,7 +54,7 @@ public class SyncStrategy {
5554

5655
private volatile boolean isClosed;
5756

58-
private final HttpClient client;
57+
private final Http2SolrClient solrClient;
5958

6059
private final ExecutorService updateExecutor;
6160

@@ -69,7 +68,7 @@ private static class RecoveryRequest {
6968

7069
public SyncStrategy(CoreContainer cc) {
7170
UpdateShardHandler updateShardHandler = cc.getUpdateShardHandler();
72-
client = updateShardHandler.getDefaultHttpClient();
71+
solrClient = updateShardHandler.getRecoveryOnlyHttpClient();
7372
shardHandler = cc.getShardHandlerFactory().getShardHandler();
7473
updateExecutor = updateShardHandler.getUpdateExecutor();
7574
}
@@ -361,12 +360,11 @@ private void requestRecovery(
361360
RequestRecovery recoverRequestCmd = new RequestRecovery();
362361
recoverRequestCmd.setAction(CoreAdminAction.REQUESTRECOVERY);
363362
recoverRequestCmd.setCoreName(coreName);
364-
365363
try (SolrClient client =
366-
new HttpSolrClient.Builder(baseUrl)
367-
.withHttpClient(SyncStrategy.this.client)
364+
new Http2SolrClient.Builder(baseUrl)
365+
.withHttpClient(solrClient)
368366
.withConnectionTimeout(30000, TimeUnit.MILLISECONDS)
369-
.withSocketTimeout(120000, TimeUnit.MILLISECONDS)
367+
.withIdleTimeout(120000, TimeUnit.MILLISECONDS)
370368
.build()) {
371369
client.request(recoverRequestCmd);
372370
} catch (Throwable t) {

solr/core/src/java/org/apache/solr/update/PeerSyncWithLeader.java

+9-17
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@
2828
import java.lang.invoke.MethodHandles;
2929
import java.util.List;
3030
import java.util.Set;
31-
import org.apache.http.client.HttpClient;
3231
import org.apache.solr.client.solrj.SolrClient;
3332
import org.apache.solr.client.solrj.SolrRequest;
3433
import org.apache.solr.client.solrj.SolrServerException;
35-
import org.apache.solr.client.solrj.impl.HttpSolrClient;
3634
import org.apache.solr.client.solrj.request.QueryRequest;
3735
import org.apache.solr.client.solrj.response.QueryResponse;
3836
import org.apache.solr.cloud.ZkController;
@@ -56,7 +54,9 @@ public class PeerSyncWithLeader implements SolrMetricProducer {
5654

5755
private UpdateHandler uhandler;
5856
private UpdateLog ulog;
59-
private SolrClient clientToLeader;
57+
private final SolrClient clientToLeader;
58+
private final String coreName;
59+
private final String leaderBaseUrl;
6060

6161
private boolean doFingerprint;
6262

@@ -79,15 +79,10 @@ public PeerSyncWithLeader(SolrCore core, String leaderUrl, int nUpdates) {
7979
this.doFingerprint = !"true".equals(System.getProperty("solr.disableFingerprint"));
8080
this.uhandler = core.getUpdateHandler();
8181
this.ulog = uhandler.getUpdateLog();
82-
HttpClient httpClient = core.getCoreContainer().getUpdateShardHandler().getDefaultHttpClient();
8382

84-
final var leaderBaseUrl = URLUtil.extractBaseUrl(leaderUrl);
85-
final var coreName = URLUtil.extractCoreFromCoreUrl(leaderUrl);
86-
this.clientToLeader =
87-
new HttpSolrClient.Builder(leaderBaseUrl)
88-
.withDefaultCollection(coreName)
89-
.withHttpClient(httpClient)
90-
.build();
83+
leaderBaseUrl = URLUtil.extractBaseUrl(leaderUrl);
84+
coreName = URLUtil.extractCoreFromCoreUrl(leaderUrl);
85+
clientToLeader = core.getCoreContainer().getUpdateShardHandler().getRecoveryOnlyHttpClient();
9186

9287
this.updater = new PeerSync.Updater(msg(), core);
9388

@@ -201,11 +196,6 @@ public PeerSync.PeerSyncResult sync(List<Long> startingVersions) {
201196
if (timerContext != null) {
202197
timerContext.close();
203198
}
204-
try {
205-
clientToLeader.close();
206-
} catch (IOException e) {
207-
log.warn("{} unable to close client to leader", msg(), e);
208-
}
209199
}
210200
}
211201

@@ -343,7 +333,9 @@ private boolean handleUpdates(
343333

344334
private NamedList<Object> request(ModifiableSolrParams params, String onFail) {
345335
try {
346-
QueryResponse rsp = new QueryRequest(params, SolrRequest.METHOD.POST).process(clientToLeader);
336+
QueryRequest request = new QueryRequest(params, SolrRequest.METHOD.POST);
337+
request.setBasePath(leaderBaseUrl);
338+
QueryResponse rsp = request.process(clientToLeader, coreName);
347339
Exception exception = rsp.getException();
348340
if (exception != null) {
349341
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, onFail);

0 commit comments

Comments
 (0)