ClickHouse/src/IO/BoundedReadBuffer.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
1.1 KiB
C++
Raw Normal View History

2022-05-25 20:45:31 +00:00
#pragma once
#include <IO/ReadBufferFromFileDecorator.h>
2022-05-25 18:28:46 +00:00
namespace DB
{
2022-07-17 13:13:28 +00:00
/// A buffer which allows to make an underlying buffer as right bounded,
/// e.g. the buffer cannot return data beyond offset specified in `setReadUntilPosition`.
class BoundedReadBuffer : public ReadBufferFromFileDecorator
2022-05-25 18:28:46 +00:00
{
public:
explicit BoundedReadBuffer(std::unique_ptr<SeekableReadBuffer> impl_);
2022-05-25 18:28:46 +00:00
bool supportsRightBoundedReads() const override { return true; }
void setReadUntilPosition(size_t position) override;
void setReadUntilEnd() override;
bool nextImpl() override;
off_t seek(off_t off, int whence) override;
2022-05-30 18:35:31 +00:00
size_t getFileOffsetOfBufferEnd() const override { return file_offset_of_buffer_end; }
/// file_offset_of_buffer_end can differ from impl's file_offset_of_buffer_end
2022-05-30 19:32:49 +00:00
/// because of resizing of the tail. => Need to also override getPosition() as
2022-05-30 18:35:31 +00:00
/// it uses file_offset_of_buffer_end.
off_t getPosition() override;
2022-05-25 18:28:46 +00:00
private:
std::optional<size_t> read_until_position;
2023-06-27 13:49:26 +00:00
/// atomic because can be used in log or exception messages while being updated.
std::atomic<size_t> file_offset_of_buffer_end = 0;
2022-05-25 18:28:46 +00:00
};
}