@Override
    protected boolean onInitLoaded() {
        final long startMs = Utils.monotonicMs();
        this.writeLock.lock();
        try {
            final File segmentsDir = new File(this.segmentsPath);
            if (!ensureDir(segmentsDir)) {
                return false;
            }
            final Checkpoint checkpoint = loadCheckpoint();

            final File[] segmentFiles = segmentsDir
                    .listFiles((final File dir, final String name) -> SEGMENT_FILE_NAME_PATTERN.matcher(name).matches());

            final boolean normalExit = !this.abortFile.exists();
            if (!normalExit) {
                LOG.info("{} {} did not exit normally, will try to recover last file.", getServiceName(),
                    this.segmentsPath);
            }
            this.segments = new ArrayList<>(segmentFiles == null ? 10 : segmentFiles.length);
            this.blankSegments = new ArrayDeque<>();
            List<File> corruptedHeaderSegments = new ArrayList<>();

            if (segmentFiles != null && segmentFiles.length > 0) {
                // Sort by sequences.
                Arrays.sort(segmentFiles, Comparator.comparing(RocksDBSegmentLogStorage::getFileSequenceFromFileName));

                final String checkpointSegFile = getCheckpointSegFilePath(checkpoint);

                // mmap files
                for (int i = 0; i < segmentFiles.length; i++) {
                    final File segFile = segmentFiles[i];
                    this.nextFileSequence.set(getFileSequenceFromFileName(segFile) + 1);
                    final SegmentFile segmentFile = new SegmentFile(this.maxSegmentFileSize, segFile.getAbsolutePath(),
                        this.writeExecutor);

                    if (!segmentFile.mmapFile(false)) {
                      assert (segmentFile.isHeaderCorrupted());
                      corruptedHeaderSegments.add(segFile);
                      continue;
                    }

                    if (segmentFile.isBlank()) {
                      this.blankSegments.add(new AllocatedResult(segmentFile));
                    } else if (segmentFile.isHeaderCorrupted()) {
                      corruptedHeaderSegments.add(segFile);
                    } else {
                      this.segments.add(segmentFile);
                    }
                }

                // Processing corrupted header files
                //TODO(boyan) maybe we can find a better solution for such case that new allocated segment file is corrupted when power failure etc.
                if(!processCorruptedHeaderFiles(corruptedHeaderSegments)) {
                  return false;
                }

                // init blank segments
                if(!initBlankFiles()) {
                  return false;
                }

                // try to recover segments
                if(!recoverFiles(checkpoint, normalExit, checkpointSegFile)) {
                  return false;
                }
            } else {
                if (checkpoint != null) {
                    LOG.warn("Missing segment files, checkpoint is: {}", checkpoint);
                    return false;
                }
            }

            LOG.info("{} Loaded {} segment files and  {} blank segment files from path {}.", getServiceName(),
                this.segments.size(), this.blankSegments.size(), this.segmentsPath);

            LOG.info("{} segments: \n{}", getServiceName(), descSegments());

            startCheckpointTask();

            if (normalExit) {
                if (!this.abortFile.create()) {
                    LOG.error("Fail to create abort file {}.", this.abortFile.getPath());
                    return false;
                }
            } else {
                this.abortFile.touch();
            }
            startSegmentAllocator();

            return true;
        } catch (final Exception e) {
            LOG.error("Fail to load segment files from directory {}.", this.segmentsPath, e);
            return false;
        } finally {
            this.writeLock.unlock();
            LOG.info("{} init and load cost {} ms.", getServiceName(), Utils.monotonicMs() - startMs);
        }
    }
Creates a RocksDBSegmentLogStorage builder.
@return a builder instance.
jraft-core/src/main/java/com/alipay/sofa/jraft/storage/log/RocksDBSegmentLogStorage.java