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


##########
fluss-server/src/main/java/org/apache/fluss/server/coordinator/rebalance/goal/Goal.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.goal;
+
+import org.apache.fluss.exception.RebalanceFailureException;
+import org.apache.fluss.server.coordinator.rebalance.ActionAcceptance;
+import org.apache.fluss.server.coordinator.rebalance.ReBalancingAction;
+import org.apache.fluss.server.coordinator.rebalance.model.ClusterModel;
+import org.apache.fluss.server.coordinator.rebalance.model.ClusterModelStats;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Serializable;
+import java.util.Comparator;
+import java.util.Set;
+
+/** This is the interface of the optimization goals used for rebalance. */
+public interface Goal {
+    Logger LOG = LoggerFactory.getLogger(Goal.class);
+
+    /**
+     * Optimize the given cluster model as needed for this goal.
+     *
+     * <p>The method will be given a cluster model. The goal can try to 
optimize the cluster model
+     * by performing some admin operations(e.g. move replicas or leader of 
tableBuckets).
+     *
+     * <p>During the optimization, the implementation should make sure that 
all the previously
+     * optimized goals are still satisfied after this method completes its 
execution. The
+     * implementation can use {@link #actionAcceptance(ReBalancingAction, 
ClusterModel)} to check
+     * whether an admin operation is allowed by a previously optimized goals.
+     *
+     * <p>The implementation of a soft goal should return a boolean indicating 
whether the goal has
+     * been met after the optimization or not.
+     *
+     * <p>The implementation of a hard goal should throw an {@link 
RebalanceFailureException} when
+     * the goal cannot be met. This will then fail the entire optimization 
attempt.
+     */
+    void optimize(ClusterModel clusterModel, Set<Goal> optimizedGoals);
+
+    /**
+     * Check whether the given action is acceptable by this goal in the given 
state of the cluster.
+     * An action is (1) accepted by a goal if it satisfies requirements of the 
goal, or (2) rejected
+     * by a goal if it violates its requirements. The return value indicates 
whether the action is
+     * accepted or why it is rejected.
+     */
+    ActionAcceptance actionAcceptance(ReBalancingAction action, ClusterModel 
clusterModel);
+
+    /**
+     * Get an instance of {@link ClusterModelStatsComparator} for this goal.
+     *
+     * <p>The {@link ClusterModelStatsComparator#compare(ClusterModelStats, 
ClusterModelStats)}
+     * method should give a preference between two {@link ClusterModelStats}.
+     *
+     * <p>The returned value must not be null.
+     *
+     * @return An instance of {@link ClusterModelStatsComparator} for this 
goal.
+     */
+    ClusterModelStatsComparator clusterModelStatsComparator();
+
+    /**
+     * Signal for finishing the process for rebalance. It is intended to mark 
the goal optimization
+     * as finished and perform the memory clean up after the goal optimization.
+     */
+    void finish();
+
+    /**
+     * @return {@code true} if this is a hard goal, {@code false} otherwise.
+     */
+    boolean isHardGoal();

Review Comment:
   I've removed it for now. It was prepared for more goals to come later.



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