Skip to content

Commit

Permalink
SOLR-17066: Switch Http2SolrClient away from coreURLs (apache#2255)
Browse files Browse the repository at this point in the history
Providing a core URL as a SolrClient's "base URL" prevents it from
communicating with other cores or making core-agnostic API requests
(e.g. node healthcheck, list cores, etc.)

This commit migrates all Http2SolrClient usage away from core URLs.
  • Loading branch information
gerlowskija authored Feb 13, 2024
1 parent a88305d commit bdf0b2f
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 40 deletions.
10 changes: 9 additions & 1 deletion solr/core/src/java/org/apache/solr/cli/PostLogsTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.SolrInputField;
import org.apache.solr.common.util.URLUtil;
import org.apache.solr.handler.component.ShardRequest;

/** A command line tool for indexing Solr logs in the out-of-the-box log format. */
Expand Down Expand Up @@ -89,9 +90,16 @@ public void runImpl(CommandLine cli) throws Exception {
}

public void runCommand(String baseUrl, String root, String credentials) throws IOException {
if (URLUtil.isBaseUrl(baseUrl)) {
throw new IllegalArgumentException(
"'url' parameter ["
+ baseUrl
+ "] must point to a particular collection but appears to be a Solr base URL");
}

Http2SolrClient.Builder builder =
new Http2SolrClient.Builder(baseUrl)
new Http2SolrClient.Builder(URLUtil.extractBaseUrl(baseUrl))
.withDefaultCollection(URLUtil.extractCoreFromCoreUrl(baseUrl))
.withKeyStoreReloadInterval(-1, TimeUnit.SECONDS)
.withOptionalBasicAuthCredentials(credentials);
try (SolrClient client = builder.build()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ public void testBackupRestore() throws Exception {

try (SolrClient adminClient =
getHttpSolrClient(cluster.getJettySolrRunners().get(0).getBaseUrl().toString());
SolrClient leaderClient = new Http2SolrClient.Builder(replica.getCoreUrl()).build()) {
SolrClient leaderClient =
new Http2SolrClient.Builder(replica.getBaseUrl())
.withDefaultCollection(replica.getCoreName())
.build()) {

SnapshotMetaData metaData = createSnapshot(adminClient, coreName, commitName);
// Create another snapshot referring to the same index commit to verify the
Expand Down Expand Up @@ -200,7 +203,10 @@ public void testIndexOptimization() throws Exception {

try (SolrClient adminClient =
getHttpSolrClient(cluster.getJettySolrRunners().get(0).getBaseUrl().toString());
SolrClient leaderClient = new Http2SolrClient.Builder(replica.getCoreUrl()).build()) {
SolrClient leaderClient =
new Http2SolrClient.Builder(replica.getBaseUrl())
.withDefaultCollection(replica.getCoreName())
.build()) {

SnapshotMetaData metaData = createSnapshot(adminClient, coreName, commitName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public void onFailure(Throwable throwable) {
new SolrNamedThreadFactory("httpShardExecutor"),
false);
try (Http2SolrClient client =
new Http2SolrClient.Builder(getBaseUrl() + collection)
new Http2SolrClient.Builder(getBaseUrl())
.withDefaultCollection(collection)
.withExecutor(commExecutor)
.build()) {
MDC.put(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public static void beforeTest() throws Exception {

@Override
public SolrClient createNewSolrClient() {
return new Http2SolrClient.Builder(getCoreUrl())
return new Http2SolrClient.Builder(getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.withRequestWriter(new BinaryRequestWriter())
// where the magic happens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public static void beforeTest() throws Exception {
public SolrClient createNewSolrClient() {

Http2SolrClient client =
new Http2SolrClient.Builder(getCoreUrl())
new Http2SolrClient.Builder(getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.withRequestWriter(new RequestWriter())
.withResponseParser(new XMLResponseParser())
Expand Down
Loading

0 comments on commit bdf0b2f

Please sign in to comment.