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/10/02 00:25:39 UTC

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

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