private boolean recoverFiles(final Checkpoint checkpoint, final boolean normalExit, final String checkpointSegFile) {
        boolean needRecover = false;
        SegmentFile prevFile = null;
        for (int i = 0; i < this.segments.size(); i++) {
            final boolean isLastFile = i == this.segments.size() - 1;
            SegmentFile segmentFile = this.segments.get(i);
            int pos = segmentFile.getSize();
            if (StringUtil.equalsIgnoreCase(checkpointSegFile, segmentFile.getFilename())) {
                needRecover = true;
                assert (checkpoint != null);
                pos = checkpoint.committedPos;
            } else {
                if (needRecover) {
                    pos = 0;
                }
            }

            final SegmentFileOptions opts = SegmentFileOptions.builder() //
                .setSync(isSync()) //
                .setRecover(needRecover && !normalExit) //
                .setLastFile(isLastFile) //
                .setNewFile(false) //
                .setPos(pos).build();

            if (!segmentFile.init(opts)) {
                LOG.error("Fail to load segment file {}.", segmentFile.getPath());
                segmentFile.shutdown();
                return false;
            }
            /**
             * It's wrote position is from start(HEADER_SIZE) but it's not the last file, SHOULD not happen.
             */
            if (segmentFile.getWrotePos() == SegmentFile.HEADER_SIZE && !isLastFile) {
                LOG.error("Detected corrupted segment file {}.", segmentFile.getPath());
                return false;
            }

            if (prevFile != null) {
                prevFile.setLastLogIndex(segmentFile.getFirstLogIndex() - 1);
            }
            prevFile = segmentFile;
        }
        if (getLastLogIndex() > 0 && prevFile != null) {
            prevFile.setLastLogIndex(getLastLogIndex());
        }
        return true;
    }
Creates a RocksDBSegmentLogStorage builder.
@return a builder instance.
jraft-core/src/main/java/com/alipay/sofa/jraft/storage/log/RocksDBSegmentLogStorage.java