morningman commented on a change in pull request #336: First commit of new tablet repair framework URL: https://github.com/apache/incubator-doris/pull/336#discussion_r237770190
########## File path: fe/src/main/java/org/apache/doris/clone/TabletChecker.java ########## @@ -0,0 +1,213 @@ +// 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.Catalog; +import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.MaterializedIndex; +import org.apache.doris.catalog.OlapTable; +import org.apache.doris.catalog.Partition; +import org.apache.doris.catalog.Table; +import org.apache.doris.catalog.Tablet; +import org.apache.doris.catalog.Tablet.TabletStatus; +import org.apache.doris.common.Pair; +import org.apache.doris.common.util.Daemon; +import org.apache.doris.system.SystemInfoService; + +import com.google.common.base.Preconditions; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Sets; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.List; +import java.util.Set; + +/* + * This checker is responsible for checking all unhealthy tablets. + * It does not responsible for any scheduler of tablet repairing or balance + */ +public class TabletChecker extends Daemon { + private static final Logger LOG = LogManager.getLogger(TabletChecker.class); + + private static final long INTERVAL_MS = 60 * 1000L; // 1min + + private Catalog catalog; + private SystemInfoService infoService; + private TabletScheduler tabletScheduler; + private TabletSchedulerStat stat; + + // db id -> (tbl id -> partition id) + // priority of replicas of partitions in this table will be set to VERY_HIGH if not healthy + private com.google.common.collect.Table<Long, Long, Set<Long>> prios = HashBasedTable.create(); + + public TabletChecker(Catalog catalog, SystemInfoService infoService, TabletScheduler tabletScheduler, + TabletSchedulerStat stat) { + super("tablet checker", INTERVAL_MS); + this.catalog = catalog; + this.infoService = infoService; + this.tabletScheduler = tabletScheduler; + this.stat = stat; + } + + public void addPrios(long dbId, long tblId, List<Long> partitionIds) { + Preconditions.checkArgument(!partitionIds.isEmpty()); + synchronized (prios) { + Set<Long> parts = prios.get(dbId, tblId); + if (parts == null) { + parts = Sets.newHashSet(); + prios.put(dbId, tblId, parts); + } + parts.addAll(partitionIds); + } + + // we also need to change the priority of tablets which are already in + tabletScheduler.changePriorityOfTablets(dbId, tblId, partitionIds); + } + + /* + * For each cycle, TabletChecker will check all OlapTable's tablet. + * If a tablet is not healthy, a TabletInfo will be created and sent to TabletScheduler for repairing. + */ + @Override + protected void runOneCycle() { + boolean schedulerHasTask = !tabletScheduler.isEmpty(); + + // if scheduler has tasks, we only check tablets in prios + checkTablets(schedulerHasTask); + stat.counterTabletCheckRound.incrementAndGet(); + + LOG.info(stat.incrementalBrief()); Review comment: Here we only catch expected exception, any unexpected exception is caught in `Deamon` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
