You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2021/02/10 23:52:45 UTC

[lucene-solr] 01/03: @1340 We only proxy to other nodes by collection, not core.

This is an automated email from the ASF dual-hosted git repository.

markrmiller pushed a commit to branch reference_impl_dev
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 59fe24c387a0e02bfafa22abacc918ea3f48f646
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Wed Feb 10 11:05:36 2021 -0600

    @1340 We only proxy to other nodes by collection, not core.
---
 .../src/java/org/apache/solr/api/V2HttpCall.java   | 38 ++++++++++++----------
 .../java/org/apache/solr/servlet/HttpSolrCall.java | 29 +++++------------
 2 files changed, 28 insertions(+), 39 deletions(-)

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 c6dd47d..9bf0369 100644
--- a/solr/core/src/java/org/apache/solr/api/V2HttpCall.java
+++ b/solr/core/src/java/org/apache/solr/api/V2HttpCall.java
@@ -67,7 +67,6 @@ public class V2HttpCall extends HttpSolrCall {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
   private Api api;
   List<String> pieces;
-  private String prefix;
   HashMap<String, String> parts = new HashMap<>();
   static final Set<String> knownPrefixes = ImmutableSet.of("cluster", "node", "collections", "cores", "c");
 
@@ -81,14 +80,9 @@ public class V2HttpCall extends HttpSolrCall {
     final String fullPath = path = path.substring(7);//strip off '/____v2'
     try {
       pieces = getPathSegments(path);
+      String prefix;
       if (pieces.size() == 0 || (pieces.size() == 1 && path.endsWith(CommonParams.INTROSPECT))) {
-        api = new Api(null) {
-          @Override
-          public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
-            rsp.add("documentation", "https://lucene.apache.org/solr/guide/v2-api.html");
-            rsp.add("description", "V2 API root path");
-          }
-        };
+        api = new MyApi();
         initAdminRequest(path);
         return;
       } else {
@@ -122,12 +116,9 @@ public class V2HttpCall extends HttpSolrCall {
           if (core == null) {
             //this collection exists , but this node does not have a replica for that collection
             if (log.isDebugEnabled()) log.debug("check remote path extraction {} {}", collection.getName(), origCorename);
-//            if (origCorename != null) {
-//              extractRemotePath(null, origCorename);
-//            }
-            if (origCorename == null || collection.getName().equals(origCorename)) {
-              extractRemotePath(collection.getName(), null);
-            }
+
+            extractRemotePath(collection.getName());
+
             if (action == REMOTEQUERY) {
               coreUrl = coreUrl.replace("/solr/", "/solr/____v2/c/");
               this.path = path = path.substring(prefix.length() + collection.getName().length() + 2);
@@ -286,7 +277,7 @@ public class V2HttpCall extends HttpSolrCall {
     return compositeApi.add(new Api(() -> ValidatingJsonMap.EMPTY) {
       @Override
       public void call(SolrQueryRequest req1, SolrQueryResponse rsp) {
-        String prefix = null;
+        String prefix;
         prefix = fullPath.endsWith(CommonParams.INTROSPECT) ?
             fullPath.substring(0, fullPath.length() - CommonParams.INTROSPECT.length()) :
             fullPath;
@@ -313,8 +304,7 @@ public class V2HttpCall extends HttpSolrCall {
         HashSet<String> subPaths = new HashSet<>();
         registry.lookup(path, new HashMap<>(), subPaths);
         for (String subPath : subPaths) {
-          Set<String> supportedMethods = pathsVsMethod.get(subPath);
-          if (supportedMethods == null) pathsVsMethod.put(subPath, supportedMethods = new HashSet<>());
+          Set<String> supportedMethods = pathsVsMethod.computeIfAbsent(subPath, k -> new HashSet<>());
           supportedMethods.add(m.toString());
         }
       }
@@ -322,7 +312,7 @@ public class V2HttpCall extends HttpSolrCall {
   }
 
   public static class CompositeApi extends Api {
-    private LinkedList<Api> apis = new LinkedList<>();
+    private final LinkedList<Api> apis = new LinkedList<>();
 
     public CompositeApi(Api api) {
       super(ApiBag.EMPTY_SPEC);
@@ -384,4 +374,16 @@ public class V2HttpCall extends HttpSolrCall {
   protected Map<String, JsonSchemaValidator> getValidators() {
     return api == null ? null : api.getCommandSchema();
   }
+
+  private static class MyApi extends Api {
+    public MyApi() {
+      super(null);
+    }
+
+    @Override
+    public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
+      rsp.add("documentation", "https://lucene.apache.org/solr/guide/v2-api.html");
+      rsp.add("description", "V2 API root path");
+    }
+  }
 }
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 0182c87..c40710a 100644
--- a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
+++ b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
@@ -86,7 +86,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;
-import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;
 import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
 import static org.apache.solr.common.params.CollectionAdminParams.SYSTEM_COLL;
 import static org.apache.solr.common.params.CollectionParams.CollectionAction.CREATE;
@@ -305,12 +304,9 @@ public class HttpSolrCall {
           // if we couldn't find it locally, look on other nodes
           if (idx > 0) {
             if (log.isDebugEnabled()) log.debug("check remote path extraction {} {}", collectionName, origCorename);
-//            if (origCorename != null) {
-//              extractRemotePath(null, origCorename);
-//            }
-            if (origCorename == null || collectionName.equals(origCorename)) {
-              extractRemotePath(collectionName, null);
-            }
+
+            extractRemotePath(collectionName);
+
             if (action == REMOTEQUERY) {
               path = path.substring(idx);
               if (log.isDebugEnabled()) log.debug("Path is parsed as {}", path);
@@ -476,11 +472,11 @@ public class HttpSolrCall {
     }
   }
 
-  protected void extractRemotePath(String collectionName, String origCorename) throws UnsupportedEncodingException, KeeperException, InterruptedException, SolrException, TimeoutException {
+  protected void extractRemotePath(String collectionName) throws UnsupportedEncodingException, KeeperException, InterruptedException, SolrException, TimeoutException {
 
     ensureStatesAreAtLeastAtClient();
 
-    coreUrl = getRemoteCoreUrl(collectionName, origCorename);
+    coreUrl = getRemoteCoreUrl(collectionName);
     // don't proxy for internal update requests
     Map<String,Integer> invalidStates = checkStateVersionsAreValid(queryParams.get(CloudSolrClient.STATE_VERSION));
     if (coreUrl != null
@@ -1102,7 +1098,7 @@ public class HttpSolrCall {
     return core;
   }
 
-  protected String getRemoteCoreUrl(String collectionName, String origCorename) throws SolrException {
+  protected String getRemoteCoreUrl(String collectionName) throws SolrException {
     ClusterState clusterState = cores.getZkController().getClusterState();
     final DocCollection docCollection = clusterState.getCollectionOrNull(collectionName, false);
     if (docCollection == null) {
@@ -1114,13 +1110,13 @@ public class HttpSolrCall {
       return null;
     }
 
-    String coreUrl = getCoreUrl(origCorename, slices);
+    String coreUrl = getCoreUrl(slices);
 
     if (log.isDebugEnabled()) log.debug("get remote core url returning {} for {} {}", coreUrl, collectionName, origCorename);
     return coreUrl;
   }
 
-  private String getCoreUrl(String origCorename, Collection<Slice> slices) {
+  private String getCoreUrl(Collection<Slice> slices) {
     String coreUrl;
 
     for (Slice slice : slices) {
@@ -1131,15 +1127,6 @@ public class HttpSolrCall {
         if (cores.getZkController().zkStateReader.getLiveNodes().contains(replica.getNodeName())
             && replica.getState() == Replica.State.ACTIVE) {
 
-          if (origCorename != null && !origCorename.equals(replica.getStr(CORE_NAME_PROP))) {
-            // if it's by core name, make sure they match
-            continue;
-          }
-          if (replica.getBaseUrl().equals(cores.getZkController().getBaseUrl())) {
-            // don't count a local core
-            continue;
-          }
-
           coreUrl = replica.getCoreUrl();
 
           return coreUrl;