SOLR-12868: Request forwarding for v2 API is broken

This commit is contained in:
Noble Paul 2018-10-26 12:50:45 +11:00
parent 8d10939349
commit f33be7a172
4 changed files with 51 additions and 4 deletions

View File

@ -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
----------------------

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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));
}
}
}