swaminathanmanish commented on code in PR #10359:
URL: https://github.com/apache/pinot/pull/10359#discussion_r1131622528


##########
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:
   Yes, Jackie and I discussed about this. We were thinking of using diff or a 
timer for these updates.  Using the in-memory state, gets rid of all these 
intermediate updates and will make this deterministic (one update per 
rebalance). I've incorporated that in my latest PR update. The only concern I 
had was that we need to ensure that this state is cleared and does not hang 
around. I've  added assertions to make sure that the in-memory is cleared. 



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

Reply via email to