Search in sources :

Example 1 with DumpChangeTask

use of com.alibaba.nacos.config.server.service.dump.task.DumpChangeTask in project nacos by alibaba.

the class DumpService method dumpConfigInfo.

private void dumpConfigInfo(DumpAllProcessor dumpAllProcessor) throws IOException {
    int timeStep = 6;
    boolean isAllDump = true;
    // initial dump all
    FileInputStream fis = null;
    Timestamp heartheatLastStamp = null;
    try {
        if (isQuickStart()) {
            File heartbeatFile = DiskUtil.heartBeatFile();
            if (heartbeatFile.exists()) {
                fis = new FileInputStream(heartbeatFile);
                String heartheatTempLast = IoUtils.toString(fis, Constants.ENCODE);
                heartheatLastStamp = Timestamp.valueOf(heartheatTempLast);
                if (TimeUtils.getCurrentTime().getTime() - heartheatLastStamp.getTime() < timeStep * 60 * 60 * 1000) {
                    isAllDump = false;
                }
            }
        }
        if (isAllDump) {
            LogUtil.DEFAULT_LOG.info("start clear all config-info.");
            DiskUtil.clearAll();
            dumpAllProcessor.process(new DumpAllTask());
        } else {
            Timestamp beforeTimeStamp = getBeforeStamp(heartheatLastStamp, timeStep);
            DumpChangeProcessor dumpChangeProcessor = new DumpChangeProcessor(this, beforeTimeStamp, TimeUtils.getCurrentTime());
            dumpChangeProcessor.process(new DumpChangeTask());
            Runnable checkMd5Task = () -> {
                LogUtil.DEFAULT_LOG.error("start checkMd5Task");
                List<String> diffList = ConfigCacheService.checkMd5();
                for (String groupKey : diffList) {
                    String[] dg = GroupKey.parseKey(groupKey);
                    String dataId = dg[0];
                    String group = dg[1];
                    String tenant = dg[2];
                    ConfigInfoWrapper configInfo = persistService.queryConfigInfo(dataId, group, tenant);
                    ConfigCacheService.dumpChange(dataId, group, tenant, configInfo.getContent(), configInfo.getLastModified(), configInfo.getEncryptedDataKey());
                }
                LogUtil.DEFAULT_LOG.error("end checkMd5Task");
            };
            ConfigExecutor.scheduleConfigTask(checkMd5Task, 0, 12, TimeUnit.HOURS);
        }
    } catch (IOException e) {
        LogUtil.FATAL_LOG.error("dump config fail" + e.getMessage());
        throw e;
    } finally {
        if (null != fis) {
            try {
                fis.close();
            } catch (IOException e) {
                LogUtil.DEFAULT_LOG.warn("close file failed");
            }
        }
    }
}
Also used : DumpAllTask(com.alibaba.nacos.config.server.service.dump.task.DumpAllTask) IOException(java.io.IOException) ConfigInfoWrapper(com.alibaba.nacos.config.server.model.ConfigInfoWrapper) Timestamp(java.sql.Timestamp) DumpChangeProcessor(com.alibaba.nacos.config.server.service.dump.processor.DumpChangeProcessor) FileInputStream(java.io.FileInputStream) DumpChangeTask(com.alibaba.nacos.config.server.service.dump.task.DumpChangeTask) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

ConfigInfoWrapper (com.alibaba.nacos.config.server.model.ConfigInfoWrapper)1 DumpChangeProcessor (com.alibaba.nacos.config.server.service.dump.processor.DumpChangeProcessor)1 DumpAllTask (com.alibaba.nacos.config.server.service.dump.task.DumpAllTask)1 DumpChangeTask (com.alibaba.nacos.config.server.service.dump.task.DumpChangeTask)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1