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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org