hqx871 commented on code in PR #64167:
URL: https://github.com/apache/doris/pull/64167#discussion_r3373084070


##########
fe/fe-core/src/main/java/org/apache/doris/clone/TenantLevelColocateTableCheckerAndBalancer.java:
##########
@@ -0,0 +1,468 @@
+// 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.doris.clone;
+
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.MaterializedIndex;
+import org.apache.doris.catalog.MaterializedIndex.IndexExtState;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Partition;
+import org.apache.doris.catalog.ReplicaAllocation;
+import org.apache.doris.catalog.Tablet;
+import org.apache.doris.catalog.Tablet.TabletHealth;
+import org.apache.doris.catalog.Tablet.TabletStatus;
+import org.apache.doris.catalog.TenantLevelColocateGroupSchema;
+import org.apache.doris.catalog.TenantLevelColocateTableIndex;
+import org.apache.doris.catalog.TenantLevelColocateTableIndex.GroupV2Id;
+import org.apache.doris.clone.TabletChecker.CheckerCounter;
+import org.apache.doris.clone.TabletSchedCtx.Priority;
+import org.apache.doris.clone.TabletScheduler.AddResult;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.Reference;
+import org.apache.doris.persist.ModifyTenantLevelColocateMapInfo;
+import org.apache.doris.resource.Tag;
+import org.apache.doris.system.SystemInfoService;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * TenantLevelColocateTableCheckerAndBalancer is responsible for tablets' 
repair and balance of colocated tables.
+ */
+public class TenantLevelColocateTableCheckerAndBalancer extends 
ColocateTableCheckerAndBalancer {
+    private static final Logger LOG = 
LogManager.getLogger(TenantLevelColocateTableCheckerAndBalancer.class);
+
+    private TenantLevelColocateTableCheckerAndBalancer(long intervalMs) {
+        super("colocate group clone checker v2", intervalMs);
+    }
+
+    private static volatile TenantLevelColocateTableCheckerAndBalancer 
INSTANCE = null;
+
+    public static TenantLevelColocateTableCheckerAndBalancer getInstance() {
+        if (INSTANCE == null) {
+            synchronized (TenantLevelColocateTableCheckerAndBalancer.class) {
+                if (INSTANCE == null) {
+                    INSTANCE = new 
TenantLevelColocateTableCheckerAndBalancer(Config.tablet_checker_interval_ms);
+                }
+            }
+        }
+        return INSTANCE;
+    }
+
+    @Override
+    public void runAfterCatalogReady() {
+        relocateAndBalanceGroups();
+        matchGroups();
+    }
+
+    private void relocateAndBalanceGroups() {
+        Set<GroupV2Id> groupIds = 
Env.getCurrentEnv().getTenantLevelColocateTableIndex().getAllGroupIds();
+
+        // balance only inside each group, excluded balance between all groups
+        Set<GroupV2Id> changeGroups = relocateAndBalanceGroup(groupIds, false);
+
+        if (!Config.disable_colocate_balance_between_groups
+                && !changeGroups.isEmpty()) {
+            // balance both inside each group and between all groups
+            relocateAndBalanceGroup(changeGroups, true);
+        }
+    }
+
+    private Set<GroupV2Id> relocateAndBalanceGroup(Set<GroupV2Id> groupIds, 
boolean balanceBetweenGroups) {
+        Set<GroupV2Id> changeGroups = Sets.newHashSet();
+        if (Config.disable_colocate_balance) {
+            return changeGroups;
+        }
+
+        Env env = Env.getCurrentEnv();
+        TenantLevelColocateTableIndex colocateIndex = 
env.getTenantLevelColocateTableIndex();
+        SystemInfoService infoService = Env.getCurrentSystemInfo();
+
+        GlobalColocateStatistic globalColocateStatistic = 
buildGlobalColocateStatistic();
+
+        // get all groups
+        for (GroupV2Id groupId : groupIds) {

Review Comment:
   updated



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to