Jackie-Jiang commented on code in PR #15312: URL: https://github.com/apache/pinot/pull/15312#discussion_r2004365100
########## pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/utils/BlockingMultiStreamConsumer.java: ########## @@ -244,11 +244,14 @@ private E readBlockOrNull() { public static class OfTransferableBlock extends BlockingMultiStreamConsumer<TransferableBlock> { - private final MultiStageQueryStats _stats; + private final int _stageId; + @Nullable + private volatile MultiStageQueryStats _stats; Review Comment: (minor) Is this class single-threaded? Do we need to keep thread safety? ########## pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java: ########## @@ -1475,6 +1476,23 @@ public static class MultiStageQueryRunner { public static final String KEY_OF_MAX_ROWS_IN_JOIN = "pinot.query.join.max.rows"; public static final String KEY_OF_JOIN_OVERFLOW_MODE = "pinot.query.join.overflow.mode"; + /// Specifies the send stats mode used in MSE. Review Comment: (minor) Consider keeping the same javadoc convention for consistency ########## pinot-server/src/main/java/org/apache/pinot/server/starter/helix/SendStatsPredicate.java: ########## @@ -0,0 +1,160 @@ +/** + * 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.List; +import java.util.Locale; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.Nullable; +import org.apache.helix.NotificationContext; +import org.apache.helix.api.listeners.InstanceConfigChangeListener; +import org.apache.helix.model.InstanceConfig; +import org.apache.pinot.common.version.PinotVersion; +import org.apache.pinot.spi.env.PinotConfiguration; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public abstract class SendStatsPredicate implements InstanceConfigChangeListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SendStatsPredicate.class); + + public abstract boolean getSendStats(); + + public static SendStatsPredicate create(PinotConfiguration configuration) { + String modeStr = configuration.getProperty( + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE, + CommonConstants.MultiStageQueryRunner.DEFAULT_SEND_STATS_MODE).toUpperCase(Locale.ENGLISH); + for (Mode mode : Mode.values()) { + if (mode.name().equals(modeStr)) { + return mode.create(); + } + } + + throw new IllegalStateException("Invalid value " + modeStr + " for " + + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE); + } + + public enum Mode { + SAFE { + @Override + public SendStatsPredicate create() { + return new Safe(); + } + }, + ALWAYS { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }, + NEVER { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }; + + public abstract SendStatsPredicate create(); + } + + private static class Safe extends SendStatsPredicate { + private final AtomicBoolean _sendStats = new AtomicBoolean(true); + + @Override + public boolean getSendStats() { + return _sendStats.get(); + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + boolean sendStats = true; + // TODO: Right now we read all configs, while only broker and servers are actually important + // But it isn't clear how to detect for sure that an instance config belongs to a broker or server + for (InstanceConfig instanceConfig : instanceConfigs) { + String otherVersion = instanceConfig.getRecord() + .getStringField(CommonConstants.Helix.Instance.PINOT_VERSION_KEY, null); + if (otherVersion == null || otherVersion.equals(PinotVersion.UNKNOWN)) { + LOGGER.warn("Instance {} does not have version", instanceConfig.getInstanceName()); + continue; + } + if (isProblematicVersion(otherVersion)) { + LOGGER.info("Found problematic version {} on instance {}. Stats may not be recognized", otherVersion, + instanceConfig.getInstanceName()); + sendStats = false; + break; + } + } + if (_sendStats.getAndSet(sendStats) != sendStats) { + LOGGER.warn("Send MSE stats is now {}", sendStats ? "enabled" : "disabled"); + } + } + + /// Returns true if the version is problematic + /// + /// Ideally [PinotVersion] should have a way to extract versions in comparable format, but given it doesn't we + /// need to parse the string here. In case version doesn't match `1\.x\..*`, we treat is as a problematic version + private boolean isProblematicVersion(@Nullable String versionStr) { + if (versionStr == null) { + return true; + } + if (versionStr.equals(PinotVersion.UNKNOWN)) { Review Comment: This can be a little bit dangerous because stats will be disabled even if all versions are the same. Do you know when version is unavailable? ########## pinot-server/src/main/java/org/apache/pinot/server/starter/helix/SendStatsPredicate.java: ########## @@ -0,0 +1,160 @@ +/** + * 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.List; +import java.util.Locale; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.Nullable; +import org.apache.helix.NotificationContext; +import org.apache.helix.api.listeners.InstanceConfigChangeListener; +import org.apache.helix.model.InstanceConfig; +import org.apache.pinot.common.version.PinotVersion; +import org.apache.pinot.spi.env.PinotConfiguration; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public abstract class SendStatsPredicate implements InstanceConfigChangeListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SendStatsPredicate.class); + + public abstract boolean getSendStats(); + + public static SendStatsPredicate create(PinotConfiguration configuration) { + String modeStr = configuration.getProperty( + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE, + CommonConstants.MultiStageQueryRunner.DEFAULT_SEND_STATS_MODE).toUpperCase(Locale.ENGLISH); + for (Mode mode : Mode.values()) { + if (mode.name().equals(modeStr)) { + return mode.create(); + } + } + + throw new IllegalStateException("Invalid value " + modeStr + " for " + + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE); + } + + public enum Mode { + SAFE { + @Override + public SendStatsPredicate create() { + return new Safe(); + } + }, + ALWAYS { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }, + NEVER { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }; + + public abstract SendStatsPredicate create(); + } + + private static class Safe extends SendStatsPredicate { + private final AtomicBoolean _sendStats = new AtomicBoolean(true); + + @Override + public boolean getSendStats() { + return _sendStats.get(); + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + boolean sendStats = true; + // TODO: Right now we read all configs, while only broker and servers are actually important + // But it isn't clear how to detect for sure that an instance config belongs to a broker or server + for (InstanceConfig instanceConfig : instanceConfigs) { + String otherVersion = instanceConfig.getRecord() + .getStringField(CommonConstants.Helix.Instance.PINOT_VERSION_KEY, null); + if (otherVersion == null || otherVersion.equals(PinotVersion.UNKNOWN)) { + LOGGER.warn("Instance {} does not have version", instanceConfig.getInstanceName()); + continue; + } + if (isProblematicVersion(otherVersion)) { + LOGGER.info("Found problematic version {} on instance {}. Stats may not be recognized", otherVersion, + instanceConfig.getInstanceName()); + sendStats = false; + break; + } + } + if (_sendStats.getAndSet(sendStats) != sendStats) { + LOGGER.warn("Send MSE stats is now {}", sendStats ? "enabled" : "disabled"); + } + } + + /// Returns true if the version is problematic Review Comment: (minor) Consider keeping the same javadoc convention for consistency ########## pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java: ########## @@ -1475,6 +1476,23 @@ public static class MultiStageQueryRunner { public static final String KEY_OF_MAX_ROWS_IN_JOIN = "pinot.query.join.max.rows"; public static final String KEY_OF_JOIN_OVERFLOW_MODE = "pinot.query.join.overflow.mode"; + /// Specifies the send stats mode used in MSE. + /// + /// Valid values are: + /// - "safe": MSE will only send stats if all instances in the cluster are running 1.4.0 or later. Review Comment: (minor) Since it is enum, use upper case is more readable IMO ########## pinot-server/src/main/java/org/apache/pinot/server/starter/helix/SendStatsPredicate.java: ########## @@ -0,0 +1,160 @@ +/** + * 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.List; +import java.util.Locale; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.Nullable; +import org.apache.helix.NotificationContext; +import org.apache.helix.api.listeners.InstanceConfigChangeListener; +import org.apache.helix.model.InstanceConfig; +import org.apache.pinot.common.version.PinotVersion; +import org.apache.pinot.spi.env.PinotConfiguration; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public abstract class SendStatsPredicate implements InstanceConfigChangeListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SendStatsPredicate.class); + + public abstract boolean getSendStats(); + + public static SendStatsPredicate create(PinotConfiguration configuration) { + String modeStr = configuration.getProperty( + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE, + CommonConstants.MultiStageQueryRunner.DEFAULT_SEND_STATS_MODE).toUpperCase(Locale.ENGLISH); + for (Mode mode : Mode.values()) { + if (mode.name().equals(modeStr)) { + return mode.create(); + } + } + + throw new IllegalStateException("Invalid value " + modeStr + " for " + + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE); + } + + public enum Mode { + SAFE { + @Override + public SendStatsPredicate create() { + return new Safe(); + } + }, + ALWAYS { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }, + NEVER { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }; + + public abstract SendStatsPredicate create(); + } + + private static class Safe extends SendStatsPredicate { + private final AtomicBoolean _sendStats = new AtomicBoolean(true); + + @Override + public boolean getSendStats() { + return _sendStats.get(); + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + boolean sendStats = true; + // TODO: Right now we read all configs, while only broker and servers are actually important + // But it isn't clear how to detect for sure that an instance config belongs to a broker or server + for (InstanceConfig instanceConfig : instanceConfigs) { + String otherVersion = instanceConfig.getRecord() + .getStringField(CommonConstants.Helix.Instance.PINOT_VERSION_KEY, null); + if (otherVersion == null || otherVersion.equals(PinotVersion.UNKNOWN)) { + LOGGER.warn("Instance {} does not have version", instanceConfig.getInstanceName()); + continue; + } + if (isProblematicVersion(otherVersion)) { + LOGGER.info("Found problematic version {} on instance {}. Stats may not be recognized", otherVersion, + instanceConfig.getInstanceName()); + sendStats = false; + break; + } + } + if (_sendStats.getAndSet(sendStats) != sendStats) { + LOGGER.warn("Send MSE stats is now {}", sendStats ? "enabled" : "disabled"); + } + } + + /// Returns true if the version is problematic + /// + /// Ideally [PinotVersion] should have a way to extract versions in comparable format, but given it doesn't we + /// need to parse the string here. In case version doesn't match `1\.x\..*`, we treat is as a problematic version + private boolean isProblematicVersion(@Nullable String versionStr) { + if (versionStr == null) { + return true; + } + if (versionStr.equals(PinotVersion.UNKNOWN)) { Review Comment: Seems like we will never hit this line ########## pinot-server/src/main/java/org/apache/pinot/server/starter/helix/SendStatsPredicate.java: ########## @@ -0,0 +1,160 @@ +/** + * 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.List; +import java.util.Locale; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.Nullable; +import org.apache.helix.NotificationContext; +import org.apache.helix.api.listeners.InstanceConfigChangeListener; +import org.apache.helix.model.InstanceConfig; +import org.apache.pinot.common.version.PinotVersion; +import org.apache.pinot.spi.env.PinotConfiguration; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public abstract class SendStatsPredicate implements InstanceConfigChangeListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SendStatsPredicate.class); + + public abstract boolean getSendStats(); + + public static SendStatsPredicate create(PinotConfiguration configuration) { + String modeStr = configuration.getProperty( + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE, + CommonConstants.MultiStageQueryRunner.DEFAULT_SEND_STATS_MODE).toUpperCase(Locale.ENGLISH); + for (Mode mode : Mode.values()) { + if (mode.name().equals(modeStr)) { + return mode.create(); + } + } + + throw new IllegalStateException("Invalid value " + modeStr + " for " + + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE); + } + + public enum Mode { + SAFE { + @Override + public SendStatsPredicate create() { + return new Safe(); + } + }, + ALWAYS { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }, + NEVER { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }; + + public abstract SendStatsPredicate create(); + } + + private static class Safe extends SendStatsPredicate { + private final AtomicBoolean _sendStats = new AtomicBoolean(true); + + @Override + public boolean getSendStats() { + return _sendStats.get(); + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + boolean sendStats = true; + // TODO: Right now we read all configs, while only broker and servers are actually important + // But it isn't clear how to detect for sure that an instance config belongs to a broker or server + for (InstanceConfig instanceConfig : instanceConfigs) { + String otherVersion = instanceConfig.getRecord() + .getStringField(CommonConstants.Helix.Instance.PINOT_VERSION_KEY, null); + if (otherVersion == null || otherVersion.equals(PinotVersion.UNKNOWN)) { + LOGGER.warn("Instance {} does not have version", instanceConfig.getInstanceName()); Review Comment: This could flood the log during rolling restart (server setting `shutDownInProgress` flag) in large cluster. Consider logging a summary line per callback ########## pinot-server/src/main/java/org/apache/pinot/server/starter/helix/SendStatsPredicate.java: ########## @@ -0,0 +1,160 @@ +/** + * 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.List; +import java.util.Locale; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.Nullable; +import org.apache.helix.NotificationContext; +import org.apache.helix.api.listeners.InstanceConfigChangeListener; +import org.apache.helix.model.InstanceConfig; +import org.apache.pinot.common.version.PinotVersion; +import org.apache.pinot.spi.env.PinotConfiguration; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public abstract class SendStatsPredicate implements InstanceConfigChangeListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SendStatsPredicate.class); + + public abstract boolean getSendStats(); + + public static SendStatsPredicate create(PinotConfiguration configuration) { + String modeStr = configuration.getProperty( + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE, + CommonConstants.MultiStageQueryRunner.DEFAULT_SEND_STATS_MODE).toUpperCase(Locale.ENGLISH); + for (Mode mode : Mode.values()) { + if (mode.name().equals(modeStr)) { + return mode.create(); + } + } + + throw new IllegalStateException("Invalid value " + modeStr + " for " + + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE); + } + + public enum Mode { + SAFE { + @Override + public SendStatsPredicate create() { + return new Safe(); + } + }, + ALWAYS { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }, + NEVER { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }; + + public abstract SendStatsPredicate create(); + } + + private static class Safe extends SendStatsPredicate { + private final AtomicBoolean _sendStats = new AtomicBoolean(true); + + @Override + public boolean getSendStats() { + return _sendStats.get(); + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + boolean sendStats = true; + // TODO: Right now we read all configs, while only broker and servers are actually important + // But it isn't clear how to detect for sure that an instance config belongs to a broker or server + for (InstanceConfig instanceConfig : instanceConfigs) { + String otherVersion = instanceConfig.getRecord() + .getStringField(CommonConstants.Helix.Instance.PINOT_VERSION_KEY, null); + if (otherVersion == null || otherVersion.equals(PinotVersion.UNKNOWN)) { + LOGGER.warn("Instance {} does not have version", instanceConfig.getInstanceName()); Review Comment: This doesn't seems correct. We shouldn't skip `null` because `null` is unsafe ########## pinot-server/src/main/java/org/apache/pinot/server/starter/helix/SendStatsPredicate.java: ########## @@ -0,0 +1,160 @@ +/** + * 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.List; +import java.util.Locale; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.Nullable; +import org.apache.helix.NotificationContext; +import org.apache.helix.api.listeners.InstanceConfigChangeListener; +import org.apache.helix.model.InstanceConfig; +import org.apache.pinot.common.version.PinotVersion; +import org.apache.pinot.spi.env.PinotConfiguration; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public abstract class SendStatsPredicate implements InstanceConfigChangeListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SendStatsPredicate.class); + + public abstract boolean getSendStats(); + + public static SendStatsPredicate create(PinotConfiguration configuration) { + String modeStr = configuration.getProperty( + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE, + CommonConstants.MultiStageQueryRunner.DEFAULT_SEND_STATS_MODE).toUpperCase(Locale.ENGLISH); + for (Mode mode : Mode.values()) { + if (mode.name().equals(modeStr)) { + return mode.create(); + } + } + + throw new IllegalStateException("Invalid value " + modeStr + " for " + + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE); + } + + public enum Mode { + SAFE { + @Override + public SendStatsPredicate create() { + return new Safe(); + } + }, + ALWAYS { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }, + NEVER { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }; + + public abstract SendStatsPredicate create(); + } + + private static class Safe extends SendStatsPredicate { + private final AtomicBoolean _sendStats = new AtomicBoolean(true); + + @Override + public boolean getSendStats() { + return _sendStats.get(); + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + boolean sendStats = true; + // TODO: Right now we read all configs, while only broker and servers are actually important Review Comment: You should be able to use `InstanceTypeUtils` ########## pinot-server/src/main/java/org/apache/pinot/server/starter/helix/SendStatsPredicate.java: ########## @@ -0,0 +1,160 @@ +/** + * 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.List; +import java.util.Locale; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.Nullable; +import org.apache.helix.NotificationContext; +import org.apache.helix.api.listeners.InstanceConfigChangeListener; +import org.apache.helix.model.InstanceConfig; +import org.apache.pinot.common.version.PinotVersion; +import org.apache.pinot.spi.env.PinotConfiguration; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public abstract class SendStatsPredicate implements InstanceConfigChangeListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SendStatsPredicate.class); + + public abstract boolean getSendStats(); + + public static SendStatsPredicate create(PinotConfiguration configuration) { + String modeStr = configuration.getProperty( + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE, + CommonConstants.MultiStageQueryRunner.DEFAULT_SEND_STATS_MODE).toUpperCase(Locale.ENGLISH); + for (Mode mode : Mode.values()) { + if (mode.name().equals(modeStr)) { + return mode.create(); + } + } + + throw new IllegalStateException("Invalid value " + modeStr + " for " + + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE); + } + + public enum Mode { + SAFE { + @Override + public SendStatsPredicate create() { + return new Safe(); + } + }, + ALWAYS { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }, + NEVER { + @Override + public SendStatsPredicate create() { + return new SendStatsPredicate() { + @Override + public boolean getSendStats() { + return false; + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + // Nothing to do + } + }; + } + }; + + public abstract SendStatsPredicate create(); + } + + private static class Safe extends SendStatsPredicate { + private final AtomicBoolean _sendStats = new AtomicBoolean(true); + + @Override + public boolean getSendStats() { + return _sendStats.get(); + } + + @Override + public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) { + boolean sendStats = true; + // TODO: Right now we read all configs, while only broker and servers are actually important + // But it isn't clear how to detect for sure that an instance config belongs to a broker or server + for (InstanceConfig instanceConfig : instanceConfigs) { + String otherVersion = instanceConfig.getRecord() + .getStringField(CommonConstants.Helix.Instance.PINOT_VERSION_KEY, null); + if (otherVersion == null || otherVersion.equals(PinotVersion.UNKNOWN)) { + LOGGER.warn("Instance {} does not have version", instanceConfig.getInstanceName()); + continue; + } + if (isProblematicVersion(otherVersion)) { + LOGGER.info("Found problematic version {} on instance {}. Stats may not be recognized", otherVersion, + instanceConfig.getInstanceName()); + sendStats = false; + break; + } + } + if (_sendStats.getAndSet(sendStats) != sendStats) { + LOGGER.warn("Send MSE stats is now {}", sendStats ? "enabled" : "disabled"); + } + } + + /// Returns true if the version is problematic + /// + /// Ideally [PinotVersion] should have a way to extract versions in comparable format, but given it doesn't we + /// need to parse the string here. In case version doesn't match `1\.x\..*`, we treat is as a problematic version + private boolean isProblematicVersion(@Nullable String versionStr) { + if (versionStr == null) { + return true; + } + if (versionStr.equals(PinotVersion.UNKNOWN)) { + return true; + } + // Lets try to parse 1.x versions Review Comment: Do we need the following check? If the version is present, it is safe version right? ########## pinot-server/src/main/java/org/apache/pinot/server/starter/helix/SendStatsPredicate.java: ########## @@ -0,0 +1,160 @@ +/** + * 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.List; +import java.util.Locale; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.Nullable; +import org.apache.helix.NotificationContext; +import org.apache.helix.api.listeners.InstanceConfigChangeListener; +import org.apache.helix.model.InstanceConfig; +import org.apache.pinot.common.version.PinotVersion; +import org.apache.pinot.spi.env.PinotConfiguration; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public abstract class SendStatsPredicate implements InstanceConfigChangeListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SendStatsPredicate.class); + + public abstract boolean getSendStats(); + + public static SendStatsPredicate create(PinotConfiguration configuration) { + String modeStr = configuration.getProperty( + CommonConstants.MultiStageQueryRunner.KEY_OF_SEND_STATS_MODE, + CommonConstants.MultiStageQueryRunner.DEFAULT_SEND_STATS_MODE).toUpperCase(Locale.ENGLISH); + for (Mode mode : Mode.values()) { Review Comment: (minor) Can we use `Mode.valueOf()`? -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org