diff --git a/src/Disks/IO/AsynchronousReadIndirectBufferFromRemoteFS.cpp b/src/Disks/IO/AsynchronousReadIndirectBufferFromRemoteFS.cpp index 43695287325..e693024449e 100644 --- a/src/Disks/IO/AsynchronousReadIndirectBufferFromRemoteFS.cpp +++ b/src/Disks/IO/AsynchronousReadIndirectBufferFromRemoteFS.cpp @@ -70,12 +70,12 @@ bool AsynchronousReadIndirectBufferFromRemoteFS::hasPendingDataToRead() if (read_until_position) { /// Everything is already read. - if (file_offset_of_buffer_end == read_until_position) + if (file_offset_of_buffer_end == *read_until_position) return false; - if (file_offset_of_buffer_end > read_until_position) + if (file_offset_of_buffer_end > *read_until_position) throw Exception(ErrorCodes::LOGICAL_ERROR, "Read beyond last offset ({} > {})", - file_offset_of_buffer_end, read_until_position); + file_offset_of_buffer_end, *read_until_position); } else if (must_read_until_position) throw Exception(ErrorCodes::LOGICAL_ERROR, @@ -124,7 +124,7 @@ void AsynchronousReadIndirectBufferFromRemoteFS::setReadUntilPosition(size_t pos throw Exception(ErrorCodes::LOGICAL_ERROR, "Prefetch is valid in readUntilPosition"); read_until_position = position; - impl->setReadUntilPosition(read_until_position); + impl->setReadUntilPosition(*read_until_position); } @@ -134,7 +134,7 @@ void AsynchronousReadIndirectBufferFromRemoteFS::setReadUntilEnd() throw Exception(ErrorCodes::LOGICAL_ERROR, "Prefetch is valid in readUntilEnd"); read_until_position = impl->getFileSize(); - impl->setReadUntilPosition(read_until_position); + impl->setReadUntilPosition(*read_until_position); } @@ -232,7 +232,7 @@ off_t AsynchronousReadIndirectBufferFromRemoteFS::seek(off_t offset_, int whence pos = working_buffer.end(); /// Note: we read in range [file_offset_of_buffer_end, read_until_position). - if (file_offset_of_buffer_end < read_until_position + if (read_until_position && file_offset_of_buffer_end < *read_until_position && static_cast(file_offset_of_buffer_end) >= getPosition() && static_cast(file_offset_of_buffer_end) < getPosition() + static_cast(min_bytes_for_seek)) { diff --git a/src/Disks/IO/AsynchronousReadIndirectBufferFromRemoteFS.h b/src/Disks/IO/AsynchronousReadIndirectBufferFromRemoteFS.h index d8fad08bc8a..2e37f448fe1 100644 --- a/src/Disks/IO/AsynchronousReadIndirectBufferFromRemoteFS.h +++ b/src/Disks/IO/AsynchronousReadIndirectBufferFromRemoteFS.h @@ -76,7 +76,7 @@ private: size_t bytes_to_ignore = 0; - size_t read_until_position = 0; + std::optional read_until_position = 0; bool must_read_until_position; };