sarkaramrit1993 commented on code in PR #5307:
URL: https://github.com/apache/solr/pull/5307#discussion_r4522863441


##########
solr/core/src/test/org/apache/solr/handler/component/ShardCpuTimeLimitTest.java:
##########
@@ -0,0 +1,191 @@
+/*
+ * 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.List;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.cloud.ConfigRequest;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.cloud.Replica;
+import org.apache.solr.common.params.ShardParams;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrQueryRequestBase;
+import org.apache.solr.request.SolrRequestInfo;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.search.QueryLimit;
+import org.apache.solr.util.TestInjection;
+import org.apache.solr.util.ThreadCpuTimer;
+import org.junit.After;
+import org.junit.BeforeClass;
+
+/** Shard CPU time when a query limit stops a distributed search. */
+public class ShardCpuTimeLimitTest extends SolrCloudTestCase {
+
+  private static final String COLLECTION = "limit-cpu";
+  private static final String HANDLER = "/fixedcpu";
+  private static final String STOP_AT_PARAM = "stopAt";
+  private static final String FINISHING = "fixedCpuFinishing";
+  private static final long SHARD_CPU_MS = 1000L;
+  // GET_TOP_IDS goes to both shards, so the first round of responses reports 
this much
+  private static final long TOP_IDS_CPU_MS = 2 * SHARD_CPU_MS;
+  // GET_FIELDS then goes only to the shard holding the one doc
+  private static final long GET_FIELDS_CPU_MS = TOP_IDS_CPU_MS + SHARD_CPU_MS;
+
+  /**
+   * Reports a fixed shard cpuTime, and marks when the coordinator finishes a 
stage with responses.
+   */
+  public static class FixedCpuComponent extends SearchComponent {
+    @Override
+    public void prepare(ResponseBuilder rb) {}
+
+    @Override
+    public void process(ResponseBuilder rb) {
+      rb.rsp.getResponseHeader().add(ThreadCpuTimer.CPU_TIME, SHARD_CPU_MS);
+    }
+
+    @Override
+    public void finishStage(ResponseBuilder rb) {
+      if (!rb.finished.isEmpty()) {
+        rb.req.getContext().put(FINISHING, true);
+      }
+    }
+
+    @Override
+    public String getDescription() {
+      return "fixed cpuTime";
+    }
+  }
+
+  /** Stops the coordinator at the check named by {@link #STOP_AT_PARAM}. */
+  private static class StopAtLimit implements QueryLimit {
+    @Override
+    public boolean shouldExit() {
+      SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
+      ResponseBuilder rb = info == null ? null : info.getResponseBuilder();
+      if (rb == null || rb.finished == null) {
+        return false;
+      }
+      return switch (rb.req.getParams().get(STOP_AT_PARAM, "")) {
+        case "start" -> true;
+        case "handleResponses" -> !rb.finished.isEmpty();
+        case "finishStage" -> rb.req.getContext().containsKey(FINISHING);
+        case "getFields" -> rb.getStage() == ResponseBuilder.STAGE_GET_FIELDS;
+        case "afterGetFields" ->
+            rb.req.getContext().containsKey(FINISHING) && rb.finished.size() > 
1;
+        default -> false;
+      };
+    }
+
+    @Override
+    public Object currentValue() {
+      return null;
+    }
+  }
+
+  @BeforeClass
+  public static void setupCluster() throws Exception {
+    System.setProperty(ThreadCpuTimer.ENABLE_CPU_TIME, "true");
+    configureCluster(2).addConfig("conf", 
configset("cloud-dynamic")).configure();

Review Comment:
   Yes, done in 
[d6ad61f](https://github.com/apache/solr/pull/5307/commits/d6ad61f9ae3e505d567a904b74ca99dddf345fb0).
 Also new since your approval: 
[818b925](https://github.com/apache/solr/pull/5307/commits/818b92523f3) 
publishes shard CPU when `partialResults=false` makes the limit throw.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to