From 7edb9f0e22fdb1679db2dff9f139e913de45849a Mon Sep 17 00:00:00 2001 From: jsonwan Date: Fri, 19 Apr 2024 16:12:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BF=90=E8=90=A5=E5=88=86=E6=9E=90?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9C=80=E5=90=8E=E6=9B=B4=E6=96=B0=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E4=B8=8D=E5=87=86=E7=A1=AE=20#2904?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../statistics/StatisticsTaskScheduler.java | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/StatisticsTaskScheduler.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/StatisticsTaskScheduler.java index 18dec820ae..7b638799c2 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/StatisticsTaskScheduler.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/StatisticsTaskScheduler.java @@ -35,7 +35,6 @@ import com.tencent.bk.job.common.redis.util.HeartBeatRedisLock; import com.tencent.bk.job.common.redis.util.HeartBeatRedisLockConfig; import com.tencent.bk.job.common.redis.util.LockResult; -import com.tencent.bk.job.common.redis.util.LockUtils; import com.tencent.bk.job.common.redis.util.RedisKeyHeartBeatThread; import com.tencent.bk.job.common.util.ApplicationContextRegister; import com.tencent.bk.job.common.util.TimeUtil; @@ -77,7 +76,6 @@ public class StatisticsTaskScheduler { private static final String machineIp = IpUtils.getFirstMachineIP(); - private static final String REDIS_KEY_STATISTIC_JOB_LOCK = "statistic-job-lock"; private static final String REDIS_KEY_STATISTIC_JOB_RUNNING_MACHINE = "statistic-job-running-machine"; public static final AtomicLong rejectedStatisticsTaskNum = new AtomicLong(0); private static final String REDIS_KEY_STATISTIC_JOB_INIT_MACHINE = "statistic-job-init-machine"; @@ -97,18 +95,6 @@ public class StatisticsTaskScheduler { private ThreadPoolExecutor currentStatisticsTaskExecutor; private ThreadPoolExecutor pastStatisticsTaskExecutor; - static { - List keyList = Collections.singletonList(REDIS_KEY_STATISTIC_JOB_LOCK); - keyList.forEach(key -> { - try { - //进程重启首先尝试释放上次加上的锁避免死锁 - LockUtils.releaseDistributedLock(key, machineIp); - } catch (Throwable t) { - log.info("Redis key:" + key + " does not need to be released, ignore"); - } - }); - } - private final StatisticConfig statisticConfig; private final RedisTemplate redisTemplate; private final PastStatisticsMakeupTask pastStatisticsMakeupTask; @@ -174,7 +160,7 @@ public boolean configThreads(Integer currentStatisticThreadsNum, Integer pastSta if (currentStatisticThreadsNum != null && currentStatisticThreadsNum > 0) { log.info("reconfig currentStatisticsTaskExecutor to {} threads", currentStatisticThreadsNum); List canceledRunnableList = currentStatisticsTaskExecutor.shutdownNow(); - if (canceledRunnableList.size() > 0) { + if (!canceledRunnableList.isEmpty()) { log.warn("{} threads of canceled", canceledRunnableList.size()); } currentStatisticsTaskExecutor = new ThreadPoolExecutor( @@ -193,7 +179,7 @@ public boolean configThreads(Integer currentStatisticThreadsNum, Integer pastSta log.info("reconfig pastStatisticsTaskExecutor to {} threads", pastStatisticThreadsNum); pastStatisticsMakeupTask.setRunFlag(false); List canceledRunnableList = pastStatisticsTaskExecutor.shutdownNow(); - if (canceledRunnableList.size() > 0) { + if (!canceledRunnableList.isEmpty()) { log.warn("{} threads of pastStatisticsTaskExecutor canceled", canceledRunnableList.size()); } pastStatisticsTaskExecutor = new ThreadPoolExecutor( @@ -265,7 +251,7 @@ public List startTasks(String startDateStr, String endDateStr, List= 0 && count < maxPreviousDays) { + while (!targetDate.isBefore(startDate) && count < maxPreviousDays) { startByTaskNameList(taskNameList, targetDate, startedTaskNames); targetDate = targetDate.minusDays(1); count += 1; @@ -465,7 +451,7 @@ public void schedule() { futureList.forEach(future -> { try { // 最长统计任务耗时约30min - int timeoutMinutes = 50; + int timeoutMinutes = 60; future.get(timeoutMinutes, TimeUnit.MINUTES); updateDataUpdateTime(TimeUtil.getCurrentTimeStr()); } catch (InterruptedException | ExecutionException | TimeoutException e) {