public AbstractFile findFileByOffset(final long offset, final boolean returnFirstIfNotFound) {
        this.readLock.lock();
        try {
            if (this.files.size() == 0)
                return null;
            final AbstractFile firstAbstractFile = getFirstFile();
            final AbstractFile lastAbstractFile = getLastFile();
            if (firstAbstractFile != null && lastAbstractFile != null) {
                if (offset < firstAbstractFile.getFileFromOffset()
                    || offset >= lastAbstractFile.getFileFromOffset() + this.fileSize) {
                    LOG.warn(
                        "Offset not matched. Request offset: {}, firstOffset: {}, lastOffset: {}, fileSize: {}, fileNums: {}",
                        offset, firstAbstractFile.getFileFromOffset(), lastAbstractFile.getFileFromOffset()
                                                                       + this.fileSize, this.fileSize,
                        this.files.size());
                } else {
                    // Locate the index
                    final int index = (int) ((offset / this.fileSize) - (firstAbstractFile.getFileFromOffset() / this.fileSize));
                    AbstractFile targetFile;
                    targetFile = this.files.get(index);

                    if (targetFile != null && offset >= targetFile.getFileFromOffset()
                        && offset < targetFile.getFileFromOffset() + this.fileSize) {
                        return targetFile;
                    }

                    // If pre not found , then traverse to find target file
                    for (final AbstractFile abstractFile : this.files) {
                        if (offset >= abstractFile.getFileFromOffset()
                            && offset < abstractFile.getFileFromOffset() + this.fileSize) {
                            return abstractFile;
                        }
                    }
                }
                if (returnFirstIfNotFound) {
                    return firstAbstractFile;
                }
            }
        } catch (final Exception e) {
            LOG.error("Error on find abstractFile by offset :{}, file type:{}", offset, this.fileType.getFileName(), e);
        } finally {
            this.readLock.unlock();
        }
        return null;
    }
@return the file that contains this offset
jraft-extension/java-log-storage-impl/src/main/java/com/alipay/sofa/jraft/storage/file/FileManager.java