Search in sources :

Example 1 with ConfigInfoChanged

use of com.alibaba.nacos.config.server.model.ConfigInfoChanged in project nacos by alibaba.

the class DumpService method dumpOperate.

protected void dumpOperate(DumpProcessor processor, DumpAllProcessor dumpAllProcessor, DumpAllBetaProcessor dumpAllBetaProcessor, DumpAllTagProcessor dumpAllTagProcessor) throws NacosException {
    String dumpFileContext = "CONFIG_DUMP_TO_FILE";
    TimerContext.start(dumpFileContext);
    try {
        LogUtil.DEFAULT_LOG.warn("DumpService start");
        Runnable dumpAll = () -> dumpAllTaskMgr.addTask(DumpAllTask.TASK_ID, new DumpAllTask());
        Runnable dumpAllBeta = () -> dumpAllTaskMgr.addTask(DumpAllBetaTask.TASK_ID, new DumpAllBetaTask());
        Runnable dumpAllTag = () -> dumpAllTaskMgr.addTask(DumpAllTagTask.TASK_ID, new DumpAllTagTask());
        Runnable clearConfigHistory = () -> {
            LOGGER.warn("clearConfigHistory start");
            if (canExecute()) {
                try {
                    Timestamp startTime = getBeforeStamp(TimeUtils.getCurrentTime(), 24 * getRetentionDays());
                    int pageSize = 1000;
                    LOGGER.warn("clearConfigHistory, getBeforeStamp:{}, pageSize:{}", startTime, pageSize);
                    persistService.removeConfigHistory(startTime, pageSize);
                } catch (Throwable e) {
                    LOGGER.error("clearConfigHistory error : {}", e.toString());
                }
            }
        };
        try {
            dumpConfigInfo(dumpAllProcessor);
            // update Beta cache
            LogUtil.DEFAULT_LOG.info("start clear all config-info-beta.");
            DiskUtil.clearAllBeta();
            if (persistService.isExistTable(BETA_TABLE_NAME)) {
                dumpAllBetaProcessor.process(new DumpAllBetaTask());
            }
            // update Tag cache
            LogUtil.DEFAULT_LOG.info("start clear all config-info-tag.");
            DiskUtil.clearAllTag();
            if (persistService.isExistTable(TAG_TABLE_NAME)) {
                dumpAllTagProcessor.process(new DumpAllTagTask());
            }
            // add to dump aggr
            List<ConfigInfoChanged> configList = persistService.findAllAggrGroup();
            if (configList != null && !configList.isEmpty()) {
                total = configList.size();
                List<List<ConfigInfoChanged>> splitList = splitList(configList, INIT_THREAD_COUNT);
                for (List<ConfigInfoChanged> list : splitList) {
                    MergeAllDataWorker work = new MergeAllDataWorker(list);
                    work.start();
                }
                LOGGER.info("server start, schedule merge end.");
            }
        } catch (Exception e) {
            LogUtil.FATAL_LOG.error("Nacos Server did not start because dumpservice bean construction failure :\n" + e);
            throw new NacosException(NacosException.SERVER_ERROR, "Nacos Server did not start because dumpservice bean construction failure :\n" + e.getMessage(), e);
        }
        if (!EnvUtil.getStandaloneMode()) {
            Runnable heartbeat = () -> {
                String heartBeatTime = TimeUtils.getCurrentTime().toString();
                // write disk
                try {
                    DiskUtil.saveHeartBeatToDisk(heartBeatTime);
                } catch (IOException e) {
                    LogUtil.FATAL_LOG.error("save heartbeat fail" + e.getMessage());
                }
            };
            ConfigExecutor.scheduleConfigTask(heartbeat, 0, 10, TimeUnit.SECONDS);
            long initialDelay = new Random().nextInt(INITIAL_DELAY_IN_MINUTE) + 10;
            LogUtil.DEFAULT_LOG.warn("initialDelay:{}", initialDelay);
            ConfigExecutor.scheduleConfigTask(dumpAll, initialDelay, DUMP_ALL_INTERVAL_IN_MINUTE, TimeUnit.MINUTES);
            ConfigExecutor.scheduleConfigTask(dumpAllBeta, initialDelay, DUMP_ALL_INTERVAL_IN_MINUTE, TimeUnit.MINUTES);
            ConfigExecutor.scheduleConfigTask(dumpAllTag, initialDelay, DUMP_ALL_INTERVAL_IN_MINUTE, TimeUnit.MINUTES);
        }
        ConfigExecutor.scheduleConfigTask(clearConfigHistory, 10, 10, TimeUnit.MINUTES);
    } finally {
        TimerContext.end(dumpFileContext, LogUtil.DUMP_LOG);
    }
}
Also used : DumpAllTask(com.alibaba.nacos.config.server.service.dump.task.DumpAllTask) DumpAllBetaTask(com.alibaba.nacos.config.server.service.dump.task.DumpAllBetaTask) ConfigInfoChanged(com.alibaba.nacos.config.server.model.ConfigInfoChanged) IOException(java.io.IOException) Timestamp(java.sql.Timestamp) NacosException(com.alibaba.nacos.api.exception.NacosException) IOException(java.io.IOException) NacosException(com.alibaba.nacos.api.exception.NacosException) Random(java.util.Random) DumpAllTagTask(com.alibaba.nacos.config.server.service.dump.task.DumpAllTagTask) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with ConfigInfoChanged

use of com.alibaba.nacos.config.server.model.ConfigInfoChanged in project nacos by alibaba.

the class MergeDatumService method splitList.

static List<List<ConfigInfoChanged>> splitList(List<ConfigInfoChanged> list, int count) {
    List<List<ConfigInfoChanged>> result = new ArrayList<List<ConfigInfoChanged>>(count);
    for (int i = 0; i < count; i++) {
        result.add(new ArrayList<ConfigInfoChanged>());
    }
    for (int i = 0; i < list.size(); i++) {
        ConfigInfoChanged config = list.get(i);
        result.get(i % count).add(config);
    }
    return result;
}
Also used : ConfigInfoChanged(com.alibaba.nacos.config.server.model.ConfigInfoChanged) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ConfigInfoChanged

use of com.alibaba.nacos.config.server.model.ConfigInfoChanged in project nacos by alibaba.

the class DumpService method splitList.

static List<List<ConfigInfoChanged>> splitList(List<ConfigInfoChanged> list, int count) {
    List<List<ConfigInfoChanged>> result = new ArrayList<List<ConfigInfoChanged>>(count);
    for (int i = 0; i < count; i++) {
        result.add(new ArrayList<>());
    }
    for (int i = 0; i < list.size(); i++) {
        ConfigInfoChanged config = list.get(i);
        result.get(i % count).add(config);
    }
    return result;
}
Also used : ConfigInfoChanged(com.alibaba.nacos.config.server.model.ConfigInfoChanged) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ConfigInfoChanged (com.alibaba.nacos.config.server.model.ConfigInfoChanged)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 NacosException (com.alibaba.nacos.api.exception.NacosException)1 DumpAllBetaTask (com.alibaba.nacos.config.server.service.dump.task.DumpAllBetaTask)1 DumpAllTagTask (com.alibaba.nacos.config.server.service.dump.task.DumpAllTagTask)1 DumpAllTask (com.alibaba.nacos.config.server.service.dump.task.DumpAllTask)1 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 Random (java.util.Random)1