This is an automated email from the ASF dual-hosted git repository. dsmiley pushed a commit to branch branch_10x in repository https://gitbox.apache.org/repos/asf/solr.git
commit fbf197fead895a972caf8b55b2594c148167c566 Author: David Smiley <[email protected]> AuthorDate: Thu Nov 27 09:50:07 2025 -0500 SOLR-17996: SolrRequest.requestWithBaseUrl and on HttpSolrClientBase (#3881) New HttpSolrClientBase.requestWithBaseUrl (abstract, returns NamedList). Change Http2SolrClient.requestWithBaseUrl to implement it, return NamedList instead of SolrRequest generic return type. New SolrRequest.processWithBaseUrl that returns the SolrRequest response. --- .../unreleased/SOLR-17996-requestWithBaseUrl.yml | 8 ++++++++ .../java/org/apache/solr/bench/MiniClusterState.java | 15 +++++++-------- .../org/apache/solr/bench/index/CloudIndexing.java | 2 +- .../org/apache/solr/bench/search/FilterCache.java | 8 ++++---- .../org/apache/solr/bench/search/JsonFaceting.java | 5 +---- .../org/apache/solr/bench/search/NumericSearch.java | 4 ++-- .../api/collections/CollectionHandlingUtils.java | 2 +- .../cloud/api/collections/ReindexCollectionCmd.java | 5 ++--- .../src/java/org/apache/solr/core/CoreContainer.java | 5 +++-- .../org/apache/solr/filestore/DistribFileStore.java | 2 +- .../java/org/apache/solr/handler/IndexFetcher.java | 9 ++++----- .../org/apache/solr/handler/SolrConfigHandler.java | 4 +--- .../java/org/apache/solr/handler/admin/ColStatus.java | 2 +- .../handler/component/IterativeMergeStrategy.java | 2 +- .../org/apache/solr/schema/ManagedIndexSchema.java | 3 +-- .../apache/solr/security/PKIAuthenticationPlugin.java | 2 +- .../org/apache/solr/update/PeerSyncWithLeader.java | 2 +- .../org/apache/solr/update/SolrCmdDistributor.java | 2 +- .../update/processor/DistributedUpdateProcessor.java | 6 +----- .../handler/TestUserManagedReplicationWithAuth.java | 4 ++-- .../solrj/impl/SolrClientNodeStateProvider.java | 8 ++------ .../apache/solr/common/cloud/NodesSysPropsCacher.java | 4 +--- .../org/apache/solr/client/solrj/SolrRequest.java | 19 +++++++++++++++++++ .../solrj/impl/ConcurrentUpdateHttp2SolrClient.java | 9 ++++----- .../solr/client/solrj/impl/Http2SolrClient.java | 18 ++++-------------- .../solr/client/solrj/impl/HttpJdkSolrClient.java | 3 ++- .../solr/client/solrj/impl/HttpSolrClientBase.java | 15 +++++++++++++++ .../apache/solr/client/solrj/impl/LBSolrClient.java | 6 ++---- .../solr/client/solrj/impl/Http2SolrClientTest.java | 4 ++-- 29 files changed, 95 insertions(+), 83 deletions(-) diff --git a/changelog/unreleased/SOLR-17996-requestWithBaseUrl.yml b/changelog/unreleased/SOLR-17996-requestWithBaseUrl.yml new file mode 100644 index 00000000000..99c4c8c40e9 --- /dev/null +++ b/changelog/unreleased/SOLR-17996-requestWithBaseUrl.yml @@ -0,0 +1,8 @@ +# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc +title: New SolrJ SolrRequest.requestWithBaseUrl, new HttpSolrClientBase.requestWithBaseUrl +type: other # added, changed, fixed, deprecated, removed, dependency_update, security, other +authors: + - name: David Smiley +links: + - name: SOLR-17996 + url: https://issues.apache.org/jira/browse/SOLR-17996 diff --git a/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java b/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java index 2dfce895ddc..baf4ccedbfb 100755 --- a/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java +++ b/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java @@ -322,7 +322,7 @@ public class MiniClusterState { CollectionAdminRequest.Create request = CollectionAdminRequest.createCollection(collection, "conf", numShards, numReplicas); client.requestWithBaseUrl( - nodes.get(random.nextInt(cluster.getJettySolrRunners().size())), null, request); + nodes.get(random.nextInt(cluster.getJettySolrRunners().size())), request, null); cluster.waitForActiveCollection( collection, 15, TimeUnit.SECONDS, numShards, numShards * numReplicas); @@ -372,7 +372,7 @@ public class MiniClusterState { UpdateRequest commitRequest = new UpdateRequest(); final var url = nodes.get(random.nextInt(cluster.getJettySolrRunners().size())); commitRequest.setAction(UpdateRequest.ACTION.COMMIT, false, true); - client.requestWithBaseUrl(url, collection, commitRequest); + client.requestWithBaseUrl(url, commitRequest, collection); log("done committing data"); } else { cluster.waitForActiveCollection(collection, 15, TimeUnit.SECONDS); @@ -380,8 +380,7 @@ public class MiniClusterState { QueryRequest queryRequest = new QueryRequest(new SolrQuery("q", "*:*", "rows", "1")); final var url = nodes.get(random.nextInt(cluster.getJettySolrRunners().size())); - NamedList<Object> result = - client.requestWithBaseUrl(url, collection, queryRequest).getResponse(); + NamedList<Object> result = client.requestWithBaseUrl(url, queryRequest, collection); log("sanity check of single row query result: " + result); log(""); @@ -428,7 +427,7 @@ public class MiniClusterState { meter.mark(); try { - client.requestWithBaseUrl(url, collection, updateRequest); + client.requestWithBaseUrl(url, updateRequest, collection); } catch (Exception e) { throw new RuntimeException(e); } @@ -456,7 +455,7 @@ public class MiniClusterState { if (i % batchSize == 0) { UpdateRequest updateRequest = new UpdateRequest(); updateRequest.add(batch); - client.requestWithBaseUrl(nodes.get(0), collection, updateRequest); + client.requestWithBaseUrl(nodes.get(0), updateRequest, collection); meter.mark(batch.size()); batch.clear(); log(meter.getCount() + " docs at " + (long) meter.getMeanRate() + " doc/s"); @@ -465,7 +464,7 @@ public class MiniClusterState { if (!batch.isEmpty()) { UpdateRequest updateRequest = new UpdateRequest(); updateRequest.add(batch); - client.requestWithBaseUrl(nodes.get(0), collection, updateRequest); + client.requestWithBaseUrl(nodes.get(0), updateRequest, collection); meter.mark(batch.size()); batch = null; } @@ -503,7 +502,7 @@ public class MiniClusterState { UpdateRequest optimizeRequest = new UpdateRequest(); final var url = nodes.get(random.nextInt(cluster.getJettySolrRunners().size())); optimizeRequest.setAction(UpdateRequest.ACTION.OPTIMIZE, false, true, maxMergeSegments); - client.requestWithBaseUrl(url, collection, optimizeRequest); + client.requestWithBaseUrl(url, optimizeRequest, collection); } } diff --git a/solr/benchmark/src/java/org/apache/solr/bench/index/CloudIndexing.java b/solr/benchmark/src/java/org/apache/solr/bench/index/CloudIndexing.java index 0ee950e7231..5f6c6526690 100755 --- a/solr/benchmark/src/java/org/apache/solr/bench/index/CloudIndexing.java +++ b/solr/benchmark/src/java/org/apache/solr/bench/index/CloudIndexing.java @@ -130,6 +130,6 @@ public class CloudIndexing { updateRequest.add(state.getNextDoc()); final var url = miniClusterState.nodes.get(miniClusterState.getRandom().nextInt(state.nodeCount)); - return miniClusterState.client.requestWithBaseUrl(url, BenchState.COLLECTION, updateRequest); + return miniClusterState.client.requestWithBaseUrl(url, updateRequest, BenchState.COLLECTION); } } diff --git a/solr/benchmark/src/java/org/apache/solr/bench/search/FilterCache.java b/solr/benchmark/src/java/org/apache/solr/bench/search/FilterCache.java index 6b7f6bf4a4f..4b1bf9485e8 100644 --- a/solr/benchmark/src/java/org/apache/solr/bench/search/FilterCache.java +++ b/solr/benchmark/src/java/org/apache/solr/bench/search/FilterCache.java @@ -109,7 +109,7 @@ public class FilterCache { throws SolrServerException, IOException { // Reload the collection/core to drop existing caches CollectionAdminRequest.Reload reload = CollectionAdminRequest.reloadCollection(COLLECTION); - miniClusterState.client.requestWithBaseUrl(miniClusterState.nodes.get(0), null, reload); + miniClusterState.client.requestWithBaseUrl(miniClusterState.nodes.get(0), reload, null); } @TearDown(Level.Iteration) @@ -139,8 +139,8 @@ public class FilterCache { throws SolrServerException, IOException { return miniClusterState.client.requestWithBaseUrl( benchState.baseUrl, - COLLECTION, - miniClusterState.getRandom().nextBoolean() ? benchState.q1 : benchState.q2); + miniClusterState.getRandom().nextBoolean() ? benchState.q1 : benchState.q2, + COLLECTION); } @Benchmark @@ -148,6 +148,6 @@ public class FilterCache { BenchState benchState, MiniClusterState.MiniClusterBenchState miniClusterState) throws SolrServerException, IOException { return miniClusterState.client.requestWithBaseUrl( - benchState.baseUrl, COLLECTION, benchState.q1); + benchState.baseUrl, benchState.q1, COLLECTION); } } diff --git a/solr/benchmark/src/java/org/apache/solr/bench/search/JsonFaceting.java b/solr/benchmark/src/java/org/apache/solr/bench/search/JsonFaceting.java index f1b2e21f2ad..9482f8a588b 100755 --- a/solr/benchmark/src/java/org/apache/solr/bench/search/JsonFaceting.java +++ b/solr/benchmark/src/java/org/apache/solr/bench/search/JsonFaceting.java @@ -193,10 +193,7 @@ public class JsonFaceting { final var url = miniClusterState.nodes.get(threadState.random.nextInt(state.nodeCount)); QueryRequest queryRequest = new QueryRequest(state.params); NamedList<Object> result = - miniClusterState - .client - .requestWithBaseUrl(url, state.collection, queryRequest) - .getResponse(); + miniClusterState.client.requestWithBaseUrl(url, queryRequest, state.collection); // MiniClusterState.log("result: " + result); diff --git a/solr/benchmark/src/java/org/apache/solr/bench/search/NumericSearch.java b/solr/benchmark/src/java/org/apache/solr/bench/search/NumericSearch.java index 398d102ec7c..7717b005fb3 100644 --- a/solr/benchmark/src/java/org/apache/solr/bench/search/NumericSearch.java +++ b/solr/benchmark/src/java/org/apache/solr/bench/search/NumericSearch.java @@ -102,7 +102,7 @@ public class NumericSearch { q.setParam("facet.limit", String.valueOf(maxCardinality)); QueryRequest req = new QueryRequest(q); QueryResponse response = - miniClusterState.client.requestWithBaseUrl(basePath, COLLECTION, req); + req.processWithBaseUrl(miniClusterState.client, basePath, COLLECTION); Set<String> numbers = response.getFacetField("numbers_i_dv").getValues().stream() .map(FacetField.Count::getName) @@ -144,7 +144,7 @@ public class NumericSearch { throws SolrServerException, IOException { // Reload the collection/core to drop existing caches CollectionAdminRequest.Reload reload = CollectionAdminRequest.reloadCollection(COLLECTION); - miniClusterState.client.requestWithBaseUrl(miniClusterState.nodes.get(0), null, reload); + miniClusterState.client.requestWithBaseUrl(miniClusterState.nodes.get(0), reload, null); } public QueryRequest intSetQuery(boolean dvs) { diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/CollectionHandlingUtils.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/CollectionHandlingUtils.java index 806ad86ba04..22f3618d111 100644 --- a/solr/core/src/java/org/apache/solr/cloud/api/collections/CollectionHandlingUtils.java +++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/CollectionHandlingUtils.java @@ -248,7 +248,7 @@ public class CollectionHandlingUtils { throws SolrServerException, IOException { UpdateRequest ureq = new UpdateRequest(); ureq.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, true, true); - return solrClient.requestWithBaseUrl(baseUrl, coreName, ureq); + return ureq.processWithBaseUrl(solrClient, baseUrl, coreName); } public static String waitForCoreNodeName( diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/ReindexCollectionCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/ReindexCollectionCmd.java index 23a7f7a6553..8909841c936 100644 --- a/solr/core/src/java/org/apache/solr/cloud/api/collections/ReindexCollectionCmd.java +++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/ReindexCollectionCmd.java @@ -864,9 +864,8 @@ public class ReindexCollectionCmd implements CollApiCmds.CollectionApiCommand { new GenericSolrRequest( SolrRequest.METHOD.POST, "/stream", SolrRequest.SolrRequestType.ADMIN, solrParams) .setRequiresCollection(true); - final var solrResponse = - solrClient.requestWithBaseUrl(daemonReplica.getBaseUrl(), daemonReplica.getCoreName(), req); - return solrResponse.getResponse(); + return solrClient.requestWithBaseUrl( + daemonReplica.getBaseUrl(), req, daemonReplica.getCoreName()); } private void cleanup( diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java index f9c88031ab6..be631383c6b 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -70,6 +70,7 @@ import org.apache.solr.api.ContainerPluginsRegistry; import org.apache.solr.api.JerseyResource; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.impl.Http2SolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClientBase; import org.apache.solr.client.solrj.io.SolrClientCache; import org.apache.solr.client.solrj.util.SolrIdentifierValidator; import org.apache.solr.cloud.CloudDescriptor; @@ -703,7 +704,7 @@ public class CoreContainer { * * @see #getDefaultHttpSolrClient() * @see ZkController#getSolrClient() - * @see Http2SolrClient#requestWithBaseUrl(String, String, SolrRequest) + * @see HttpSolrClientBase#requestWithBaseUrl(String, SolrRequest, String) * @deprecated likely to simply be moved to the ObjectCache so as to not be used */ @Deprecated @@ -2389,7 +2390,7 @@ public class CoreContainer { * <p>The caller does not need to close the client. * * @return the existing {@link Http2SolrClient} - * @see Http2SolrClient#requestWithBaseUrl(String, String, SolrRequest) + * @see HttpSolrClientBase#requestWithBaseUrl(String, SolrRequest, String) */ public Http2SolrClient getDefaultHttpSolrClient() { return solrClientProvider.getSolrClient(); diff --git a/solr/core/src/java/org/apache/solr/filestore/DistribFileStore.java b/solr/core/src/java/org/apache/solr/filestore/DistribFileStore.java index 94177f65180..797b1f584e5 100644 --- a/solr/core/src/java/org/apache/solr/filestore/DistribFileStore.java +++ b/solr/core/src/java/org/apache/solr/filestore/DistribFileStore.java @@ -205,7 +205,7 @@ public class DistribFileStore implements FileStore { ByteBuffer filedata = null; try { final var fileRequest = new FileStoreApi.GetFile(path); - final var fileResponse = solrClient.requestWithBaseUrl(baseUrl, null, fileRequest); + final var fileResponse = fileRequest.processWithBaseUrl(solrClient, baseUrl, null); try (final var stream = fileResponse.getResponseStreamIfSuccessful()) { filedata = Utils.newBytesConsumer((int) MAX_PKG_SIZE).accept(stream); } diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java index 7eb563d1629..430fad38971 100644 --- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java +++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java @@ -358,7 +358,7 @@ public class IndexFetcher { params.set(CommonParams.WT, JAVABIN); var req = createReplicationHandlerRequest(params); try { - return solrClient.requestWithBaseUrl(leaderBaseUrl, leaderCoreName, req).getResponse(); + return solrClient.requestWithBaseUrl(leaderBaseUrl, req, leaderCoreName); } catch (SolrServerException e) { throw new SolrException(ErrorCode.SERVER_ERROR, e.getMessage(), e); } @@ -376,8 +376,7 @@ public class IndexFetcher { params.set(CommonParams.WT, JAVABIN); var req = createReplicationHandlerRequest(params); try { - NamedList<?> response = - solrClient.requestWithBaseUrl(leaderBaseUrl, leaderCoreName, req).getResponse(); + NamedList<?> response = solrClient.requestWithBaseUrl(leaderBaseUrl, req, leaderCoreName); List<Map<String, Object>> files = (List<Map<String, Object>>) response.get(CMD_GET_FILE_LIST); if (files != null) filesToDownload = Collections.synchronizedList(files); @@ -1907,7 +1906,7 @@ public class IndexFetcher { var req = createReplicationHandlerRequest(params); req.setResponseParser(new InputStreamResponseParser(FILE_STREAM)); if (useExternalCompression) req.addHeader("Accept-Encoding", "gzip"); - response = solrClient.requestWithBaseUrl(leaderBaseUrl, leaderCoreName, req).getResponse(); + response = solrClient.requestWithBaseUrl(leaderBaseUrl, req, leaderCoreName); final var responseStatus = (Integer) response.get("responseStatus"); is = (InputStream) response.get("stream"); @@ -2050,7 +2049,7 @@ public class IndexFetcher { params.set("follower", false); var request = createReplicationHandlerRequest(params); - return solrClient.requestWithBaseUrl(leaderBaseUrl, leaderCoreName, request).getResponse(); + return solrClient.requestWithBaseUrl(leaderBaseUrl, request, leaderCoreName); } public void destroy() { diff --git a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java b/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java index e1f9e030232..b22626f3339 100644 --- a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java @@ -1006,9 +1006,7 @@ public class SolrConfigHandler extends RequestHandlerBase Thread.sleep(100); NamedList<Object> resp = - solrClient - .requestWithBaseUrl(replica.getBaseUrl(), replica.getCoreName(), this) - .getResponse(); + solrClient.requestWithBaseUrl(replica.getBaseUrl(), this, replica.getCoreName()); if (resp != null) { @SuppressWarnings({"rawtypes"}) Map m = (Map) resp.get(ZNODEVER); diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ColStatus.java b/solr/core/src/java/org/apache/solr/handler/admin/ColStatus.java index 0ef42781ddf..efca9d39fa5 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/ColStatus.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/ColStatus.java @@ -206,7 +206,7 @@ public class ColStatus { SolrRequest.SolrRequestType.ADMIN, params) .setRequiresCollection(true); - NamedList<Object> rsp = solrClient.requestWithBaseUrl(url, null, req).getResponse(); + NamedList<Object> rsp = solrClient.requestWithBaseUrl(url, req, null); final var segmentResponse = SolrJacksonMapper.getObjectMapper().convertValue(rsp, GetSegmentDataResponse.class); segmentResponse.responseHeader = null; diff --git a/solr/core/src/java/org/apache/solr/handler/component/IterativeMergeStrategy.java b/solr/core/src/java/org/apache/solr/handler/component/IterativeMergeStrategy.java index 7fb538315ff..31f1d95ed0f 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/IterativeMergeStrategy.java +++ b/solr/core/src/java/org/apache/solr/handler/component/IterativeMergeStrategy.java @@ -104,7 +104,7 @@ public abstract class IterativeMergeStrategy implements MergeStrategy { @Override public CallBack call() throws Exception { - response = httpSolrClient.requestWithBaseUrl(shardBaseUrl, shardCoreName, req); + response = req.processWithBaseUrl(httpSolrClient, shardBaseUrl, shardCoreName); return this; } } diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java index 671aafe0555..75c2f9c9a93 100644 --- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java +++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java @@ -381,8 +381,7 @@ public final class ManagedIndexSchema extends IndexSchema { zkController .getCoreContainer() .getDefaultHttpSolrClient() - .requestWithBaseUrl(baseUrl, coreName, this) - .getResponse(); + .requestWithBaseUrl(baseUrl, this, coreName); if (zkversionResp != null) remoteVersion = (Integer) zkversionResp.get("zkversion"); if (remoteVersion < expectedZkVersion) { diff --git a/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java b/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java index 44251bb324d..baec6f23e3b 100644 --- a/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java +++ b/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java @@ -383,7 +383,7 @@ public class PKIAuthenticationPlugin extends AuthenticationPlugin final var request = new GenericSolrRequest(GET, PublicKeyHandler.PATH, solrParams); log.debug("Fetching fresh public key from: {}", url); var solrClient = cores.getDefaultHttpSolrClient(); - NamedList<Object> resp = solrClient.requestWithBaseUrl(url, request::process).getResponse(); + NamedList<Object> resp = solrClient.requestWithBaseUrl(url, request, null); String key = (String) resp.get("key"); if (key == null) { diff --git a/solr/core/src/java/org/apache/solr/update/PeerSyncWithLeader.java b/solr/core/src/java/org/apache/solr/update/PeerSyncWithLeader.java index 49027b1665c..b6dc8e14fdf 100644 --- a/solr/core/src/java/org/apache/solr/update/PeerSyncWithLeader.java +++ b/solr/core/src/java/org/apache/solr/update/PeerSyncWithLeader.java @@ -354,7 +354,7 @@ public class PeerSyncWithLeader implements SolrMetricProducer { new GenericSolrRequest( SolrRequest.METHOD.GET, "/get", SolrRequest.SolrRequestType.QUERY, params) .setRequiresCollection(true); - var rsp = clientToLeader.requestWithBaseUrl(leaderBaseUrl, coreName, request); + var rsp = request.processWithBaseUrl(clientToLeader, leaderBaseUrl, coreName); Exception exception = rsp.getException(); if (exception != null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, onFail); diff --git a/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java b/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java index 02b88932154..5046d9ed876 100644 --- a/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java +++ b/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java @@ -316,7 +316,7 @@ public class SolrCmdDistributor implements Closeable { try { clients .getHttpClient() - .requestWithBaseUrl(req.node.getBaseUrl(), req.node.getCoreName(), req.uReq); + .requestWithBaseUrl(req.node.getBaseUrl(), req.uReq, req.node.getCoreName()); } catch (Exception e) { log.error("Exception making request", e); SolrError error = new SolrError(); diff --git a/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java b/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java index 0dc45a046c9..82424a5f06a 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java +++ b/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java @@ -692,11 +692,7 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor { NamedList<Object> rsp; try { - rsp = - updateShardHandler - .getUpdateOnlyHttpClient() - .requestWithBaseUrl(leaderUrl, null, ur) - .getResponse(); + rsp = updateShardHandler.getUpdateOnlyHttpClient().requestWithBaseUrl(leaderUrl, ur, null); } catch (SolrServerException e) { throw new SolrException( ErrorCode.SERVER_ERROR, diff --git a/solr/core/src/test/org/apache/solr/handler/TestUserManagedReplicationWithAuth.java b/solr/core/src/test/org/apache/solr/handler/TestUserManagedReplicationWithAuth.java index ccd150a740b..af7d03fec4c 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestUserManagedReplicationWithAuth.java +++ b/solr/core/src/test/org/apache/solr/handler/TestUserManagedReplicationWithAuth.java @@ -236,7 +236,7 @@ public class TestUserManagedReplicationWithAuth extends SolrTestCaseJ4 { withBasicAuth(req); final var baseUrl = buildUrl(Jetty.getLocalPort()); - solrClient.requestWithBaseUrl(baseUrl, DEFAULT_TEST_CORENAME, req); + solrClient.requestWithBaseUrl(baseUrl, req, DEFAULT_TEST_CORENAME); } private void pullIndexFromTo( @@ -245,7 +245,7 @@ public class TestUserManagedReplicationWithAuth extends SolrTestCaseJ4 { String srcUrl = buildUrl(srcSolr.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME; QueryRequest req = getQueryRequestForFetchIndex(authEnabled, srcUrl); final var baseUrl = buildUrl(destSolr.getLocalPort()); - followerClient.requestWithBaseUrl(baseUrl, DEFAULT_TEST_CORENAME, req); + followerClient.requestWithBaseUrl(baseUrl, req, DEFAULT_TEST_CORENAME); } private QueryRequest getQueryRequestForFetchIndex(boolean authEnabled, String srcUrl) { diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java b/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java index 7e21f30daf1..da494738281 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java @@ -220,10 +220,7 @@ public class SolrClientNodeStateProvider implements NodeStateProvider, MapWriter try (InputStream in = (InputStream) - ctx.http2SolrClient() - .requestWithBaseUrl(baseUrl, req::process) - .getResponse() - .get(STREAM_KEY)) { + ctx.http2SolrClient().requestWithBaseUrl(baseUrl, req, null).get(STREAM_KEY)) { NodeValueFetcher.Metrics.prometheusMetricStream(in).forEach(lineProcessor); } catch (Exception e) { @@ -322,8 +319,7 @@ public class SolrClientNodeStateProvider implements NodeStateProvider, MapWriter request.setResponseParser(new JavaBinResponseParser()); try { - return ((Http2SolrClient) cloudSolrClient.getHttpClient()) - .requestWithBaseUrl(url, request::process); + return request.processWithBaseUrl(cloudSolrClient.getHttpClient(), url, null); } catch (SolrServerException | IOException e) { throw new SolrException(ErrorCode.SERVER_ERROR, "Fetching replica metrics failed", e); } diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/NodesSysPropsCacher.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/NodesSysPropsCacher.java index c3b679546ec..f8773b6e213 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/NodesSysPropsCacher.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/NodesSysPropsCacher.java @@ -83,9 +83,7 @@ public class NodesSysPropsCacher implements NodesSysProps, AutoCloseable { try { LinkedHashMap<String, Object> result = new LinkedHashMap<>(); NavigableObject response = - solrClient - .requestWithBaseUrl(zkStateReader.getBaseUrlForNodeName(nodeName), null, req) - .getResponse(); + solrClient.requestWithBaseUrl(zkStateReader.getBaseUrlForNodeName(nodeName), req, null); var metrics = NavigableObject.wrap(response._get("system.properties")); tags.forEach((tag) -> result.put(tag, metrics._get(tag))); return result; diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java index 72ccc3e2987..b3a4eee893e 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClientBase; import org.apache.solr.client.solrj.request.RequestWriter; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.ContentStream; @@ -291,6 +292,24 @@ public abstract class SolrRequest<T> implements Serializable { return typedResponse; } + /** + * @lucene.experimental + */ + public final T processWithBaseUrl(HttpSolrClientBase client, String url, String collection) + throws SolrServerException, IOException { + // duplicative with process(), except for requestWithBaseUrl + long startNanos = System.nanoTime(); + var namedList = client.requestWithBaseUrl(url, this, collection); + long endNanos = System.nanoTime(); + T typedResponse = createResponse(namedList); + // SolrResponse is pre-V2 API + if (typedResponse instanceof SolrResponse res) { + res.setResponse(namedList); // TODO insist createResponse does this ? + res.setElapsedTime(TimeUnit.NANOSECONDS.toMillis(endNanos - startNanos)); + } + return typedResponse; + } + /** * Send this request to a {@link SolrClient} and return the response * diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java index 91f57fe55cc..0b9684f6b5b 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java @@ -374,7 +374,7 @@ public class ConcurrentUpdateHttp2SolrClient extends SolrClient { ? defaultCollection : collection; if (!(request instanceof UpdateRequest req)) { - return client.requestWithBaseUrl(basePath, (c) -> c.request(request, effectiveCollection)); + return client.requestWithBaseUrl(basePath, request, effectiveCollection); } // this happens for commit... if (streamDeletes) { @@ -383,14 +383,13 @@ public class ConcurrentUpdateHttp2SolrClient extends SolrClient { && (req.getDeleteByIdMap() == null || req.getDeleteByIdMap().isEmpty())) { if (req.getDeleteQuery() == null) { blockUntilFinished(); - return client.requestWithBaseUrl( - basePath, (c) -> c.request(request, effectiveCollection)); + return client.requestWithBaseUrl(basePath, request, effectiveCollection); } } } else { if ((req.getDocuments() == null || req.getDocuments().isEmpty())) { blockUntilFinished(); - return client.requestWithBaseUrl(basePath, (c) -> c.request(request, effectiveCollection)); + return client.requestWithBaseUrl(basePath, request, effectiveCollection); } } @@ -400,7 +399,7 @@ public class ConcurrentUpdateHttp2SolrClient extends SolrClient { if (params.getBool(UpdateParams.WAIT_SEARCHER, false)) { log.info("blocking for commit/optimize"); blockUntilFinished(); // empty the queue - return client.requestWithBaseUrl(basePath, (c) -> c.request(request, effectiveCollection)); + return client.requestWithBaseUrl(basePath, request, effectiveCollection); } } 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 a7b777cbc54..83b24671bbe 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 @@ -44,7 +44,6 @@ import org.apache.solr.client.solrj.ResponseParser; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrClientFunction; import org.apache.solr.client.solrj.SolrRequest; -import org.apache.solr.client.solrj.SolrResponse; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.embedded.SSLConfig; import org.apache.solr.client.solrj.impl.HttpListenerFactory.RequestResponseListener; @@ -613,20 +612,11 @@ public class Http2SolrClient extends HttpSolrClientBase { } } - /** - * Executes a SolrRequest using the provided URL to temporarily override any "base URL" currently - * used by this client - * - * @param baseUrl a URL to a root Solr path (i.e. "/solr") that should be used for this request - * @param collection an optional collection or core name used to override the client's "default - * collection". May be 'null' for any requests that don't require a collection or wish to rely - * on the client's default - * @param req the SolrRequest to send - */ - public final <R extends SolrResponse> R requestWithBaseUrl( - String baseUrl, String collection, SolrRequest<R> req) + @Override + public NamedList<Object> requestWithBaseUrl( + String baseUrl, SolrRequest<?> solrRequest, String collection) throws SolrServerException, IOException { - return requestWithBaseUrl(baseUrl, (c) -> req.process(c, collection)); + return requestWithBaseUrl(baseUrl, c -> c.request(solrRequest, collection)); } /** diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java index 5f3fa63fe15..d65a8fb9681 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java @@ -165,7 +165,8 @@ public class HttpJdkSolrClient extends HttpSolrClientBase { } } - protected NamedList<Object> requestWithBaseUrl( + @Override + public NamedList<Object> requestWithBaseUrl( String baseUrl, SolrRequest<?> solrRequest, String collection) throws SolrServerException, IOException { PreparedRequest pReq = prepareRequest(solrRequest, collection, baseUrl); diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClientBase.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClientBase.java index 92cc3b79caf..0fa2936cbfc 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClientBase.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClientBase.java @@ -340,6 +340,21 @@ public abstract class HttpSolrClientBase extends SolrClient { protected abstract void updateDefaultMimeTypeForParser(); + /** + * Executes a SolrRequest using the provided URL to temporarily override any "base URL" currently + * used by this client + * + * @param baseUrl a URL to a root Solr path (i.e. "/solr") that should be used for this request + * @param solrRequest the SolrRequest to send + * @param collection an optional collection or core name used to override the client's "default + * collection". May be 'null' for any requests that don't require a collection or wish to rely + * on the client's default + * @see SolrRequest#processWithBaseUrl(HttpSolrClientBase, String, String) + */ + public abstract NamedList<Object> requestWithBaseUrl( + String baseUrl, SolrRequest<?> solrRequest, String collection) + throws SolrServerException, IOException; + /** * Execute an asynchronous request against a Solr server for a given collection. * diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBSolrClient.java index b2560bc7eae..c71d0210bec 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBSolrClient.java @@ -506,10 +506,8 @@ public abstract class LBSolrClient extends SolrClient { // Some implementations of LBSolrClient.getClient(...) return a Http2SolrClient that may not be // pointed at the desired URL (or any URL for that matter). We special case that here to ensure // the appropriate URL is provided. - if (solrClient instanceof Http2SolrClient httpSolrClient) { - return httpSolrClient.requestWithBaseUrl(baseUrl, (c) -> c.request(solrRequest, collection)); - } else if (solrClient instanceof HttpJdkSolrClient) { - return ((HttpJdkSolrClient) solrClient).requestWithBaseUrl(baseUrl, solrRequest, collection); + if (solrClient instanceof HttpSolrClientBase hasReqWithUrl) { + return hasReqWithUrl.requestWithBaseUrl(baseUrl, solrRequest, collection); } // Assume provided client already uses 'baseUrl' diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java index b05da93f3f3..a56f1bab1b0 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java @@ -138,7 +138,7 @@ public class Http2SolrClientTest extends HttpSolrClientTestBase { try (Http2SolrClient client = new Http2SolrClient.Builder(null).build()) { try { // if client base url is null, request url will be used in exception message - client.requestWithBaseUrl(getBaseUrl() + DEBUG_SERVLET_PATH, DEFAULT_CORE, new SolrPing()); + client.requestWithBaseUrl(getBaseUrl() + DEBUG_SERVLET_PATH, new SolrPing(), DEFAULT_CORE); fail("Didn't get excepted exception from oversided request"); } catch (SolrException e) { @@ -231,7 +231,7 @@ public class Http2SolrClientTest extends HttpSolrClientTestBase { try (Http2SolrClient client = new Http2SolrClient.Builder(defaultUrl).withDefaultCollection(DEFAULT_CORE).build()) { try { - client.requestWithBaseUrl(urlToUse, null, new QueryRequest(queryParams)); + client.requestWithBaseUrl(urlToUse, new QueryRequest(queryParams), null); } catch (SolrClient.RemoteSolrException rse) { }
