yashmayya commented on code in PR #17576:
URL: https://github.com/apache/pinot/pull/17576#discussion_r2785547413


##########
pinot-controller/src/main/resources/app/components/Query/FlamegraphQueryStageStats.tsx:
##########
@@ -99,48 +99,89 @@ const generateFlameGraphData = (stats, highlightedStage : 
Number = null, mode :
 
   const stages = [];
 
-  const processNode = (node, currentStage) => {
-    const { children, ...data } = node;
+  const processNode = (node, currentStage, onPipelineBreaker: boolean = false) 
=> {
+    let { children, ...data } = node;
 
     const baseNode = {
       tooltip: JSON.stringify(data),
       value: getNodeValue(data),
       backgroundColor: highlightedStage === currentStage ? 'lightblue' : null,
     }
-    // If it's a MAILBOX_RECEIVE node, prune the tree here
-    if (data.type === "MAILBOX_RECEIVE") {
-      const sendOperator = children[0];
-      visitStage(sendOperator, currentStage);
-      return {
-        name: `MAILBOX_RECEIVE from stage ${sendOperator.stage || 'unknown'}`,
-        relatedStage: sendOperator.stage || null,
-        ...baseNode,
-      };
+    let name: String;
+    switch (data.type) {
+      case "LEAF": {
+        name = `LEAF (${data.table || ''})`;
+        if (children && children.length !== 0) {
+          // We don't want to include the children in this stage because its 
time is independent of the leaf node.
+          children = [];
+        }
+        break;
+      }
+      case "MAILBOX_RECEIVE": {
+        // If it's a MAILBOX_RECEIVE node, prune the tree here
+        const sendOperator = children[0];
+        visitStage(sendOperator, currentStage);
+        const prefix = onPipelineBreaker ? "PIPELINE_BREAKER " : 
"MAILBOX_RECEIVE";
+        return {
+          name: `${prefix} from stage ${sendOperator.stage || 'unknown'}`,
+          relatedStage: sendOperator.stage || null, ...baseNode,
+        };
+      }
+      default: {
+        name = data.type || "Unknown Type";
+      }
     }
 
     // For other nodes, continue processing children
     return {
-      name: data.type || "Unknown Type",
+      name: name,
       ...baseNode,
       children: children
-        ? children.map(node => processNode(node, currentStage))
+        ? children.map(node => processNode(node, currentStage, 
onPipelineBreaker))
           .filter(child => child !== null) : [],
     };
   }
 
+  const getPipelineBreakerNode = (children, currentStage: number) => {
+    const stack = [...children];

Review Comment:
   Should this be guarded with a check like `if (!children || children.length 
=== 0) return null;`



##########
pinot-controller/src/main/resources/app/components/Query/FlamegraphQueryStageStats.tsx:
##########
@@ -99,48 +99,89 @@ const generateFlameGraphData = (stats, highlightedStage : 
Number = null, mode :
 
   const stages = [];
 
-  const processNode = (node, currentStage) => {
-    const { children, ...data } = node;
+  const processNode = (node, currentStage, onPipelineBreaker: boolean = false) 
=> {
+    let { children, ...data } = node;
 
     const baseNode = {
       tooltip: JSON.stringify(data),
       value: getNodeValue(data),
       backgroundColor: highlightedStage === currentStage ? 'lightblue' : null,
     }
-    // If it's a MAILBOX_RECEIVE node, prune the tree here
-    if (data.type === "MAILBOX_RECEIVE") {
-      const sendOperator = children[0];
-      visitStage(sendOperator, currentStage);
-      return {
-        name: `MAILBOX_RECEIVE from stage ${sendOperator.stage || 'unknown'}`,
-        relatedStage: sendOperator.stage || null,
-        ...baseNode,
-      };
+    let name: String;
+    switch (data.type) {
+      case "LEAF": {
+        name = `LEAF (${data.table || ''})`;
+        if (children && children.length !== 0) {
+          // We don't want to include the children in this stage because its 
time is independent of the leaf node.
+          children = [];
+        }
+        break;
+      }
+      case "MAILBOX_RECEIVE": {
+        // If it's a MAILBOX_RECEIVE node, prune the tree here
+        const sendOperator = children[0];
+        visitStage(sendOperator, currentStage);
+        const prefix = onPipelineBreaker ? "PIPELINE_BREAKER " : 
"MAILBOX_RECEIVE";
+        return {
+          name: `${prefix} from stage ${sendOperator.stage || 'unknown'}`,
+          relatedStage: sendOperator.stage || null, ...baseNode,
+        };
+      }
+      default: {
+        name = data.type || "Unknown Type";
+      }
     }
 
     // For other nodes, continue processing children
     return {
-      name: data.type || "Unknown Type",
+      name: name,
       ...baseNode,
       children: children
-        ? children.map(node => processNode(node, currentStage))
+        ? children.map(node => processNode(node, currentStage, 
onPipelineBreaker))
           .filter(child => child !== null) : [],
     };
   }
 
+  const getPipelineBreakerNode = (children, currentStage: number) => {
+    const stack = [...children];
+    while (stack.length > 0) {
+      const node = stack.pop();
+      if (node.type === "LEAF" && node.children && node.children.length > 0) {
+        return processNode(node.children[0], currentStage, true);
+      }
+      if (node.type == "MAILBOX_RECEIVE") {
+        // We don't want to go past MAILBOX_RECEIVE nodes, as their children 
belong to other stages.
+        continue;
+      }
+      if (node.children && node.children.length > 0) {
+        stack.push(...node.children);
+      }
+    }
+    return null;
+  }
+
   const visitStage = (node, parentStage = null) => {
     const { children, ...data } = node;
     const stage = data.stage || 0;
-    const value = getNodeValue(node);
+    const pipelineBreakerNode = getPipelineBreakerNode(children, stage);
+    let value: number;
+    const childrenNodes = children
+        ? children.map(node => processNode(node, stage)).filter(child => child 
!== null)
+        : [];
+    if (pipelineBreakerNode) {
+      value = getNodeValue(node) + pipelineBreakerNode.value || 0;

Review Comment:
   Should this be `value = getNodeValue(node) + (pipelineBreakerNode.value || 
0)`;



##########
pinot-server/src/main/java/org/apache/pinot/server/starter/helix/KeepPipelineBreakerStatsPredicate.java:
##########
@@ -0,0 +1,78 @@
+/**
+ * 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.pinot.server.starter.helix;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import org.apache.pinot.spi.config.provider.PinotClusterConfigChangeListener;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class KeepPipelineBreakerStatsPredicate implements 
PinotClusterConfigChangeListener {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(KeepPipelineBreakerStatsPredicate.class);
+
+  private volatile boolean _skip;
+
+  public KeepPipelineBreakerStatsPredicate(boolean skip) {
+    _skip = skip;
+  }
+
+  // NOTE: When this method is called, the helix manager is not yet connected.
+  public static KeepPipelineBreakerStatsPredicate create(PinotConfiguration 
serverConf) {
+    boolean skip = serverConf.getProperty(
+        
CommonConstants.MultiStageQueryRunner.KEY_OF_SKIP_PIPELINE_BREAKER_STATS,
+        
CommonConstants.MultiStageQueryRunner.DEFAULT_SKIP_PIPELINE_BREAKER_STATS);
+    LOGGER.info("Initialized {} with value: {}",
+        
CommonConstants.MultiStageQueryRunner.KEY_OF_SKIP_PIPELINE_BREAKER_STATS, skip);
+    return new KeepPipelineBreakerStatsPredicate(skip);
+  }
+
+  public boolean isEnabled() {
+    return !_skip;
+  }
+
+  @Override
+  public void onChange(Set<String> changedConfigs, Map<String, String> 
clusterConfigs) {
+    String key = 
CommonConstants.MultiStageQueryRunner.KEY_OF_SKIP_PIPELINE_BREAKER_STATS;
+    if (!changedConfigs.contains(key)) {
+      LOGGER.debug("No change for key: {}, keeping its value as {}", key, 
_skip);
+      return;
+    }
+    String value = clusterConfigs.get(key);
+    if (value == null || value.isEmpty()) {
+      LOGGER.info("Empty or null value for key: {}, reset to default: {}",
+          key,
+          
CommonConstants.MultiStageQueryRunner.DEFAULT_SKIP_PIPELINE_BREAKER_STATS);
+      _skip = 
CommonConstants.MultiStageQueryRunner.DEFAULT_SKIP_PIPELINE_BREAKER_STATS;
+    } else {
+      boolean oldEnabled = _skip;

Review Comment:
   enabled <-> skip is confusing / wrong?



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/MultiStageEngineIntegrationTest.java:
##########
@@ -2149,6 +2148,117 @@ public void testNaturalJoinWithNoVirtualColumns()
     assertNotNull(response.get("resultTable"), "Should have result table");
   }
 
+  @Test
+  public void testStageStatsPipelineBreaker()
+      throws Exception {
+    HelixConfigScope scope =
+        new 
HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).forCluster(getHelixClusterName())
+            .build();
+    try {
+      _helixManager.getConfigAccessor()
+          .set(scope, 
CommonConstants.MultiStageQueryRunner.KEY_OF_SKIP_PIPELINE_BREAKER_STATS, 
"false");
+      String query = "select * from mytable "
+          + "WHERE DayOfWeek in (select dayid from daysOfWeek)";
+      JsonNode response = postQuery(query);
+      assertNotNull(response.get("stageStats"), "Should have stage stats");
+
+      JsonNode receiveNode = response.get("stageStats");
+      
Assertions.assertThat(receiveNode.get("type").asText()).isEqualTo("MAILBOX_RECEIVE");
+
+      JsonNode sendNode = receiveNode.get("children").get(0);
+      
Assertions.assertThat(sendNode.get("type").asText()).isEqualTo("MAILBOX_SEND");
+
+      JsonNode mytableLeaf = sendNode.get("children").get(0);
+      
Assertions.assertThat(mytableLeaf.get("type").asText()).isEqualTo("LEAF");
+      
Assertions.assertThat(mytableLeaf.get("table").asText()).isEqualTo("mytable");
+
+      JsonNode pipelineReceive = mytableLeaf.get("children").get(0);
+      
Assertions.assertThat(pipelineReceive.get("type").asText()).isEqualTo("MAILBOX_RECEIVE");
+
+      JsonNode pipelineSend = pipelineReceive.get("children").get(0);
+      
Assertions.assertThat(pipelineSend.get("type").asText()).isEqualTo("MAILBOX_SEND");
+
+      JsonNode dayOfWeekLeaf = pipelineSend.get("children").get(0);
+      
Assertions.assertThat(dayOfWeekLeaf.get("type").asText()).isEqualTo("LEAF");
+      
Assertions.assertThat(dayOfWeekLeaf.get("table").asText()).isEqualTo("daysOfWeek");
+    } finally {
+      _helixManager.getConfigAccessor()
+          .set(scope, 
CommonConstants.MultiStageQueryRunner.KEY_OF_SKIP_PIPELINE_BREAKER_STATS, 
"true");
+    }
+  }
+
+  @Test
+  public void testPipelineBreakerKeepsNumGroupsLimitReached()
+      throws Exception {
+    HelixConfigScope scope =
+        new 
HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).forCluster(getHelixClusterName())
+            .build();
+    try {
+      _helixManager.getConfigAccessor()
+          .set(scope, 
CommonConstants.MultiStageQueryRunner.KEY_OF_SKIP_PIPELINE_BREAKER_STATS, 
"false");
+      String query = ""
+          + "SET numGroupsLimit = 1;"
+          + "SELECT * FROM daysOfWeek "
+          + "WHERE dayid in ("
+          + " SELECT DayOfWeek FROM mytable"
+          + " GROUP BY DayOfWeek"
+          + ")";
+
+      JsonNode response = postQuery(query);
+      assertNotNull(response.get("stageStats"), "Should have stage stats");
+
+      JsonNode receiveNode = response.get("stageStats");
+      
Assertions.assertThat(receiveNode.get("type").asText()).isEqualTo("MAILBOX_RECEIVE");
+
+      JsonNode sendNode = receiveNode.get("children").get(0);
+      
Assertions.assertThat(sendNode.get("type").asText()).isEqualTo("MAILBOX_SEND");
+
+      JsonNode mytableLeaf = sendNode.get("children").get(0);
+      
Assertions.assertThat(mytableLeaf.get("type").asText()).isEqualTo("LEAF");
+      
Assertions.assertThat(mytableLeaf.get("table").asText()).isEqualToIgnoringCase("daysOfWeek");
+
+      JsonNode pipelineReceive = mytableLeaf.get("children").get(0);
+      
Assertions.assertThat(pipelineReceive.get("type").asText()).isEqualTo("MAILBOX_RECEIVE");
+
+      JsonNode pipelineSend = pipelineReceive.get("children").get(0);
+      
Assertions.assertThat(pipelineSend.get("type").asText()).isEqualTo("MAILBOX_SEND");
+
+      
Assertions.assertThat(response.get("numGroupsLimitReached").asBoolean(false))
+          .describedAs("numGroupsLimitReached should be true even when the 
limit is reached on a pipeline breaker")
+          .isEqualTo(true);
+    } finally {
+      _helixManager.getConfigAccessor()
+          .set(scope, 
CommonConstants.MultiStageQueryRunner.KEY_OF_SKIP_PIPELINE_BREAKER_STATS, 
"true");
+    }
+  }
+
+  @Test
+  public void testPipelineBreakerWithoutKeepingStats()
+      throws Exception {
+    // let's try several times to give helix time to propagate the config 
change
+    String erroMsg = "Failed to verify absence of pipeline breaker stats after 
multiple attempts after 10 attempts";

Review Comment:
   ```suggestion
       String errorMsg = "Failed to verify absence of pipeline breaker stats 
after multiple attempts after 10 attempts";
   ```
   nit



##########
pinot-server/src/main/java/org/apache/pinot/server/starter/helix/KeepPipelineBreakerStatsPredicate.java:
##########
@@ -0,0 +1,78 @@
+/**
+ * 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.pinot.server.starter.helix;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import org.apache.pinot.spi.config.provider.PinotClusterConfigChangeListener;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class KeepPipelineBreakerStatsPredicate implements 
PinotClusterConfigChangeListener {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(KeepPipelineBreakerStatsPredicate.class);
+
+  private volatile boolean _skip;
+
+  public KeepPipelineBreakerStatsPredicate(boolean skip) {
+    _skip = skip;
+  }
+
+  // NOTE: When this method is called, the helix manager is not yet connected.
+  public static KeepPipelineBreakerStatsPredicate create(PinotConfiguration 
serverConf) {
+    boolean skip = serverConf.getProperty(
+        
CommonConstants.MultiStageQueryRunner.KEY_OF_SKIP_PIPELINE_BREAKER_STATS,
+        
CommonConstants.MultiStageQueryRunner.DEFAULT_SKIP_PIPELINE_BREAKER_STATS);
+    LOGGER.info("Initialized {} with value: {}",
+        
CommonConstants.MultiStageQueryRunner.KEY_OF_SKIP_PIPELINE_BREAKER_STATS, skip);
+    return new KeepPipelineBreakerStatsPredicate(skip);
+  }
+
+  public boolean isEnabled() {
+    return !_skip;
+  }
+
+  @Override
+  public void onChange(Set<String> changedConfigs, Map<String, String> 
clusterConfigs) {
+    String key = 
CommonConstants.MultiStageQueryRunner.KEY_OF_SKIP_PIPELINE_BREAKER_STATS;
+    if (!changedConfigs.contains(key)) {
+      LOGGER.debug("No change for key: {}, keeping its value as {}", key, 
_skip);
+      return;
+    }
+    String value = clusterConfigs.get(key);
+    if (value == null || value.isEmpty()) {
+      LOGGER.info("Empty or null value for key: {}, reset to default: {}",
+          key,
+          
CommonConstants.MultiStageQueryRunner.DEFAULT_SKIP_PIPELINE_BREAKER_STATS);
+      _skip = 
CommonConstants.MultiStageQueryRunner.DEFAULT_SKIP_PIPELINE_BREAKER_STATS;
+    } else {
+      boolean oldEnabled = _skip;
+      String valueStr = value.trim();
+      _skip = Boolean.parseBoolean(valueStr.toLowerCase(Locale.ENGLISH));

Review Comment:
   Redundant call to `toLowerCase`?



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