Copilot commented on code in PR #17576:
URL: https://github.com/apache/pinot/pull/17576#discussion_r2785559017
##########
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;
Review Comment:
In TS/JS it’s best to avoid boxed types and loose equality. Prefer `string`
over `String` for `name`, and use `===` instead of `==` for `node.type`
comparisons to avoid coercion edge cases and align with typical lint rules.
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java:
##########
@@ -2031,6 +2031,14 @@ public static class MultiStageQueryRunner {
public static final String KEY_OF_SEND_STATS_MODE =
"pinot.query.mse.stats.mode";
public static final String DEFAULT_SEND_STATS_MODE = "SAFE";
+ /// Used to indicate whether MSE pipeline breaker stats should be included
in the queryStats field.
+ /// This flag was introduced in 1.5.0. Before 1.5.0, MSE pipeline breaker
stats were not kept. Starting from 1.5.0,
+ /// they are not included by default but can be included by setting this
flag to false (upper or lower case).
+ ///
+ /// It is expected that in 1.6.0 and later, MSE pipeline breaker stats
will be included by default.
+ public static final String KEY_OF_SKIP_PIPELINE_BREAKER_STATS =
"pinot.query.mse.skip.pipeline.breaker.stats";
+ public static final boolean DEFAULT_SKIP_PIPELINE_BREAKER_STATS = true;
Review Comment:
The config key name is expressed as “skip”
(`KEY_OF_SKIP_PIPELINE_BREAKER_STATS`) but the docstring describes it primarily
as “include” behavior, which is easy to misread for operators and also appears
inconsistent with the PR description’s “keep.*” naming. Consider either (a)
renaming the property to a positive form (e.g.,
`pinot.query.mse.keep.pipeline.breaker.stats` with an appropriate default), or
(b) updating the Javadoc to explicitly lead with “when true, pipeline breaker
stats are skipped” and clearly describe the `true/false` semantics to avoid
confusion.
##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/plan/pipeline/PipelineBreakerOperator.java:
##########
@@ -149,6 +150,13 @@ protected MultiStageQueryStats calculateUpstreamStats() {
@Override
public StatMap<StatKey> copyStatMaps() {
+ if (_statMap.getLong(StatKey.EMITTED_ROWS) == 0) {
+ long totalRows = _resultMap.values().stream()
+ .flatMap(List::stream)
+ .mapToLong(block -> ((MseBlock.Data) block).getNumRows())
+ .sum();
+ _statMap.merge(StatKey.EMITTED_ROWS, totalRows);
+ }
Review Comment:
This unconditionally casts every `MseBlock` to `MseBlock.Data`. If the
pipeline breaker result map includes non-data blocks (e.g., EOS/success/error
blocks), this will throw `ClassCastException`. Fix by filtering for `block
instanceof MseBlock.Data` (or using a safe accessor if one exists) before
reading `getNumRows()`.
##########
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";
+ TestUtils.waitForCondition(() -> {
Review Comment:
The variable name and message have typos/awkward phrasing: `erroMsg` should
be `errorMsg`, and the message repeats “after multiple attempts after 10
attempts”. Consider correcting both to improve readability/debuggability.
##########
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));
+ if (oldEnabled != _skip) {
+ LOGGER.info("Updated {} from: {} to: {}, parsed as {}", key, valueStr,
oldEnabled, _skip);
Review Comment:
The variable naming and log message arguments are internally inconsistent:
`oldEnabled` is actually the old “skip” value, and the log prints `from:
<string> to: <old boolean>, parsed as <new boolean>`, which is misleading.
Rename `oldEnabled` to something like `oldSkip` (or invert logic and track
`oldEnabled`/`newEnabled` consistently), and adjust the log to report old → new
boolean values while optionally including the raw string separately.
```suggestion
boolean oldSkip = _skip;
String valueStr = value.trim();
_skip = Boolean.parseBoolean(valueStr.toLowerCase(Locale.ENGLISH));
if (oldSkip != _skip) {
LOGGER.info("Updated {} from: {} to: {} (raw: {})", key, oldSkip,
_skip, valueStr);
```
##########
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;
+ }
Review Comment:
In TS/JS it’s best to avoid boxed types and loose equality. Prefer `string`
over `String` for `name`, and use `===` instead of `==` for `node.type`
comparisons to avoid coercion edge cases and align with typical lint rules.
##########
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)
=> {
Review Comment:
In TS/JS it’s best to avoid boxed types and loose equality. Prefer `string`
over `String` for `name`, and use `===` instead of `==` for `node.type`
comparisons to avoid coercion edge cases and align with typical lint rules.
--
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]