swuferhong commented on code in PR #1452:
URL: https://github.com/apache/fluss/pull/1452#discussion_r2664566818


##########
fluss-server/src/main/java/org/apache/fluss/server/coordinator/rebalance/RebalanceManager.java:
##########
@@ -0,0 +1,436 @@
+/*
+ * 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.fluss.server.coordinator.rebalance;
+
+import org.apache.fluss.annotation.VisibleForTesting;
+import org.apache.fluss.cluster.rebalance.RebalancePlanForBucket;
+import org.apache.fluss.cluster.rebalance.RebalanceProgress;
+import org.apache.fluss.cluster.rebalance.RebalanceResultForBucket;
+import org.apache.fluss.cluster.rebalance.RebalanceStatus;
+import org.apache.fluss.cluster.rebalance.ServerTag;
+import org.apache.fluss.exception.RebalanceFailureException;
+import org.apache.fluss.metadata.TableBucket;
+import org.apache.fluss.server.coordinator.CoordinatorContext;
+import org.apache.fluss.server.coordinator.CoordinatorEventProcessor;
+import org.apache.fluss.server.coordinator.rebalance.goal.Goal;
+import org.apache.fluss.server.coordinator.rebalance.goal.GoalOptimizer;
+import org.apache.fluss.server.coordinator.rebalance.model.ClusterModel;
+import org.apache.fluss.server.coordinator.rebalance.model.RackModel;
+import org.apache.fluss.server.coordinator.rebalance.model.ServerModel;
+import org.apache.fluss.server.metadata.ServerInfo;
+import org.apache.fluss.server.zk.ZooKeeperClient;
+import org.apache.fluss.server.zk.data.LeaderAndIsr;
+import org.apache.fluss.server.zk.data.RebalancePlan;
+import org.apache.fluss.utils.MapUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.GuardedBy;
+import javax.annotation.concurrent.ThreadSafe;
+
+import java.util.ArrayDeque;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Queue;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import static org.apache.fluss.cluster.rebalance.RebalanceStatus.CANCELED;
+import static org.apache.fluss.cluster.rebalance.RebalanceStatus.COMPLETED;
+import static org.apache.fluss.cluster.rebalance.RebalanceStatus.NOT_STARTED;
+import static org.apache.fluss.cluster.rebalance.RebalanceStatus.NO_TASK;
+import static org.apache.fluss.cluster.rebalance.RebalanceStatus.REBALANCING;
+import static org.apache.fluss.cluster.rebalance.RebalanceUtils.FINAL_STATUSES;
+import static org.apache.fluss.utils.Preconditions.checkArgument;
+import static org.apache.fluss.utils.Preconditions.checkNotNull;
+import static org.apache.fluss.utils.concurrent.LockUtils.inLock;
+
+/**
+ * A rebalance manager to generate rebalance plan, and execution rebalance 
plan.
+ *
+ * <p>This manager can only be used in {@link CoordinatorEventProcessor} as a 
single threaded model.
+ */
+@ThreadSafe
+public class RebalanceManager {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(RebalanceManager.class);
+
+    private final AtomicBoolean isClosed = new AtomicBoolean(false);
+    private final Lock lock = new ReentrantLock();
+    private final ZooKeeperClient zkClient;
+    private final CoordinatorEventProcessor eventProcessor;
+
+    @GuardedBy("lock")
+    private final Queue<TableBucket> ongoingRebalanceTasksQueue = new 
ArrayDeque<>();
+
+    /** A mapping from table bucket to rebalance status of pending and running 
tasks. */
+    @GuardedBy("lock")
+    private final Map<TableBucket, RebalanceResultForBucket> 
ongoingRebalanceTasks =
+            MapUtils.newConcurrentHashMap();
+
+    /** A mapping from table bucket to rebalance status of failed or completed 
tasks. */
+    @GuardedBy("lock")
+    private final Map<TableBucket, RebalanceResultForBucket> 
finishedRebalanceTasks =
+            MapUtils.newConcurrentHashMap();
+
+    @GuardedBy("lock")
+    private final GoalOptimizer goalOptimizer;
+
+    @GuardedBy("lock")
+    private long registerTime;
+
+    @GuardedBy("lock")
+    private volatile RebalanceStatus rebalanceStatus = NO_TASK;

Review Comment:
   These two variable is not in lock. I will remove the annotation 
`@GuardedBy("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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to