You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2020/09/15 19:54:19 UTC

[GitHub] [incubator-pinot] KKcorps opened a new pull request #6020: Add Caching in Controller Broker API

KKcorps opened a new pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020


   Currently, Controller does multiple calls to zookeeper to fetch the list of brokers per tenant and table. This PR aims to cache the instance configs of zookeeper so that the calls don't go always.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#issuecomment-702888304


   @mcvsubbu The issue is the changes are needed for new /Brokers api.
   The plan is to call the API to fetch the brokers for a tenant from JDBC driver. The current implementation requires too many calls to zookeeper. 
   I was not aware of the watchers concern though. @kishoreg @fx19880617 What should we do about this?


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#issuecomment-702350789


   @Jackie-Jiang Can you take a look at this PR?


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r495919782



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -2458,6 +2486,7 @@ private void waitForSegmentsBecomeOnline(String tableNameWithType, Set<String> s
     return onlineSegments;
   }
 
+

Review comment:
       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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#issuecomment-704448410


   Closing this PR! 


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps closed pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps closed pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r495917780



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -223,6 +228,16 @@ public synchronized void start(HelixManager helixZkManager) {
     boolean caseInsensitive = Boolean.parseBoolean(configs.get(Helix.ENABLE_CASE_INSENSITIVE_KEY)) || Boolean
         .parseBoolean(configs.get(Helix.DEPRECATED_ENABLE_CASE_INSENSITIVE_KEY));
     _tableCache = new TableCache(_propertyStore, caseInsensitive);
+
+    _clusterInstanceConfigChangeListener = new ClusterInstanceConfigChangeListener(_helixZkManager);
+    _clusterLiveInstanceChangeListener = new ClusterLiveInstanceChangeListener(_helixDataAccessor, _keyBuilder);
+    try {
+      addConfigListeners(_clusterInstanceConfigChangeListener);
+      addLiveInstanceListeners(_clusterLiveInstanceChangeListener);
+    } catch (Exception e) {
+      LOGGER.warn(
+          "Unable to add config listener in controller. This will result in incorrect response from controller's broker API");

Review comment:
       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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] Jackie-Jiang commented on pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
Jackie-Jiang commented on pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#issuecomment-703157496


   Find an old issue related to caching the configs: https://github.com/apache/incubator-pinot/issues/4665


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r491796919



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterLiveInstanceChangeListener.java
##########
@@ -0,0 +1,34 @@
+package org.apache.pinot.controller.helix.core.listener;
+
+import java.util.ArrayList;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.LiveInstanceChangeListener;
+import org.apache.helix.model.LiveInstance;
+
+import java.util.List;
+import org.apache.helix.PropertyKey.Builder;
+
+
+public class ClusterLiveInstanceChangeListener implements LiveInstanceChangeListener {
+  private HelixDataAccessor _helixDataAccessor;
+  private Builder _keyBuilder;
+  private List<LiveInstance> _liveInstances = new ArrayList<>();
+
+  public ClusterLiveInstanceChangeListener(HelixDataAccessor helixDataAccessor, Builder keyBuilder) {
+    _helixDataAccessor = helixDataAccessor;
+    _keyBuilder = keyBuilder;
+  }
+
+  @Override
+  public void onLiveInstanceChange(List<LiveInstance> liveInstances, NotificationContext changeContext) {
+    _liveInstances = liveInstances;

Review comment:
       This was returning older values rather than updated values in onChange methoda.

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,32 @@
+package org.apache.pinot.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+        _instanceConfigs = instanceConfigs;

Review comment:
       This was returning older values rather than updated values in onChange methoda.
   
   




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r498650655



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+    private Long _lastEventTimestamp = null;
+    private boolean _listenerInitiated = false;
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {

Review comment:
       done

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;

Review comment:
       done

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {

Review comment:
       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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] fx19880617 commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
fx19880617 commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r494081645



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -223,6 +228,16 @@ public synchronized void start(HelixManager helixZkManager) {
     boolean caseInsensitive = Boolean.parseBoolean(configs.get(Helix.ENABLE_CASE_INSENSITIVE_KEY)) || Boolean
         .parseBoolean(configs.get(Helix.DEPRECATED_ENABLE_CASE_INSENSITIVE_KEY));
     _tableCache = new TableCache(_propertyStore, caseInsensitive);
+
+    _clusterInstanceConfigChangeListener = new ClusterInstanceConfigChangeListener(_helixZkManager);
+    _clusterLiveInstanceChangeListener = new ClusterLiveInstanceChangeListener(_helixDataAccessor, _keyBuilder);
+    try {
+      addConfigListeners(_clusterInstanceConfigChangeListener);
+      addLiveInstanceListeners(_clusterLiveInstanceChangeListener);
+    } catch (Exception e) {
+      LOGGER.warn(
+          "Unable to add config listener in controller. This will result in incorrect response from controller's broker API");

Review comment:
       1. separate the try catch and error msg for two listeners
   2. shall we consider to fallback to direct fetch api?

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -2458,6 +2486,7 @@ private void waitForSegmentsBecomeOnline(String tableNameWithType, Set<String> s
     return onlineSegments;
   }
 
+

Review comment:
       remove this

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -223,6 +228,16 @@ public synchronized void start(HelixManager helixZkManager) {
     boolean caseInsensitive = Boolean.parseBoolean(configs.get(Helix.ENABLE_CASE_INSENSITIVE_KEY)) || Boolean
         .parseBoolean(configs.get(Helix.DEPRECATED_ENABLE_CASE_INSENSITIVE_KEY));
     _tableCache = new TableCache(_propertyStore, caseInsensitive);
+
+    _clusterInstanceConfigChangeListener = new ClusterInstanceConfigChangeListener(_helixZkManager);
+    _clusterLiveInstanceChangeListener = new ClusterLiveInstanceChangeListener(_helixDataAccessor, _keyBuilder);
+    try {
+      addConfigListeners(_clusterInstanceConfigChangeListener);
+      addLiveInstanceListeners(_clusterLiveInstanceChangeListener);
+    } catch (Exception e) {
+      LOGGER.warn(
+          "Unable to add config listener in controller. This will result in incorrect response from controller's broker API");

Review comment:
       For *ChangeListener, shall we add a transparent mode, which allows the api to fetch information directly from helix?
   So in case of the listener register failure, pinot won't fail.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r498641677



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+    private Long _lastEventTimestamp = null;
+    private boolean _listenerInitiated = false;
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+        if(context.getType() == NotificationContext.Type.INIT){
+            _listenerInitiated = true;
+        }
+
+        if(_lastEventTimestamp == null || _lastEventTimestamp <= context.getCreationTime()) {
+            synchronized (this) {
+                _instanceConfigs = instanceConfigs;
+                _lastEventTimestamp = context.getCreationTime();
+            }
+        }

Review comment:
       Actually, this is required.  Earlier the code was what you suggested but two issues were occurring - 
   * out of order events
   * empty instance config returned when the listener was not initiated.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] fx19880617 commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
fx19880617 commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r496263638



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -223,6 +228,16 @@ public synchronized void start(HelixManager helixZkManager) {
     boolean caseInsensitive = Boolean.parseBoolean(configs.get(Helix.ENABLE_CASE_INSENSITIVE_KEY)) || Boolean
         .parseBoolean(configs.get(Helix.DEPRECATED_ENABLE_CASE_INSENSITIVE_KEY));
     _tableCache = new TableCache(_propertyStore, caseInsensitive);
+
+    _clusterInstanceConfigChangeListener = new ClusterInstanceConfigChangeListener(_helixZkManager);
+    _clusterLiveInstanceChangeListener = new ClusterLiveInstanceChangeListener(_helixDataAccessor, _keyBuilder);
+    try {
+      addConfigListeners(_clusterInstanceConfigChangeListener);
+      addLiveInstanceListeners(_clusterLiveInstanceChangeListener);
+    } catch (Exception e) {

Review comment:
       shall we separate the listener register into two try-catch?
   So if first one failed, the second one can still work or make something like a delayed retry if you want to make this logic perfect :)




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] fx19880617 commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
fx19880617 commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r496265520



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,59 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+    private Long _lastEventTimestamp = null;
+    private boolean _listenerInitiated = false;
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+        if(context.getType() == NotificationContext.Type.INIT){
+            _listenerInitiated = true;
+        }
+
+        if(_lastEventTimestamp == null || _lastEventTimestamp <= context.getCreationTime()) {
+            _instanceConfigs = instanceConfigs;
+            _lastEventTimestamp = context.getCreationTime();
+        }
+    }
+
+    public List<InstanceConfig> getInstanceConfigs() {
+        if(_instanceConfigs.isEmpty() || !_listenerInitiated){
+            _instanceConfigs = HelixHelper.getInstanceConfigs(_helixManager);

Review comment:
       will there be a race condition that _instanceConfigs is set by both  `onInstanceConfigChange` and `getInstanceConfigs` ?
   
   Shall we put a lock?
   




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] fx19880617 commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
fx19880617 commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r489717878



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,32 @@
+package org.apache.pinot.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+        _instanceConfigs = instanceConfigs;
+    }
+
+    public List<InstanceConfig> getInstanceConfigs() {
+        if(_instanceConfigs.isEmpty()){

Review comment:
       don't set instanceConfig in get call




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r498706060



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+    private Long _lastEventTimestamp = null;
+    private boolean _listenerInitiated = false;
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+        if(context.getType() == NotificationContext.Type.INIT){
+            _listenerInitiated = true;
+        }
+
+        if(_lastEventTimestamp == null || _lastEventTimestamp <= context.getCreationTime()) {
+            synchronized (this) {
+                _instanceConfigs = instanceConfigs;
+                _lastEventTimestamp = context.getCreationTime();
+            }
+        }
+    }
+
+    public List<InstanceConfig> getInstanceConfigs() {
+        if(_instanceConfigs.isEmpty() || !_listenerInitiated){
+            synchronized (this) {
+                _instanceConfigs = HelixHelper.getInstanceConfigs(_helixManager);
+            }
+        }
+        return _instanceConfigs;

Review comment:
       resolved




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r491796919



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterLiveInstanceChangeListener.java
##########
@@ -0,0 +1,34 @@
+package org.apache.pinot.controller.helix.core.listener;
+
+import java.util.ArrayList;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.LiveInstanceChangeListener;
+import org.apache.helix.model.LiveInstance;
+
+import java.util.List;
+import org.apache.helix.PropertyKey.Builder;
+
+
+public class ClusterLiveInstanceChangeListener implements LiveInstanceChangeListener {
+  private HelixDataAccessor _helixDataAccessor;
+  private Builder _keyBuilder;
+  private List<LiveInstance> _liveInstances = new ArrayList<>();
+
+  public ClusterLiveInstanceChangeListener(HelixDataAccessor helixDataAccessor, Builder keyBuilder) {
+    _helixDataAccessor = helixDataAccessor;
+    _keyBuilder = keyBuilder;
+  }
+
+  @Override
+  public void onLiveInstanceChange(List<LiveInstance> liveInstances, NotificationContext changeContext) {
+    _liveInstances = liveInstances;

Review comment:
       This was returning older values rather than updated values in onChange methoda.

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,32 @@
+package org.apache.pinot.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+        _instanceConfigs = instanceConfigs;

Review comment:
       This was returning older values rather than updated values in onChange methoda.
   
   

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,32 @@
+package org.apache.pinot.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;

Review comment:
       Returns null or empty list

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,32 @@
+package org.apache.pinot.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+        _instanceConfigs = instanceConfigs;
+    }
+
+    public List<InstanceConfig> getInstanceConfigs() {
+        if(_instanceConfigs.isEmpty()){

Review comment:
       Returns null or empty list




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r498641247



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -2174,13 +2192,42 @@ public boolean instanceExists(String instanceName) {
    */
   public List<String> getOnlineUnTaggedServerInstanceList() {
     List<String> instanceList = HelixHelper.getInstancesWithTag(_helixZkManager, Helix.UNTAGGED_SERVER_INSTANCE);
-    List<String> liveInstances = _helixDataAccessor.getChildNames(_keyBuilder.liveInstances());
+    List<String> liveInstances = getOnlineInstanceList();
     instanceList.retainAll(liveInstances);
     return instanceList;
   }
 
   public List<String> getOnlineInstanceList() {
-    return _helixDataAccessor.getChildNames(_keyBuilder.liveInstances());
+    return _clusterLiveInstanceChangeListener.getLiveInstances().stream().map(LiveInstance::getInstanceName)
+        .collect(Collectors.toList());
+  }
+
+  public void addConfigListeners(ClusterInstanceConfigChangeListener clusterInstanceConfigChangeListener)
+      throws Exception {
+    RetryPolicies.exponentialBackoffRetryPolicy(3, 100, 5).attempt(() -> {

Review comment:
       I think keeping retry is a good option as this is a critical flow.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] Jackie-Jiang commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
Jackie-Jiang commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r499103367



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,59 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+  private final HelixManager _helixManager;
+  private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+  private Long _lastEventTimestamp = null;
+  private boolean _listenerInitiated = false;
+
+  public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+    _helixManager = helixManager;
+  }
+
+  @Override
+  public synchronized void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+    if (context.getType() == NotificationContext.Type.INIT) {
+      _listenerInitiated = true;
+    }
+
+    if (_lastEventTimestamp == null || _lastEventTimestamp <= context.getCreationTime()) {
+      _instanceConfigs = instanceConfigs;
+      _lastEventTimestamp = context.getCreationTime();
+    }
+  }
+
+  public synchronized List<InstanceConfig> getInstanceConfigs() {

Review comment:
       Don't make this method `synchronized`, this method can be called concurrently

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,59 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+  private final HelixManager _helixManager;
+  private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+  private Long _lastEventTimestamp = null;
+  private boolean _listenerInitiated = false;
+
+  public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+    _helixManager = helixManager;
+  }
+
+  @Override
+  public synchronized void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+    if (context.getType() == NotificationContext.Type.INIT) {
+      _listenerInitiated = true;
+    }
+
+    if (_lastEventTimestamp == null || _lastEventTimestamp <= context.getCreationTime()) {
+      _instanceConfigs = instanceConfigs;
+      _lastEventTimestamp = context.getCreationTime();
+    }
+  }
+
+  public synchronized List<InstanceConfig> getInstanceConfigs() {
+    if (_instanceConfigs.isEmpty() || !_listenerInitiated) {

Review comment:
       I don't think you need to maintain `_listenerInitiated`, checking `_instanceConfigs.isEmpty()` should be enough.

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,59 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+  private final HelixManager _helixManager;
+  private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+  private Long _lastEventTimestamp = null;

Review comment:
       (nit) we can use primitive type here and initialize it to `Long.MIN_VALUE`

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,59 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+  private final HelixManager _helixManager;
+  private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+  private Long _lastEventTimestamp = null;
+  private boolean _listenerInitiated = false;
+
+  public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+    _helixManager = helixManager;
+  }
+
+  @Override
+  public synchronized void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+    if (context.getType() == NotificationContext.Type.INIT) {
+      _listenerInitiated = true;
+    }
+
+    if (_lastEventTimestamp == null || _lastEventTimestamp <= context.getCreationTime()) {

Review comment:
       I'm quite surprised to know that the `creationTime` could go back when Helix is using single thread to handle the callbacks. Even in that case, I still think we don't need to check this time as the config fetch happens just before calling this method. Check Helix `CallbackHandler.invoke()`.

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,59 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+  private final HelixManager _helixManager;
+  private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+  private Long _lastEventTimestamp = null;
+  private boolean _listenerInitiated = false;
+
+  public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+    _helixManager = helixManager;
+  }
+
+  @Override
+  public synchronized void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+    if (context.getType() == NotificationContext.Type.INIT) {

Review comment:
       Is the `instanceConfigs` always empty when it is an `INIT` type callback? Please double check because I don't think that is the case, where `INIT` should give the current `instanceConfigs` in the cluster.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] fx19880617 commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
fx19880617 commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r489717662



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,32 @@
+package org.apache.pinot.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+        _instanceConfigs = instanceConfigs;

Review comment:
       _instanceConfigs = HelixHelper.getInstanceConfigs(_helixManager);




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r496623617



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -223,6 +228,16 @@ public synchronized void start(HelixManager helixZkManager) {
     boolean caseInsensitive = Boolean.parseBoolean(configs.get(Helix.ENABLE_CASE_INSENSITIVE_KEY)) || Boolean
         .parseBoolean(configs.get(Helix.DEPRECATED_ENABLE_CASE_INSENSITIVE_KEY));
     _tableCache = new TableCache(_propertyStore, caseInsensitive);
+
+    _clusterInstanceConfigChangeListener = new ClusterInstanceConfigChangeListener(_helixZkManager);
+    _clusterLiveInstanceChangeListener = new ClusterLiveInstanceChangeListener(_helixDataAccessor, _keyBuilder);
+    try {
+      addConfigListeners(_clusterInstanceConfigChangeListener);
+      addLiveInstanceListeners(_clusterLiveInstanceChangeListener);
+    } catch (Exception e) {

Review comment:
       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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] fx19880617 commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
fx19880617 commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r496265728



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterLiveInstanceChangeListener.java
##########
@@ -0,0 +1,61 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import java.util.ArrayList;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.LiveInstanceChangeListener;
+import org.apache.helix.model.LiveInstance;
+
+import java.util.List;
+import org.apache.helix.PropertyKey.Builder;
+
+
+public class ClusterLiveInstanceChangeListener implements LiveInstanceChangeListener {
+  private HelixDataAccessor _helixDataAccessor;
+  private Builder _keyBuilder;
+  private List<LiveInstance> _liveInstances = new ArrayList<>();
+  private Long _lastEventTimestamp = null;
+  private boolean _listenerInitiated = false;
+
+  public ClusterLiveInstanceChangeListener(HelixDataAccessor helixDataAccessor, Builder keyBuilder) {
+    _helixDataAccessor = helixDataAccessor;
+    _keyBuilder = keyBuilder;
+  }
+
+  @Override
+  public void onLiveInstanceChange(List<LiveInstance> liveInstances, NotificationContext changeContext) {

Review comment:
       shall we have a lock for onLiveInstanceChange and getLiveInstances




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] mcvsubbu commented on pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
mcvsubbu commented on pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#issuecomment-703716431


   > @mcvsubbu I don't think this change will add more watchers though. These watchers are always set by Helix, and we are just registering some extra callbacks to Helix
   
   That is not true. We have separated Helix and pinot controllers. The watches are registered by helix controllers. Pinot controllers have zero watches in them


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] fx19880617 commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
fx19880617 commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r489717469



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterLiveInstanceChangeListener.java
##########
@@ -0,0 +1,34 @@
+package org.apache.pinot.controller.helix.core.listener;
+
+import java.util.ArrayList;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.LiveInstanceChangeListener;
+import org.apache.helix.model.LiveInstance;
+
+import java.util.List;
+import org.apache.helix.PropertyKey.Builder;
+
+
+public class ClusterLiveInstanceChangeListener implements LiveInstanceChangeListener {
+  private HelixDataAccessor _helixDataAccessor;
+  private Builder _keyBuilder;
+  private List<LiveInstance> _liveInstances = new ArrayList<>();
+
+  public ClusterLiveInstanceChangeListener(HelixDataAccessor helixDataAccessor, Builder keyBuilder) {
+    _helixDataAccessor = helixDataAccessor;
+    _keyBuilder = keyBuilder;
+  }
+
+  @Override
+  public void onLiveInstanceChange(List<LiveInstance> liveInstances, NotificationContext changeContext) {
+    _liveInstances = liveInstances;

Review comment:
       _liveInstances = _helixDataAccessor.getProperty(_keyBuilder.liveInstances());




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] mcvsubbu commented on pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
mcvsubbu commented on pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#issuecomment-703717382


   > @mcvsubbu The issue is the changes are needed for new /Brokers api.
   > The plan is to call the API to fetch the brokers for a tenant from JDBC driver. The current implementation requires too many calls to zookeeper.
   > I was not aware of the watchers concern though. @kishoreg @fx19880617 What should we do about this?
   
   Why is calls to zookeeper bad? How many calls is it? Zookeepers can handle a lot more calls to it than pinot controllers can.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r491797007



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,32 @@
+package org.apache.pinot.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;

Review comment:
       Returns null or empty list

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,32 @@
+package org.apache.pinot.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+        _instanceConfigs = instanceConfigs;
+    }
+
+    public List<InstanceConfig> getInstanceConfigs() {
+        if(_instanceConfigs.isEmpty()){

Review comment:
       Returns null or empty list




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r496623436



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,59 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+    private Long _lastEventTimestamp = null;
+    private boolean _listenerInitiated = false;
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+        if(context.getType() == NotificationContext.Type.INIT){
+            _listenerInitiated = true;
+        }
+
+        if(_lastEventTimestamp == null || _lastEventTimestamp <= context.getCreationTime()) {
+            _instanceConfigs = instanceConfigs;
+            _lastEventTimestamp = context.getCreationTime();
+        }
+    }
+
+    public List<InstanceConfig> getInstanceConfigs() {
+        if(_instanceConfigs.isEmpty() || !_listenerInitiated){
+            _instanceConfigs = HelixHelper.getInstanceConfigs(_helixManager);

Review comment:
       Looks better? Or should I keep synchronized with the whole method?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] fx19880617 commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
fx19880617 commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r494081645



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -223,6 +228,16 @@ public synchronized void start(HelixManager helixZkManager) {
     boolean caseInsensitive = Boolean.parseBoolean(configs.get(Helix.ENABLE_CASE_INSENSITIVE_KEY)) || Boolean
         .parseBoolean(configs.get(Helix.DEPRECATED_ENABLE_CASE_INSENSITIVE_KEY));
     _tableCache = new TableCache(_propertyStore, caseInsensitive);
+
+    _clusterInstanceConfigChangeListener = new ClusterInstanceConfigChangeListener(_helixZkManager);
+    _clusterLiveInstanceChangeListener = new ClusterLiveInstanceChangeListener(_helixDataAccessor, _keyBuilder);
+    try {
+      addConfigListeners(_clusterInstanceConfigChangeListener);
+      addLiveInstanceListeners(_clusterLiveInstanceChangeListener);
+    } catch (Exception e) {
+      LOGGER.warn(
+          "Unable to add config listener in controller. This will result in incorrect response from controller's broker API");

Review comment:
       1. separate the try catch and error msg for two listeners
   2. shall we consider to fallback to direct fetch api?

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -2458,6 +2486,7 @@ private void waitForSegmentsBecomeOnline(String tableNameWithType, Set<String> s
     return onlineSegments;
   }
 
+

Review comment:
       remove this

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -223,6 +228,16 @@ public synchronized void start(HelixManager helixZkManager) {
     boolean caseInsensitive = Boolean.parseBoolean(configs.get(Helix.ENABLE_CASE_INSENSITIVE_KEY)) || Boolean
         .parseBoolean(configs.get(Helix.DEPRECATED_ENABLE_CASE_INSENSITIVE_KEY));
     _tableCache = new TableCache(_propertyStore, caseInsensitive);
+
+    _clusterInstanceConfigChangeListener = new ClusterInstanceConfigChangeListener(_helixZkManager);
+    _clusterLiveInstanceChangeListener = new ClusterLiveInstanceChangeListener(_helixDataAccessor, _keyBuilder);
+    try {
+      addConfigListeners(_clusterInstanceConfigChangeListener);
+      addLiveInstanceListeners(_clusterLiveInstanceChangeListener);
+    } catch (Exception e) {
+      LOGGER.warn(
+          "Unable to add config listener in controller. This will result in incorrect response from controller's broker API");

Review comment:
       For *ChangeListener, shall we add a transparent mode, which allows the api to fetch information directly from helix?
   So in case of the listener register failure, pinot won't fail.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] Jackie-Jiang commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
Jackie-Jiang commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r498566599



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {

Review comment:
       Please fix the format and indentation for this class

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterLiveInstanceChangeListener.java
##########
@@ -0,0 +1,65 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import java.util.ArrayList;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.LiveInstanceChangeListener;
+import org.apache.helix.model.LiveInstance;
+
+import java.util.List;
+import org.apache.helix.PropertyKey.Builder;
+
+
+public class ClusterLiveInstanceChangeListener implements LiveInstanceChangeListener {

Review comment:
       Same as the comments in `ClusterInstanceConfigChangeListener`

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;

Review comment:
       ```suggestion
       private final HelixManager _helixManager;
   ```

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+    private Long _lastEventTimestamp = null;
+    private boolean _listenerInitiated = false;
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+        if(context.getType() == NotificationContext.Type.INIT){
+            _listenerInitiated = true;
+        }
+
+        if(_lastEventTimestamp == null || _lastEventTimestamp <= context.getCreationTime()) {
+            synchronized (this) {
+                _instanceConfigs = instanceConfigs;
+                _lastEventTimestamp = context.getCreationTime();
+            }
+        }

Review comment:
       I don't think we need to check the context, Helix should already handle them
   ```suggestion
           _instanceConfigs = instanceConfigs;
   ```

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+    private Long _lastEventTimestamp = null;
+    private boolean _listenerInitiated = false;
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {

Review comment:
       ```suggestion
       public synchronized void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
   ```

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+    private Long _lastEventTimestamp = null;
+    private boolean _listenerInitiated = false;
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
+        if(context.getType() == NotificationContext.Type.INIT){
+            _listenerInitiated = true;
+        }
+
+        if(_lastEventTimestamp == null || _lastEventTimestamp <= context.getCreationTime()) {
+            synchronized (this) {
+                _instanceConfigs = instanceConfigs;
+                _lastEventTimestamp = context.getCreationTime();
+            }
+        }
+    }
+
+    public List<InstanceConfig> getInstanceConfigs() {
+        if(_instanceConfigs.isEmpty() || !_listenerInitiated){
+            synchronized (this) {
+                _instanceConfigs = HelixHelper.getInstanceConfigs(_helixManager);
+            }
+        }
+        return _instanceConfigs;

Review comment:
       Don't store the fetched instanceConfigs into `_instanceConfigs`. We always use `_instanceConfigs` to cache the configs from the callback.
   ```suggestion
           if (_instanceConfigs.isEmpty()) {
               return HelixHelper.getInstanceConfigs(_helixManager);
           } else {
               return _instanceConfigs;
           }
   ```

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -2174,13 +2192,42 @@ public boolean instanceExists(String instanceName) {
    */
   public List<String> getOnlineUnTaggedServerInstanceList() {
     List<String> instanceList = HelixHelper.getInstancesWithTag(_helixZkManager, Helix.UNTAGGED_SERVER_INSTANCE);
-    List<String> liveInstances = _helixDataAccessor.getChildNames(_keyBuilder.liveInstances());
+    List<String> liveInstances = getOnlineInstanceList();
     instanceList.retainAll(liveInstances);
     return instanceList;
   }
 
   public List<String> getOnlineInstanceList() {
-    return _helixDataAccessor.getChildNames(_keyBuilder.liveInstances());
+    return _clusterLiveInstanceChangeListener.getLiveInstances().stream().map(LiveInstance::getInstanceName)
+        .collect(Collectors.toList());
+  }
+
+  public void addConfigListeners(ClusterInstanceConfigChangeListener clusterInstanceConfigChangeListener)
+      throws Exception {
+    RetryPolicies.exponentialBackoffRetryPolicy(3, 100, 5).attempt(() -> {

Review comment:
       I don't think we need retry for this. It should not fail in normal case




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] fx19880617 commented on a change in pull request #6020: Add Caching in Controller Broker API

Posted by GitBox <gi...@apache.org>.
fx19880617 commented on a change in pull request #6020:
URL: https://github.com/apache/incubator-pinot/pull/6020#discussion_r489718101



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/listener/ClusterInstanceConfigChangeListener.java
##########
@@ -0,0 +1,32 @@
+package org.apache.pinot.controller.helix.core.listener;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.InstanceConfigChangeListener;
+import org.apache.helix.model.InstanceConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+public class ClusterInstanceConfigChangeListener implements InstanceConfigChangeListener {
+    private HelixManager _helixManager;
+    private List<InstanceConfig> _instanceConfigs = new ArrayList<>();
+
+    public ClusterInstanceConfigChangeListener(HelixManager helixManager) {
+        _helixManager = helixManager;

Review comment:
       set _instanceConfigs here




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org