亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

PowerJob的CleanService清理服務流程

 更新時間:2024年02月16日 13:57:16   作者:codecraft  
這篇文章主要為大家介紹了PowerJob的CleanService清理服務流程源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪<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點定時清理
     */
    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();

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

        // 刪除數(shù)據(jù)庫歷史的數(shù)據(jù)
        cleanByOneServer();
    }
timingClean先執(zhí)行WorkerClusterManagerService.cleanUp()釋放本地緩存,之后通過cleanLocal釋放本地磁盤空間,最后執(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;
        }
        // 計算最大偏移量
        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會刪除指定目錄中l(wèi)astModified距離當前時間大于等于1天的文件

cleanByOneServer

private void cleanByOneServer() {
        // 只要第一個server搶到鎖其他server就會返回,所以鎖10分鐘應該足夠了
        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ù)庫運行記錄
            cleanInstanceLog();
            cleanWorkflowInstanceLog();
            // 刪除無用節(jié)點
            cleanWorkflowNodeInfo();
            // 刪除 GridFS 過期文件
            cleanRemote(Constants.LOG_BUCKET, instanceInfoRetentionDay);
            cleanRemote(Constants.CONTAINER_BUCKET, remoteContainerRetentionDay);
        } finally {
            lockService.unlock(HISTORY_DELETE_LOCK);
        }
    }
cleanByOneServer先加鎖,然后執(zhí)行cleanInstanceLog、cleanWorkflowInstanceLog、cleanWorkflowNodeInfo等

小結

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

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

相關文章

  • JVM指令的使用深入詳解

    JVM指令的使用深入詳解

    這篇文章主要給大家介紹了關于JVM指令使用的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-01-01
  • 關于Integer.parseInt()方法的使用

    關于Integer.parseInt()方法的使用

    這篇文章主要介紹了關于Integer.parseInt()方法的使用,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • Java使用itextpdf實現(xiàn)PDF轉(zhuǎn)文本以及轉(zhuǎn)圖片

    Java使用itextpdf實現(xiàn)PDF轉(zhuǎn)文本以及轉(zhuǎn)圖片

    PDF轉(zhuǎn)文本的插件常用的有pdfbox ,itextpdf 和 spire.pdf,本文主要介紹如何使用itextpdf實現(xiàn)PDF轉(zhuǎn)文本以及轉(zhuǎn)圖片,需要的可以參考一下
    2025-01-01
  • Java中的動態(tài)代理使用

    Java中的動態(tài)代理使用

    這篇文章主要介紹了Java中的動態(tài)代理使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • 關于elasticsearch的match_phrase_prefix查詢詳解

    關于elasticsearch的match_phrase_prefix查詢詳解

    這篇文章主要介紹了關于elasticsearch的match_phrase_prefix查詢問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Java?方法的重載與參數(shù)傳遞詳解

    Java?方法的重載與參數(shù)傳遞詳解

    在java中,方法就是用來完成解決某件事情或?qū)崿F(xiàn)某個功能的辦法。方法實現(xiàn)的過程中,會包含很多條語句用于完成某些有意義的功能——通常是處理文本,控制輸入或計算數(shù)值,這篇文章我們來探究一下方法的重載與傳參
    2022-04-04
  • 使用ServletInputStream在攔截器或過濾器中應用后重寫

    使用ServletInputStream在攔截器或過濾器中應用后重寫

    這篇文章主要介紹了使用ServletInputStream在攔截器或過濾器中應用后重寫,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • Java8時間轉(zhuǎn)換(LocalDateTime)代碼實例

    Java8時間轉(zhuǎn)換(LocalDateTime)代碼實例

    這篇文章主要介紹了java8時間轉(zhuǎn)換(LocalDateTime)代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-11-11
  • Mybatis-Plus使用ID_WORKER生成主鍵id重復的解決方法

    Mybatis-Plus使用ID_WORKER生成主鍵id重復的解決方法

    本文主要介紹了Mybatis-Plus使用ID_WORKER生成主鍵id重復的解決方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-07-07
  • java基本教程之常用的實現(xiàn)多線程的兩種方式 java多線程教程

    java基本教程之常用的實現(xiàn)多線程的兩種方式 java多線程教程

    下面開始學習“常用的實現(xiàn)多線程的2種方式”:Thread 和 Runnable。之所以說是常用的,是因為通過還可以通過java.util.concurrent包中的線程池來實現(xiàn)多線程
    2014-01-01

最新評論