Skip to content

Commit

Permalink
SOLR-17290: Update SyncStrategy and PeerSyncWithLeader to use the rec…
Browse files Browse the repository at this point in the history
…overy 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]>
  • Loading branch information
3 people authored May 24, 2024
1 parent 281c77c commit 2b28161
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ Other Changes

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

* SOLR-16503: Use Jetty HTTP2 for SyncStrategy and PeerSyncWithLeader for "recovery" operations (Sanjay Dutt, David Smiley)

================== 9.6.1 ==================
Bug Fixes
---------------------
Expand Down
14 changes: 6 additions & 8 deletions solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.http.client.HttpClient;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.client.solrj.request.CoreAdminRequest.RequestRecovery;
import org.apache.solr.common.cloud.ZkCoreNodeProps;
import org.apache.solr.common.cloud.ZkNodeProps;
Expand Down Expand Up @@ -55,7 +54,7 @@ public class SyncStrategy {

private volatile boolean isClosed;

private final HttpClient client;
private final Http2SolrClient solrClient;

private final ExecutorService updateExecutor;

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

public SyncStrategy(CoreContainer cc) {
UpdateShardHandler updateShardHandler = cc.getUpdateShardHandler();
client = updateShardHandler.getDefaultHttpClient();
solrClient = updateShardHandler.getRecoveryOnlyHttpClient();
shardHandler = cc.getShardHandlerFactory().getShardHandler();
updateExecutor = updateShardHandler.getUpdateExecutor();
}
Expand Down Expand Up @@ -361,12 +360,11 @@ private void requestRecovery(
RequestRecovery recoverRequestCmd = new RequestRecovery();
recoverRequestCmd.setAction(CoreAdminAction.REQUESTRECOVERY);
recoverRequestCmd.setCoreName(coreName);

try (SolrClient client =
new HttpSolrClient.Builder(baseUrl)
.withHttpClient(SyncStrategy.this.client)
new Http2SolrClient.Builder(baseUrl)
.withHttpClient(solrClient)
.withConnectionTimeout(30000, TimeUnit.MILLISECONDS)
.withSocketTimeout(120000, TimeUnit.MILLISECONDS)
.withIdleTimeout(120000, TimeUnit.MILLISECONDS)
.build()) {
client.request(recoverRequestCmd);
} catch (Throwable t) {
Expand Down
26 changes: 9 additions & 17 deletions solr/core/src/java/org/apache/solr/update/PeerSyncWithLeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.Set;
import org.apache.http.client.HttpClient;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.cloud.ZkController;
Expand All @@ -56,7 +54,9 @@ public class PeerSyncWithLeader implements SolrMetricProducer {

private UpdateHandler uhandler;
private UpdateLog ulog;
private SolrClient clientToLeader;
private final SolrClient clientToLeader;
private final String coreName;
private final String leaderBaseUrl;

private boolean doFingerprint;

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

final var leaderBaseUrl = URLUtil.extractBaseUrl(leaderUrl);
final var coreName = URLUtil.extractCoreFromCoreUrl(leaderUrl);
this.clientToLeader =
new HttpSolrClient.Builder(leaderBaseUrl)
.withDefaultCollection(coreName)
.withHttpClient(httpClient)
.build();
leaderBaseUrl = URLUtil.extractBaseUrl(leaderUrl);
coreName = URLUtil.extractCoreFromCoreUrl(leaderUrl);
clientToLeader = core.getCoreContainer().getUpdateShardHandler().getRecoveryOnlyHttpClient();

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

Expand Down Expand Up @@ -201,11 +196,6 @@ public PeerSync.PeerSyncResult sync(List<Long> startingVersions) {
if (timerContext != null) {
timerContext.close();
}
try {
clientToLeader.close();
} catch (IOException e) {
log.warn("{} unable to close client to leader", msg(), e);
}
}
}

Expand Down Expand Up @@ -343,7 +333,9 @@ private boolean handleUpdates(

private NamedList<Object> request(ModifiableSolrParams params, String onFail) {
try {
QueryResponse rsp = new QueryRequest(params, SolrRequest.METHOD.POST).process(clientToLeader);
QueryRequest request = new QueryRequest(params, SolrRequest.METHOD.POST);
request.setBasePath(leaderBaseUrl);
QueryResponse rsp = request.process(clientToLeader, coreName);
Exception exception = rsp.getException();
if (exception != null) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, onFail);
Expand Down

0 comments on commit 2b28161

Please sign in to comment.