This is an automated email from the ASF dual-hosted git repository.

gortiz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 6ff9e013892 Make DefaultClusterConfigChangeHandler thread safe (#16778)
6ff9e013892 is described below

commit 6ff9e013892f0eed10cffaf63e958ddb36aef0ff
Author: Gonzalo Ortiz Jaureguizar <[email protected]>
AuthorDate: Wed Sep 10 15:11:44 2025 +0200

    Make DefaultClusterConfigChangeHandler thread safe (#16778)
---
 .../config/DefaultClusterConfigChangeHandler.java  | 24 ++++++++++++----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git 
a/pinot-common/src/main/java/org/apache/pinot/common/config/DefaultClusterConfigChangeHandler.java
 
b/pinot-common/src/main/java/org/apache/pinot/common/config/DefaultClusterConfigChangeHandler.java
index 0314029e69b..5024d781bde 100644
--- 
a/pinot-common/src/main/java/org/apache/pinot/common/config/DefaultClusterConfigChangeHandler.java
+++ 
b/pinot-common/src/main/java/org/apache/pinot/common/config/DefaultClusterConfigChangeHandler.java
@@ -18,11 +18,11 @@
  */
 package org.apache.pinot.common.config;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
 import org.apache.helix.NotificationContext;
 import org.apache.helix.api.listeners.BatchMode;
 import org.apache.helix.api.listeners.ClusterConfigChangeListener;
@@ -37,12 +37,12 @@ import org.slf4j.LoggerFactory;
 public class DefaultClusterConfigChangeHandler implements 
ClusterConfigChangeListener, PinotClusterConfigProvider {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(DefaultClusterConfigChangeHandler.class);
 
-  private volatile Map<String, String> _properties;
-  private final List<PinotClusterConfigChangeListener> 
_clusterConfigChangeListeners;
+  private volatile ImmutableMap<String, String> _properties;
+  private final CopyOnWriteArrayList<PinotClusterConfigChangeListener> 
_clusterConfigChangeListeners;
 
   public DefaultClusterConfigChangeHandler() {
-    _properties = new HashMap<>();
-    _clusterConfigChangeListeners = new ArrayList<>();
+    _properties = ImmutableMap.of();
+    _clusterConfigChangeListeners = new CopyOnWriteArrayList<>();
   }
 
   @Override
@@ -53,13 +53,15 @@ public class DefaultClusterConfigChangeHandler implements 
ClusterConfigChangeLis
   }
 
   private synchronized void process(Map<String, String> properties) {
-    Set<String> changedProperties = getChangedProperties(_properties, 
properties);
-    _properties = properties;
-    _clusterConfigChangeListeners.forEach(l -> l.onChange(changedProperties, 
_properties));
+    Set<String> changedProperties = 
ImmutableSet.copyOf(getChangedProperties(_properties, properties));
+    _properties = ImmutableMap.copyOf(properties);
+    for (PinotClusterConfigChangeListener listener : 
_clusterConfigChangeListeners) {
+      listener.onChange(changedProperties, _properties);
+    }
   }
 
   @Override
-  public Map<String, String> getClusterConfigs() {
+  public ImmutableMap<String, String> getClusterConfigs() {
     return _properties;
   }
 


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

Reply via email to