最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PowerJob的CleanService清理服務(wù)流程

 更新時(shí)間:2024年02月16日 13:57:16   作者:codecraft  
這篇文章主要為大家介紹了PowerJob的CleanService清理服務(wù)流程源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪<BR>

引言

本文主要研究一下PowerJob的CleanService

CleanService

@Slf4j
@Service
public class CleanService {
    private final DFsService dFsService;
    private final InstanceInfoRepository instanceInfoRepository;
    private final WorkflowInstanceInfoRepository workflowInstanceInfoRepository;
    private final WorkflowNodeInfoRepository workflowNodeInfoRepository;
    private final LockService lockService;
    private final int instanceInfoRetentionDay;
    private final int localContainerRetentionDay;
    private final int remoteContainerRetentionDay;
    private static final int TEMPORARY_RETENTION_DAY = 3;
    /**
     * 每天凌晨3點(diǎn)定時(shí)清理
     */
    private static final String CLEAN_TIME_EXPRESSION = "0 0 3 * * ?";
    private static final String HISTORY_DELETE_LOCK = "history_delete_lock";
    public CleanService(DFsService dFsService, InstanceInfoRepository instanceInfoRepository, WorkflowInstanceInfoRepository workflowInstanceInfoRepository,
                        WorkflowNodeInfoRepository workflowNodeInfoRepository, LockService lockService,
                        @Value("${oms.instanceinfo.retention}") int instanceInfoRetentionDay,
                        @Value("${oms.container.retention.local}") int localContainerRetentionDay,
                        @Value("${oms.container.retention.remote}") int remoteContainerRetentionDay) {
        this.dFsService = dFsService;
        this.instanceInfoRepository = instanceInfoRepository;
        this.workflowInstanceInfoRepository = workflowInstanceInfoRepository;
        this.workflowNodeInfoRepository = workflowNodeInfoRepository;
        this.lockService = lockService;
        this.instanceInfoRetentionDay = instanceInfoRetentionDay;
        this.localContainerRetentionDay = localContainerRetentionDay;
        this.remoteContainerRetentionDay = remoteContainerRetentionDay;
    }
    //......
}
CleanService提供了timingClean、cleanLocal方法

timingClean

@Async(PJThreadPool.TIMING_POOL)
    @Scheduled(cron = CLEAN_TIME_EXPRESSION)
    public void timingClean() {

        // 釋放本地緩存
        WorkerClusterManagerService.cleanUp();

        // 釋放磁盤(pán)空間
        cleanLocal(OmsFileUtils.genLogDirPath(), instanceInfoRetentionDay);
        cleanLocal(OmsFileUtils.genContainerJarPath(), localContainerRetentionDay);
        cleanLocal(OmsFileUtils.genTemporaryPath(), TEMPORARY_RETENTION_DAY);

        // 刪除數(shù)據(jù)庫(kù)歷史的數(shù)據(jù)
        cleanByOneServer();
    }
timingClean先執(zhí)行WorkerClusterManagerService.cleanUp()釋放本地緩存,之后通過(guò)cleanLocal釋放本地磁盤(pán)空間,最后執(zhí)行cleanByOneServer刪除歷史數(shù)據(jù)

cleanLocal

@VisibleForTesting
    public void cleanLocal(String path, int day) {
        if (day < 0) {
            log.info("[CleanService] won't clean up {} because of offset day <= 0.", path);
            return;
        }
        Stopwatch stopwatch = Stopwatch.createStarted();
        File dir = new File(path);
        if (!dir.exists()) {
            return;
        }
        File[] logFiles = dir.listFiles();
        if (logFiles == null || logFiles.length == 0) {
            return;
        }
        // 計(jì)算最大偏移量
        long maxOffset = day * 24 * 60 * 60 * 1000L;
        for (File f : logFiles) {
            long offset = System.currentTimeMillis() - f.lastModified();
            if (offset >= maxOffset) {
                if (!f.delete()) {
                    log.warn("[CleanService] delete file({}) failed.", f.getName());
                }else {
                    log.info("[CleanService] delete file({}) successfully.", f.getName());
                }
            }
        }
        log.info("[CleanService] clean {} successfully, using {}.", path, stopwatch.stop());
    }
cleanLocal會(huì)刪除指定目錄中l(wèi)astModified距離當(dāng)前時(shí)間大于等于1天的文件

cleanByOneServer

private void cleanByOneServer() {
        // 只要第一個(gè)server搶到鎖其他server就會(huì)返回,所以鎖10分鐘應(yīng)該足夠了
        boolean lock = lockService.tryLock(HISTORY_DELETE_LOCK, 10 * 60 * 1000L);
        if (!lock) {
            log.info("[CleanService] clean job is already running, just return.");
            return;
        }
        try {
            // 刪除數(shù)據(jù)庫(kù)運(yùn)行記錄
            cleanInstanceLog();
            cleanWorkflowInstanceLog();
            // 刪除無(wú)用節(jié)點(diǎn)
            cleanWorkflowNodeInfo();
            // 刪除 GridFS 過(guò)期文件
            cleanRemote(Constants.LOG_BUCKET, instanceInfoRetentionDay);
            cleanRemote(Constants.CONTAINER_BUCKET, remoteContainerRetentionDay);
        } finally {
            lockService.unlock(HISTORY_DELETE_LOCK);
        }
    }
cleanByOneServer先加鎖,然后執(zhí)行cleanInstanceLog、cleanWorkflowInstanceLog、cleanWorkflowNodeInfo等

小結(jié)

PowerJob的CleanService提供了timingClean、cleanLocal方法,其中timingClean先執(zhí)行WorkerClusterManagerService.cleanUp()釋放本地緩存,之后通過(guò)cleanLocal釋放本地磁盤(pán)空間,最后執(zhí)行cleanByOneServer刪除歷史數(shù)據(jù);cleanLocal會(huì)刪除指定目錄中l(wèi)astModified距離當(dāng)前時(shí)間大于等于1天的文件。

以上就是PowerJob的CleanService清理服務(wù)流程的詳細(xì)內(nèi)容,更多關(guān)于PowerJob CleanService流程的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Java中常見(jiàn)隊(duì)列舉例詳解(非線(xiàn)程安全)

    Java中常見(jiàn)隊(duì)列舉例詳解(非線(xiàn)程安全)

    隊(duì)列用于模擬隊(duì)列這種數(shù)據(jù)結(jié)構(gòu),隊(duì)列通常是指先進(jìn)先出的容器,這篇文章主要介紹了Java中常見(jiàn)隊(duì)列(非線(xiàn)程安全)的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-06-06
  • Java的super關(guān)鍵字與instanceof運(yùn)算符使用方法

    Java的super關(guān)鍵字與instanceof運(yùn)算符使用方法

    這篇文章主要介紹了Java的super關(guān)鍵字與instanceof運(yùn)算符使用方法,是Java入門(mén)學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-09-09
  • 詳解SpringBoot同時(shí)可以處理多少請(qǐng)求

    詳解SpringBoot同時(shí)可以處理多少請(qǐng)求

    在日常操作中,相信很多人在SpringBoot能同時(shí)處理多少請(qǐng)求問(wèn)題上存在疑惑,本文就來(lái)詳細(xì)的介紹一下,感興趣的可以了解一下
    2024-06-06
  • SpringBoot如何基于POI-tl和word模板導(dǎo)出龐大的Word文件

    SpringBoot如何基于POI-tl和word模板導(dǎo)出龐大的Word文件

    這篇文章主要介紹了SpringBoot如何基于POI-tl和word模板導(dǎo)出龐大的Word文件,poi-tl是一個(gè)基于Apache?POI的Word模板引擎,也是一個(gè)免費(fèi)開(kāi)源的Java類(lèi)庫(kù)
    2022-08-08
  • Window搭建部署RocketMQ步驟詳解

    Window搭建部署RocketMQ步驟詳解

    這篇文章主要介紹了Window搭建部署RocketMQ步驟詳解,RocketMq是一個(gè)由阿里巴巴開(kāi)源的消息中間件,脫胎去阿里每部使用的MetaQ,在設(shè)計(jì)上借鑒了Kafka。,需要的朋友可以參考下
    2019-06-06
  • Java標(biāo)識(shí)接口的使用方法

    Java標(biāo)識(shí)接口的使用方法

    在本篇文章中小編給大家分享了關(guān)于Java標(biāo)識(shí)接口的使用方法和教程內(nèi)容,有需要的朋友們學(xué)習(xí)下。
    2019-01-01
  • 利用Spring Social輕松搞定微信授權(quán)登錄的方法示例

    利用Spring Social輕松搞定微信授權(quán)登錄的方法示例

    這篇文章主要介紹了利用Spring Social輕松搞定微信授權(quán)登錄的方法示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12
  • 如何在Java中讀取resources下的文件及資源路徑

    如何在Java中讀取resources下的文件及資源路徑

    本文介紹了如何在Java中讀取resources下的文件以及獲取resource文件的路徑,通過(guò)使用ClassLoader或Class的getResourceAsStream方法,可以輕松地讀取resources目錄下的文件,感興趣的朋友跟隨小編一起看看吧
    2023-06-06
  • java 中sleep() 和 wait() 的對(duì)比

    java 中sleep() 和 wait() 的對(duì)比

    這篇文章主要介紹了java 中sleep() 和 wait() 的對(duì)比的相關(guān)資料,需要的朋友可以參考下
    2017-04-04
  • 通Java接口上傳實(shí)現(xiàn)SMMS圖床

    通Java接口上傳實(shí)現(xiàn)SMMS圖床

    這篇文章主要介紹了通Java接口上傳實(shí)現(xiàn)SMMS圖床,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-07-07

最新評(píng)論

金寨县| 布拖县| 大石桥市| 吴桥县| 郎溪县| 宁波市| 江都市| 阳曲县| 灵台县| 永和县| 陕西省| 洛南县| 宜阳县| 石狮市| 长阳| 陆良县| 浠水县| 凌源市| 墨脱县| 昌宁县| 原阳县| 南开区| 辉县市| 清涧县| 余干县| 白水县| 北宁市| 蓬安县| 景东| 奉新县| 关岭| 嘉荫县| 乐昌市| 通海县| 阿克陶县| 开封县| 湘乡市| 壤塘县| 沙田区| 游戏| 深水埗区|