You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2021/06/14 15:32:54 UTC

[GitHub] [solr] cpoerschke opened a new pull request #176: SOLR-15476: Add ResponseBuilder.(newShardsInfo|addShardInfo) methods to facilitate 'shards.info' content customisation.

cpoerschke opened a new pull request #176:
URL: https://github.com/apache/solr/pull/176


   SOLR-15476: Add ResponseBuilder.(newShardsInfo|addShardInfo) methods to facilitate 'shards.info' content customisation.
   
   https://issues.apache.org/jira/browse/SOLR-15476


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob commented on a change in pull request #176: SOLR-15476: Add ResponseBuilder.(newShardsInfo|addShardInfo) methods to facilitate 'shards.info' content customisation.

Posted by GitBox <gi...@apache.org>.
madrob commented on a change in pull request #176:
URL: https://github.com/apache/solr/pull/176#discussion_r651060611



##########
File path: solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java
##########
@@ -175,6 +175,23 @@ public void addRequest(SearchComponent me, ShardRequest sreq) {
     }
   }
 
+  /**
+   *  Override this method and the {@link ResponseBuilder#addShardInfo(Object, String, NamedList)}
+   *  method e.g. if you wish to return a list instead of a map container.
+   */
+  protected Object newShardsInfo() {

Review comment:
       Should this return some interface instead of an Object?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] cpoerschke commented on a change in pull request #176: SOLR-15476: Facilitate 'shards.info' content customisation.

Posted by GitBox <gi...@apache.org>.
cpoerschke commented on a change in pull request #176:
URL: https://github.com/apache/solr/pull/176#discussion_r684330959



##########
File path: solr/core/src/test/org/apache/solr/handler/component/CustomSearchHandlerTest.java
##########
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.handler.component;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.cloud.AbstractDistribZkTestBase;
+import org.apache.solr.cloud.ConfigRequest;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CustomSearchHandlerTest extends SolrCloudTestCase {
+
+  /** A custom search handler that uses a custom response builder. */
+  public static class CustomSearchHandler extends SearchHandler {
+    @Override
+    protected ResponseBuilder newResponseBuilder(
+        SolrQueryRequest req, SolrQueryResponse rsp, List<SearchComponent> components) {
+      return new CustomResponseBuilder(req, rsp, components);
+    }
+  }
+
+  /** A custom response builder that uses a custom shards info container. */
+  private static class CustomResponseBuilder extends ResponseBuilder {
+
+    public CustomResponseBuilder(
+        SolrQueryRequest req, SolrQueryResponse rsp, List<SearchComponent> components) {
+      super(req, rsp, components);
+    }
+
+    @Override
+    protected ShardsInfoContainer newShardsInfoContainer() {
+      return new CustomShardsInfoContainer();
+    }
+  }
+
+  /**
+   * A container for recording shard to shard info mappings, retaining only the "shardAddress" part
+   * of the shard info.
+   *
+   * @see org.apache.solr.common.params.ShardParams#SHARDS_INFO
+   */
+  private static class CustomShardsInfoContainer extends ShardsInfoContainer {

Review comment:
       1/3 The `CustomResponseBuilder` and `CustomShardsInfoContainer` could in principle be done as inner classes of the `CustomSearchHandler` but like this seems clearer.

##########
File path: solr/core/src/test/org/apache/solr/handler/component/CustomSearchHandlerTest.java
##########
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.handler.component;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.cloud.AbstractDistribZkTestBase;
+import org.apache.solr.cloud.ConfigRequest;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CustomSearchHandlerTest extends SolrCloudTestCase {
+
+  /** A custom search handler that uses a custom response builder. */
+  public static class CustomSearchHandler extends SearchHandler {
+    @Override
+    protected ResponseBuilder newResponseBuilder(
+        SolrQueryRequest req, SolrQueryResponse rsp, List<SearchComponent> components) {
+      return new CustomResponseBuilder(req, rsp, components);
+    }
+  }
+
+  /** A custom response builder that uses a custom shards info container. */
+  private static class CustomResponseBuilder extends ResponseBuilder {
+
+    public CustomResponseBuilder(
+        SolrQueryRequest req, SolrQueryResponse rsp, List<SearchComponent> components) {
+      super(req, rsp, components);
+    }
+
+    @Override
+    protected ShardsInfoContainer newShardsInfoContainer() {
+      return new CustomShardsInfoContainer();
+    }
+  }
+
+  /**
+   * A container for recording shard to shard info mappings, retaining only the "shardAddress" part
+   * of the shard info.
+   *
+   * @see org.apache.solr.common.params.ShardParams#SHARDS_INFO
+   */
+  private static class CustomShardsInfoContainer extends ShardsInfoContainer {
+
+    private final List<Object> container = new ArrayList<>();
+
+    @Override
+    public void accept(String shardInfoName, NamedList<Object> shardInfoValue) {
+      final Object shardAddress = shardInfoValue.remove("shardAddress");
+      if (shardAddress != null) {
+        container.add(shardAddress);
+      }
+    }
+
+    @Override
+    public Object get() {
+      return container;
+    }
+  }
+
+  private static String COLLECTION;
+  private static int NUM_SHARDS;
+
+  @BeforeClass
+  public static void setupCluster() throws Exception {
+
+    // decide collection name ...
+    COLLECTION = "collection" + (1 + random().nextInt(100));
+    // ... and shard/replica/node numbers
+    NUM_SHARDS = 1 + random().nextInt(3);
+    final int numReplicas = 2;
+    final int nodeCount = NUM_SHARDS * numReplicas;
+
+    // create and configure cluster
+    configureCluster(nodeCount).addConfig("conf", configset("cloud-dynamic")).configure();
+
+    // create an empty collection
+    CollectionAdminRequest.createCollection(COLLECTION, "conf", NUM_SHARDS, numReplicas)
+        .processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);
+    AbstractDistribZkTestBase.waitForRecoveriesToFinish(
+        COLLECTION, cluster.getSolrClient().getZkStateReader(), false, true, DEFAULT_TIMEOUT);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void testShardsInfoContainerCustomisation() throws Exception {
+
+    // determine custom search handler name (the exact name should not matter)
+    final String customSearchHandlerName = "/custom_select" + random().nextInt();
+
+    // add custom handler
+    {
+      cluster
+          .getSolrClient()
+          .request(
+              new ConfigRequest(
+                  "{\n"
+                      + "  'add-requesthandler': {\n"
+                      + "    'name' : '"
+                      + customSearchHandlerName
+                      + "',\n"
+                      + "    'class' : '"
+                      + CustomSearchHandler.class.getName()
+                      + "',\n"
+                      + "    'components' : [ '"
+                      + QueryComponent.COMPONENT_NAME
+                      + "' ]\n"
+                      + "  }\n"
+                      + "}"),
+              COLLECTION);
+    }

Review comment:
       2/3 ConfigRequest use here as alternative to yet another `solrconfig-for-my-test.xml` file.

##########
File path: solr/core/src/test/org/apache/solr/handler/component/CustomSearchHandlerTest.java
##########
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.handler.component;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.cloud.AbstractDistribZkTestBase;
+import org.apache.solr.cloud.ConfigRequest;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CustomSearchHandlerTest extends SolrCloudTestCase {
+
+  /** A custom search handler that uses a custom response builder. */
+  public static class CustomSearchHandler extends SearchHandler {
+    @Override
+    protected ResponseBuilder newResponseBuilder(
+        SolrQueryRequest req, SolrQueryResponse rsp, List<SearchComponent> components) {
+      return new CustomResponseBuilder(req, rsp, components);
+    }
+  }
+
+  /** A custom response builder that uses a custom shards info container. */
+  private static class CustomResponseBuilder extends ResponseBuilder {
+
+    public CustomResponseBuilder(
+        SolrQueryRequest req, SolrQueryResponse rsp, List<SearchComponent> components) {
+      super(req, rsp, components);
+    }
+
+    @Override
+    protected ShardsInfoContainer newShardsInfoContainer() {
+      return new CustomShardsInfoContainer();
+    }
+  }
+
+  /**
+   * A container for recording shard to shard info mappings, retaining only the "shardAddress" part
+   * of the shard info.
+   *
+   * @see org.apache.solr.common.params.ShardParams#SHARDS_INFO
+   */
+  private static class CustomShardsInfoContainer extends ShardsInfoContainer {
+
+    private final List<Object> container = new ArrayList<>();
+
+    @Override
+    public void accept(String shardInfoName, NamedList<Object> shardInfoValue) {
+      final Object shardAddress = shardInfoValue.remove("shardAddress");
+      if (shardAddress != null) {
+        container.add(shardAddress);
+      }
+    }
+
+    @Override
+    public Object get() {
+      return container;
+    }
+  }
+
+  private static String COLLECTION;
+  private static int NUM_SHARDS;
+
+  @BeforeClass
+  public static void setupCluster() throws Exception {
+
+    // decide collection name ...
+    COLLECTION = "collection" + (1 + random().nextInt(100));
+    // ... and shard/replica/node numbers
+    NUM_SHARDS = 1 + random().nextInt(3);
+    final int numReplicas = 2;
+    final int nodeCount = NUM_SHARDS * numReplicas;
+
+    // create and configure cluster
+    configureCluster(nodeCount).addConfig("conf", configset("cloud-dynamic")).configure();
+
+    // create an empty collection
+    CollectionAdminRequest.createCollection(COLLECTION, "conf", NUM_SHARDS, numReplicas)
+        .processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);
+    AbstractDistribZkTestBase.waitForRecoveriesToFinish(
+        COLLECTION, cluster.getSolrClient().getZkStateReader(), false, true, DEFAULT_TIMEOUT);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void testShardsInfoContainerCustomisation() throws Exception {
+
+    // determine custom search handler name (the exact name should not matter)
+    final String customSearchHandlerName = "/custom_select" + random().nextInt();
+
+    // add custom handler
+    {
+      cluster
+          .getSolrClient()
+          .request(
+              new ConfigRequest(
+                  "{\n"
+                      + "  'add-requesthandler': {\n"
+                      + "    'name' : '"
+                      + customSearchHandlerName
+                      + "',\n"
+                      + "    'class' : '"
+                      + CustomSearchHandler.class.getName()
+                      + "',\n"
+                      + "    'components' : [ '"
+                      + QueryComponent.COMPONENT_NAME
+                      + "' ]\n"
+                      + "  }\n"
+                      + "}"),

Review comment:
       3/3 The layout here is not to my taste but it's what "spotless" made it to be.
   
   Elsewhere we have https://github.com/apache/lucene-solr/blob/releases/lucene-solr/8.9.0/solr/core/src/test/org/apache/solr/handler/component/CustomHighlightComponentTest.java#L167-L174 and https://github.com/apache/lucene-solr/blob/releases/lucene-solr/8.9.0/solr/core/src/test/org/apache/solr/handler/component/CustomTermsComponentTest.java#L96-L103 layout.
   
   But well for the three new files in this pull request it seemed logical to go with what "spotless" would (eventually) enforce for them.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob commented on pull request #176: SOLR-15476: Facilitate 'shards.info' content customisation.

Posted by GitBox <gi...@apache.org>.
madrob commented on pull request #176:
URL: https://github.com/apache/solr/pull/176#issuecomment-860837631


   > I've placed use illustrations on the JIRA ticket, does that help? That's not to say we can't have unit test coverage too of course.
   
   Yea, those are helpful. Test coverage will be more discoverable for some people, I think.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] cpoerschke commented on a change in pull request #176: SOLR-15476: Add ResponseBuilder.(newShardsInfo|addShardInfo) methods to facilitate 'shards.info' content customisation.

Posted by GitBox <gi...@apache.org>.
cpoerschke commented on a change in pull request #176:
URL: https://github.com/apache/solr/pull/176#discussion_r651065963



##########
File path: solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java
##########
@@ -175,6 +175,23 @@ public void addRequest(SearchComponent me, ShardRequest sreq) {
     }
   }
 
+  /**
+   *  Override this method and the {@link ResponseBuilder#addShardInfo(Object, String, NamedList)}
+   *  method e.g. if you wish to return a list instead of a map container.
+   */
+  protected Object newShardsInfo() {

Review comment:
       > Should this return some interface instead of an Object?
   
   Yes, that's a good idea, thank you. It would also avoid the _"if you changed this method you must also change the other method"_ stuff.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob commented on pull request #176: SOLR-15476: Add ResponseBuilder.(newShardsInfo|addShardInfo) methods to facilitate 'shards.info' content customisation.

Posted by GitBox <gi...@apache.org>.
madrob commented on pull request #176:
URL: https://github.com/apache/solr/pull/176#issuecomment-860783598


   I'm having trouble understanding how this is used in practice, can you add a unit test showing an example override implementation?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] cpoerschke commented on pull request #176: SOLR-15476: Add ResponseBuilder.(newShardsInfo|addShardInfo) methods to facilitate 'shards.info' content customisation.

Posted by GitBox <gi...@apache.org>.
cpoerschke commented on pull request #176:
URL: https://github.com/apache/solr/pull/176#issuecomment-860787505


   > I'm having trouble understanding how this is used in practice, can you add a unit test showing an example override implementation?
   
   I've placed use illustrations on the JIRA ticket, does that help? That's not to say we can't have unit test coverage too of course.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob commented on a change in pull request #176: SOLR-15476: Facilitate 'shards.info' content customisation.

Posted by GitBox <gi...@apache.org>.
madrob commented on a change in pull request #176:
URL: https://github.com/apache/solr/pull/176#discussion_r651120975



##########
File path: solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java
##########
@@ -175,6 +177,26 @@ public void addRequest(SearchComponent me, ShardRequest sreq) {
     }
   }
 
+  public static abstract class ShardsInfoContainer implements BiConsumer<String,NamedList<Object>>, Supplier<Object> {

Review comment:
       interface v abstract class?
   
   I'd like to see some javadoc here too.

##########
File path: solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java
##########
@@ -175,6 +177,26 @@ public void addRequest(SearchComponent me, ShardRequest sreq) {
     }
   }
 
+  public static abstract class ShardsInfoContainer implements BiConsumer<String,NamedList<Object>>, Supplier<Object> {
+  }
+
+  protected ShardsInfoContainer newShardsInfoContainer() {
+    return new ShardsInfoContainer() {

Review comment:
       could this be a concrete implementation?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org