How to ensure the consistency of the final three messages file.

Consider forwarding tasks not performed successfully, then the message Broker server downtime, resulting in inconsistent commitlog, consumeQueue, IndexFile file data.

Look mq loading process is stored on the file:

public boolean load() {
        boolean result = true;

        try {
            boolean lastExitOK = !this.isTempFileExist();
            log.info("last shutdown {}", lastExitOK ? "normally" : "abnormally");

            if (null != scheduleMessageService) {
                result = result && this.scheduleMessageService.load();
            }

            // load Commit Log
            result = result && this.commitLog.load();

            // load Consume Queue
            result = result && this.loadConsumeQueue();

            if (result) {
                this.storeCheckpoint =
                    new StoreCheckpoint(StorePathConfigHelper.getStoreCheckpoint(this.messageStoreConfig.getStorePathRootDir()));

                this.indexService.load(lastExitOK);

                this.recover(lastExitOK);

                log.info("load over, and the max phy offset = {}", this.getMaxPhyOffset());
            }
        } catch (Exception e) {
            log.error("load exception", e);
            result = false;
        }

        if (!result) {
            this.allocateMappedFileService.shutdown();
        }

        return result;
    }

 

Exit on to determine whether a normal, broker at startup file creation abort, abort delete files when you exit by registering jvm hook function. If the file exists abort next start. Description Broker is abnormal exit.

 

Guess you like

Origin www.cnblogs.com/lccsblog/p/12235321.html