swaminathanmanish commented on code in PR #10359: URL: https://github.com/apache/pinot/pull/10359#discussion_r1132835263
########## pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/rebalance/ZkBasedTableRebalanceObserver.java: ########## @@ -0,0 +1,168 @@ +/** + * 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.rebalance; + +import com.google.common.base.Preconditions; +import java.util.Map; +import org.apache.helix.store.zk.ZkHelixPropertyStore; +import org.apache.helix.zookeeper.datamodel.ZNRecord; +import org.apache.pinot.controller.helix.core.PinotHelixResourceManager; +import org.apache.pinot.spi.utils.CommonConstants; +/** + * <code>ZkBasedTableRebalanceObserver</code> observes rebalance progress and tracks rebalance status, + * stats in Zookeeper. This will be used to show the progress of rebalance to users via rebalanceStatus API. + */ +public class ZkBasedTableRebalanceObserver implements TableRebalanceObserver { + private final String _tableNameWithType; + private final String _rebalanceJobId; + private final ZkHelixPropertyStore<ZNRecord> _propertyStore; + TableRebalanceProgressStats _tableRebalanceProgressStats; + + public ZkBasedTableRebalanceObserver(String tableNameWithType, + String rebalanceJobId, + ZkHelixPropertyStore<ZNRecord> propertyStore) { + Preconditions.checkState(tableNameWithType != null, "Table name cannot be null"); + Preconditions.checkState(rebalanceJobId != null, "rebalanceId cannot be null"); + Preconditions.checkState(propertyStore != null, "propertyStore cannot be null"); + _tableNameWithType = tableNameWithType; + _rebalanceJobId = rebalanceJobId; + _propertyStore = propertyStore; + _tableRebalanceProgressStats = new TableRebalanceProgressStats(); + } + + @Override + public void onTrigger(Trigger trigger, Map<String, Map<String, String>> currentState, + Map<String, Map<String, String>> targetState) { + switch (trigger) { + case START_TRIGGER: + updateOnStart(currentState, targetState); + break; + case IDEAL_STATE_CHANGE_TRIGGER: + _tableRebalanceProgressStats.setCurrentToTargetConvergence(getDifferenceBetweenTableRebalanceStates( + targetState, currentState)); + break; + case EXTERNAL_VIEW_TO_IDEAL_STATE_CONVERGENCE_TRIGGER: + _tableRebalanceProgressStats.setExternalViewToIdealStateConvergence( + getDifferenceBetweenTableRebalanceStates(targetState, currentState)); + break; + default: + throw new IllegalArgumentException("Unimplemented trigger: " + trigger); + } + PinotHelixResourceManager.addRebalanceResultToZk(_tableNameWithType, _rebalanceJobId, Review Comment: @saurabhd336 and I discussed. The in-memory state is local to the controller and will not be available to other controllers. We'll have to query all controllers to figure out which one has the rebalanceStatus. This approach complicates the status API as well as keep around in-memory state (HashMap). We decided to take the other approach to persist in ZK, but only when there's a difference in the stats computed. This will minimize updates to Zk. Added stats to track number of updates to Zk so that we'll know the write load on Zk. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org