zhiqiang-hhhh commented on code in PR #41170: URL: https://github.com/apache/doris/pull/41170#discussion_r1776220114
########## fe/fe-core/src/main/java/org/apache/doris/qe/SimpleScheduler.java: ########## @@ -19,37 +19,169 @@ import org.apache.doris.catalog.Env; import org.apache.doris.common.Config; -import org.apache.doris.common.Pair; import org.apache.doris.common.Reference; import org.apache.doris.common.UserException; import org.apache.doris.system.Backend; import org.apache.doris.system.SystemInfoService; import org.apache.doris.thrift.TNetworkAddress; import org.apache.doris.thrift.TScanRangeLocation; +import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import org.apache.commons.collections.CollectionUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; public class SimpleScheduler { private static final Logger LOG = LogManager.getLogger(SimpleScheduler.class); + public static final long RecordBlackListThreshold = 10; + + public static class BlackListInfo { + public BlackListInfo() {} + + private Lock lock = new ReentrantLock(); + private String reasonForBlackList = ""; + private Long firstRecordBlackTimestampMs = 0L; + private Long lastRecordBlackTimestampMs = 0L; + private Long lastBlackTimestampMs = 0L; + private Long recordBlackListCount = 0L; + private Long backendID = 0L; + + public void tryAddBlackList(String reason) { + lock.lock(); + try { + recordAddBlackList(reason); + if (shuoldBeBlackListed()) { + doAddBlackList(); + LOG.info("Backend is added to black list.\n{}", getDebugInfo()); + } + } finally { + lock.unlock(); + } + } + + private void recordAddBlackList(String reason) { + if (firstRecordBlackTimestampMs <= 0) { + firstRecordBlackTimestampMs = System.currentTimeMillis(); + } + + lastRecordBlackTimestampMs = System.currentTimeMillis(); + recordBlackListCount++; + + if (Strings.isNullOrEmpty(reasonForBlackList) && !Strings.isNullOrEmpty(reason)) { + reasonForBlackList = reason; + } + } + + private boolean shuoldBeBlackListed() { + if (lastRecordBlackTimestampMs <= 0 || firstRecordBlackTimestampMs <= 0) { + return false; + } + if (recordBlackListCount < RecordBlackListThreshold) { + return false; + } + + if (lastRecordBlackTimestampMs - firstRecordBlackTimestampMs + >= Config.do_add_backend_black_list_threshold_secs * 1000) { + return false; + } + + return true; + } + + private void doAddBlackList() { + lastBlackTimestampMs = System.currentTimeMillis(); + Exception e = new Exception(); + String stack = org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e); Review Comment: 日志里会有一个 null exception -- 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: commits-unsubscr...@doris.apache.org 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