private boolean checkConsistencyAndAlignLog() {
        final long lastIndex = this.indexDB.getLastLogIndex();
        final long lastSegmentIndex = this.segmentLogDB.getLastLogIndex();
        final long lastConfIndex = this.confDB.getLastLogIndex();
        if (lastIndex == lastSegmentIndex || lastIndex == lastConfIndex) {
            return true;
        }
        final long maxLogIndex = Math.max(lastSegmentIndex, lastConfIndex);
        if (lastIndex > maxLogIndex) {
            // In this case, just align indexDB to the index of max(lastSegmentIndex, lastConfIndex)
            return this.indexDB.truncateSuffix(maxLogIndex, 0);
        } else {
            // In this case, we should generate indexEntry array sorted by index from segmentDB and confDB, then
            // store indexEntry array to indexDB

            // Step1, lookup last (segment/conf) index in indexDB
            final Pair<IndexEntry, IndexEntry> lastIndexPair = this.indexDB.lookupLastLogIndexAndPosFromTail();
            IndexEntry lastSegmentIndexInfo = lastIndexPair.getFirst();
            IndexEntry lastConfIndexInfo = lastIndexPair.getSecond();

            /**
             * There exists a bad case, for example
             * The index db has index entries 1 ~ 12, but all of the index entries are log index, don't contain conf index
             * The segmentLog db has logs 1 ~ 12 and 16 ~ 19, the conf db has logs 13 ~ 15.
             * So in this case, the lastConfIndexInfo will be null, but we should set it to the first log position
             */
            if (lastSegmentIndexInfo == null) {
                lastSegmentIndexInfo = new IndexEntry(this.segmentLogDB.getFirstLogIndex(), FileHeader.HEADER_SIZE,
                    IndexType.IndexSegment.getType());
            }
            if (lastConfIndexInfo == null) {
                lastConfIndexInfo = new IndexEntry(this.confDB.getFirstLogIndex(), FileHeader.HEADER_SIZE,
                    IndexType.IndexConf.getType());
            }

            // Step2, Using two-way merging algorithm to construct ordered index entry array
            final LogEntryIterator segmentLogIterator = this.segmentLogDB.iterator(this.logEntryDecoder,
                lastSegmentIndexInfo.getLogIndex(), lastSegmentIndexInfo.getPosition());
            final LogEntryIterator confLogIterator = this.confDB.iterator(this.logEntryDecoder,
                lastConfIndexInfo.getLogIndex(), lastConfIndexInfo.getPosition());
            final List<IndexEntry> indexArray = generateOrderedIndexArrayByMergingLogIterator(segmentLogIterator,
                confLogIterator);

            // Step3, store array to indexDB
            long maxFlushPosition = this.indexDB.appendBatchIndexAsync(indexArray);

            // Step4, wait for flushing indexDB
            return this.indexDB.waitForFlush(maxFlushPosition, this.storeOptions.getMaxFlushTimes());
        }
    }
Check db's consistency and align the log;
@return true if align success;
jraft-extension/java-log-storage-impl/src/main/java/com/alipay/sofa/jraft/storage/LogitLogStorage.java