somandal commented on code in PR #14894: URL: https://github.com/apache/pinot/pull/14894#discussion_r1927431058
########## pinot-server/src/main/java/org/apache/pinot/server/starter/helix/DefaultClusterConfigChangeHandler.java: ########## @@ -0,0 +1,86 @@ +/** + * 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.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.helix.HelixManager; +import org.apache.helix.HelixManagerFactory; +import org.apache.helix.InstanceType; +import org.apache.helix.NotificationContext; +import org.apache.helix.api.listeners.BatchMode; +import org.apache.helix.api.listeners.ClusterConfigChangeListener; +import org.apache.helix.model.ClusterConfig; +import org.apache.pinot.spi.config.provider.PinotClusterConfigChangeListener; +import org.apache.pinot.spi.config.provider.PinotClusterConfigProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +@BatchMode(enabled = false) +public class DefaultClusterConfigChangeHandler implements ClusterConfigChangeListener, PinotClusterConfigProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultClusterConfigChangeHandler.class); + + private volatile Map<String, String> _properties; + private final Set<PinotClusterConfigChangeListener> _clusterConfigChangeListeners = ConcurrentHashMap.newKeySet(); Review Comment: I changed it to be a `HashSet` instead of concurrent set. I still don't want to register duplicate objects, so thought set is better than `ArrayList` here. ########## pinot-server/src/main/java/org/apache/pinot/server/starter/helix/DefaultClusterConfigChangeHandler.java: ########## @@ -0,0 +1,86 @@ +/** + * 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.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.helix.HelixManager; +import org.apache.helix.HelixManagerFactory; +import org.apache.helix.InstanceType; +import org.apache.helix.NotificationContext; +import org.apache.helix.api.listeners.BatchMode; +import org.apache.helix.api.listeners.ClusterConfigChangeListener; +import org.apache.helix.model.ClusterConfig; +import org.apache.pinot.spi.config.provider.PinotClusterConfigChangeListener; +import org.apache.pinot.spi.config.provider.PinotClusterConfigProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +@BatchMode(enabled = false) +public class DefaultClusterConfigChangeHandler implements ClusterConfigChangeListener, PinotClusterConfigProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultClusterConfigChangeHandler.class); + + private volatile Map<String, String> _properties; + private final Set<PinotClusterConfigChangeListener> _clusterConfigChangeListeners = ConcurrentHashMap.newKeySet(); + + public void init(String zkAddress, String clusterName) { + LOGGER.info("Handling Cluster ConfigChanges: INIT START"); + try { + HelixManager helixManager = + HelixManagerFactory.getZKHelixManager(clusterName, "admin", InstanceType.ADMINISTRATOR, zkAddress); + helixManager.connect(); + ClusterConfig clusterConfig = helixManager.getConfigAccessor().getClusterConfig(clusterName); + process(clusterConfig.getRecord().getSimpleFields()); + helixManager.disconnect(); + } catch (Exception e) { + LOGGER.error("Exception while initializing DefaultClusterConfigChangeHandler for zk: {} and clusterName: {}", + zkAddress, clusterName, e); + } + LOGGER.info("Handling Cluster ConfigChanges: INIT END"); + } + + @Override + public void onClusterConfigChange(ClusterConfig clusterConfig, NotificationContext notificationContext) { + LOGGER.info("Handling Cluster ConfigChanges: CALLBACK START"); + process(clusterConfig.getRecord().getSimpleFields()); + LOGGER.info("Handling Cluster ConfigChanges: CALLBACK DONE"); + } + + private void process(Map<String, String> properties) { Review Comment: yes good point, done -- 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