diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 7715efad0e2..03c97fd8767 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -210,6 +210,8 @@ Bug Fixes * SOLR-12874: Java 9+ GC Logging filesize parameter should use a unit. (Tim Underwood via Uwe Schindler) +* SOLR-12868: Request forwarding for v2 API is broken (noble) + Improvements ---------------------- diff --git a/solr/core/src/java/org/apache/solr/api/V2HttpCall.java b/solr/core/src/java/org/apache/solr/api/V2HttpCall.java index d2b891e1436..c318cb0115d 100644 --- a/solr/core/src/java/org/apache/solr/api/V2HttpCall.java +++ b/solr/core/src/java/org/apache/solr/api/V2HttpCall.java @@ -121,9 +121,10 @@ public class V2HttpCall extends HttpSolrCall { core = getCoreByCollection(collection.getName(), isPreferLeader); if (core == null) { //this collection exists , but this node does not have a replica for that collection - extractRemotePath(collection.getName(), origCorename); + extractRemotePath(collection.getName(), collection.getName()); if (action == REMOTEQUERY) { - this.path = path = path.substring(prefix.length() + origCorename.length() + 2); + coreUrl = coreUrl.replace("/solr/", "/solr/____v2/c/"); + this.path = path = path.substring(prefix.length() + collection.getName().length() + 2); return; } } diff --git a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java index 4a3c34f70f1..64dc3dd1dd7 100644 --- a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java +++ b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java @@ -133,7 +133,7 @@ import static org.apache.solr.servlet.SolrDispatchFilter.Action.RETURN; public class HttpSolrCall { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - static final Random random; + public static final Random random; static { // We try to make things reproducible in the context of our tests by initializing the random instance // based on the current seed @@ -877,7 +877,7 @@ public class HttpSolrCall { } } - private String getRemotCoreUrl(String collectionName, String origCorename) { + protected String getRemotCoreUrl(String collectionName, String origCorename) { ClusterState clusterState = cores.getZkController().getClusterState(); final DocCollection docCollection = clusterState.getCollectionOrNull(collectionName); Slice[] slices = (docCollection != null) ? docCollection.getActiveSlicesArr() : null; diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestV2Request.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestV2Request.java index 12b3271c887..4aa1b643815 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestV2Request.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestV2Request.java @@ -18,18 +18,25 @@ package org.apache.solr.client.solrj.request; import java.io.IOException; +import java.lang.invoke.MethodHandles; import java.util.List; 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.response.V2Response; import org.apache.solr.cloud.SolrCloudTestCase; +import org.apache.solr.common.cloud.ClusterState; import org.apache.solr.common.util.NamedList; import org.junit.BeforeClass; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class TestV2Request extends SolrCloudTestCase { + private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + @BeforeClass public static void setupCluster() throws Exception { @@ -99,4 +106,41 @@ public class TestV2Request extends SolrCloudTestCase { } + public void testV2Forwarding() throws Exception { + SolrClient client = cluster.getSolrClient(); + assertSuccess(client, new V2Request.Builder("/collections") + .withMethod(SolrRequest.METHOD.POST) + .withPayload("{" + + " 'create' : {" + + " 'name' : 'v2forward'," + + " 'numShards' : 1," + + " 'replicationFactor' : 1," + + " 'config' : 'config'" + + " }" + + "}").build()); + + ClusterState cs = cluster.getSolrClient().getClusterStateProvider().getClusterState(); + System.out.println("livenodes: " + cs.getLiveNodes()); + + String[] node = new String[1]; + cs.getCollection("v2forward").forEachReplica((s, replica) -> node[0] = replica.getNodeName()); + + //find a node that does not have a replica for this collection + final String[] testNode = new String[1]; + cs.getLiveNodes().forEach(s -> { + if (!s.equals(node[0])) testNode[0] = s; + }); + + String testServer = cluster.getSolrClient().getZkStateReader().getBaseUrlForNodeName(testNode[0]); + V2Request v2r = new V2Request.Builder("/c/v2forward/_introspect") + .withMethod(SolrRequest.METHOD.GET).build(); + + try(HttpSolrClient client1 = new HttpSolrClient.Builder() + .withBaseSolrUrl(testServer) + .build()) { + V2Response rsp = v2r.process(client1); + assertEquals("0",rsp._getStr("responseHeader/status", null)); + } + } + }