private SegmentFile createNewSegmentFile(final long logIndex, final int oldSegmentCount,
                                             final WriteContext ctx) throws InterruptedException, IOException {
        SegmentFile segmentFile = null;
        this.writeLock.lock();
        try {
            // CAS by segments count.
            if (this.segments.size() != oldSegmentCount) {
                return segmentFile;
            }
            if (!this.segments.isEmpty()) {
                // Sync current last file and correct it's lastLogIndex.
                final SegmentFile currLastFile = getLastSegmentWithoutLock();
                currLastFile.setLastLogIndex(logIndex - 1);
                ctx.startJob();
                // Attach a finish hook to set last segment file to be read-only.
                ctx.addFinishHook(() -> currLastFile.setReadOnly(true));
                // Run sync in parallel
                this.writeExecutor.execute(() -> {
                    try {
                        currLastFile.sync(isSync());
                    } catch (final IOException e) {
                        ctx.setError(e);
                    } finally {
                        ctx.finishJob();
                    }

                });

            }
            segmentFile = allocateSegmentFile(logIndex);
            return segmentFile;
        } finally {
            this.writeLock.unlock();
        }

    }
Creates a RocksDBSegmentLogStorage builder.
@return a builder instance.
jraft-core/src/main/java/com/alipay/sofa/jraft/storage/log/RocksDBSegmentLogStorage.java