diff --git a/src/Disks/ReadIndirectBufferFromRemoteFS.cpp b/src/Disks/ReadIndirectBufferFromRemoteFS.cpp index 2bbc2e2197e..960844e5281 100644 --- a/src/Disks/ReadIndirectBufferFromRemoteFS.cpp +++ b/src/Disks/ReadIndirectBufferFromRemoteFS.cpp @@ -87,10 +87,7 @@ bool ReadIndirectBufferFromRemoteFS::nextImpl() { /// Find first available buffer that fits to given offset. if (!current_buf) - { current_buf = initialize(); - pos = working_buffer.begin(); - } /// If current buffer has remaining data - use it. if (current_buf) @@ -115,10 +112,14 @@ bool ReadIndirectBufferFromRemoteFS::nextImpl() template bool ReadIndirectBufferFromRemoteFS::nextAndShiftPosition() { + /// Transfer current position and working_buffer to actual ReadBuffer swap(*current_buf); + /// Position and working_buffer will be updated in next() call auto result = current_buf->next(); + /// and assigned to current buffer. swap(*current_buf); + /// absolute position is shifted by a data size that was read in next() call above. if (result) absolute_position += working_buffer.size(); diff --git a/src/Disks/S3/DiskS3.cpp b/src/Disks/S3/DiskS3.cpp index 3ca8e07bba6..33c0c2a7f52 100644 --- a/src/Disks/S3/DiskS3.cpp +++ b/src/Disks/S3/DiskS3.cpp @@ -320,6 +320,7 @@ void DiskS3::startup() { auto settings = current_settings.get(); + /// Need to be enabled if it was disabled during shutdown() call. settings->client->EnableRequestProcessing(); if (!settings->send_metadata) diff --git a/src/IO/ReadBufferFromS3.cpp b/src/IO/ReadBufferFromS3.cpp index 86cf44178eb..0e342fb846a 100644 --- a/src/IO/ReadBufferFromS3.cpp +++ b/src/IO/ReadBufferFromS3.cpp @@ -91,18 +91,15 @@ bool ReadBufferFromS3::nextImpl() off_t ReadBufferFromS3::seek(off_t offset_, int whence) { + if (impl) + throw Exception("Seek is allowed only before first read attempt from the buffer.", ErrorCodes::CANNOT_SEEK_THROUGH_FILE); + if (whence != SEEK_SET) throw Exception("Only SEEK_SET mode is allowed.", ErrorCodes::CANNOT_SEEK_THROUGH_FILE); if (offset_ < 0) throw Exception("Seek position is out of bounds. Offset: " + std::to_string(offset_), ErrorCodes::SEEK_POSITION_OUT_OF_BOUND); - if (impl) - { - impl.reset(); - pos = working_buffer.end(); - } - offset = offset_; return offset;