public AbstractFile getLastFile(final long logIndex, final int waitToWroteSize, final boolean createIfNecessary) {
        AbstractFile lastFile = null;
        while (true) {
            int fileCount = 0;
            this.readLock.lock();
            try {
                if (!this.files.isEmpty()) {
                    fileCount = this.files.size();
                    final AbstractFile file = this.files.get(fileCount - 1);
                    if (waitToWroteSize <= 0 || !file.reachesFileEndBy(waitToWroteSize)) {
                        lastFile = file;
                    } else if (file.reachesFileEndBy(waitToWroteSize)) {
                        // Reach file end , need to fill blank bytes in file end
                        file.fillEmptyBytesInFileEnd();
                    }
                }
            } finally {
                this.readLock.unlock();
            }
            // Try to get a new file
            if (lastFile == null && createIfNecessary) {
                this.writeLock.lock();
                try {
                    if (this.files.size() != fileCount) {
                        // That means already create a new file , just continue and try again
                        continue;
                    }
                    lastFile = this.allocateService.takeEmptyFile();
                    if (lastFile != null) {
                        final long newFileOffset = (long) this.files.size() * (long) this.fileSize;
                        lastFile.setFileFromOffset(newFileOffset);
                        this.files.add(lastFile);
                        this.swapOutFilesIfNecessary();
                        return lastFile;
                    } else {
                        continue;
                    }
                } catch (final Exception e) {
                    LOG.error("Error on create new abstract file , current logIndex:{}", logIndex);
                } finally {
                    this.writeLock.unlock();
                }
            }
            return lastFile;
        }
    }
Check file's correctness of name and length
@return mmap file
jraft-extension/java-log-storage-impl/src/main/java/com/alipay/sofa/jraft/storage/file/FileManager.java