vagetablechicken commented on a change in pull request #5010: URL: https://github.com/apache/incubator-doris/pull/5010#discussion_r548418768
########## File path: fe/fe-core/src/main/java/org/apache/doris/clone/PartitionRebalancer.java ########## @@ -0,0 +1,324 @@ +// 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 com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Ordering; +import com.google.common.collect.TreeMultimap; +import org.apache.doris.catalog.Replica; +import org.apache.doris.catalog.TabletInvertedIndex; +import org.apache.doris.catalog.TabletMeta; +import org.apache.doris.common.Config; +import org.apache.doris.common.Pair; +import org.apache.doris.system.SystemInfoService; +import org.apache.doris.thrift.TStorageMedium; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.List; +import java.util.Map; +import java.util.NavigableSet; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.Collectors; + +public class PartitionRebalancer extends Rebalancer { + private static final Logger LOG = LogManager.getLogger(PartitionRebalancer.class); + + private final TwoDimensionalGreedyAlgo algo = new TwoDimensionalGreedyAlgo(); + protected final MovesInProgressCache movesInProgressCache = new MovesInProgressCache(); + + private final AtomicLong counterBalanceMoveCreated = new AtomicLong(0); + private final AtomicLong counterBalanceMoveSucceeded = new AtomicLong(0); + + public PartitionRebalancer(SystemInfoService infoService, TabletInvertedIndex invertedIndex) { + super(infoService, invertedIndex); + } + + @Override + protected List<TabletSchedCtx> selectAlternativeTabletsForCluster( + String clusterName, ClusterLoadStatistic clusterStat, TStorageMedium medium) { + MovesInProgressCache.Cell movesInProgress = movesInProgressCache.getCache(clusterName, medium); + Preconditions.checkNotNull(movesInProgress, "clusterStat is got from statisticMap, movesInProgressMap should have the same entry"); + + // iterating through cache.asMap().values() does not reset access time for the entries you retrieve. + List<ReplicaMove> movesInProgressList = movesInProgress.get().asMap().values() + .stream().map(p -> p.first).collect(Collectors.toList()); + List<Long> toDeleteKeys = Lists.newArrayList(); + + // The problematic movements will be found in buildClusterInfo(), so here is a simply move completion check + // of moves which have valid ToDeleteReplica. + List<ReplicaMove> movesNeedCheck = movesInProgress.get().asMap().values() + .stream().filter(p -> p.second != -1L).map(p -> p.first).collect(Collectors.toList()); + checkMovesCompleted(movesNeedCheck, toDeleteKeys); + + ClusterBalanceInfo clusterBalanceInfo = new ClusterBalanceInfo(); + // We should assume the in-progress moves have been succeeded to avoid producing the same moves. + // Apply in-progress moves to current cluster stats, use TwoDimensionalGreedyAlgo.ApplyMove for simplicity. + if (!buildClusterInfo(clusterStat, medium, movesInProgressList, clusterBalanceInfo, toDeleteKeys)) { + return Lists.newArrayList(); + } + + // Just delete the completed or problematic moves + if (!toDeleteKeys.isEmpty()) { + movesInProgress.get().invalidateAll(toDeleteKeys); + movesInProgressList = movesInProgressList.stream() + .filter(m -> !toDeleteKeys.contains(m.tabletId)).collect(Collectors.toList()); + } + + if (movesInProgressCache.size() > Config.max_balancing_tablets) { Review comment: move不可能去掉,调度单位就是ReplicaMove。 `movesInProgressCache.size() > Config.max_balancing_tablets` 这一句如果觉得难理解,可以加点注释 ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org