PeekableReadBufferCheckpoint

This commit is contained in:
Alexander Tokmakov 2019-05-17 04:12:32 +03:00 committed by Alexander Tokmakov
parent 456a8c4b17
commit 7e9c3f2022
2 changed files with 13 additions and 2 deletions

View File

@ -268,7 +268,7 @@ bool PeekableReadBuffer::checkpointInOwnMemory() const
return checkpoint_in_own_memory;
}
void PeekableReadBuffer::assertCanBeDistructed() const
void PeekableReadBuffer::assertCanBeDestructed() const
{
if (peeked_size && pos != memory.data() + peeked_size)
throw DB::Exception("There are data, which were extracted from sub-buffer, but not from peekable buffer: "

View File

@ -49,7 +49,7 @@ public:
/// but not from this buffer, so the data will not be lost after destruction of this buffer.
/// If position is in sub-buffer, returns empty buffer.
std::shared_ptr<BufferWithOwnMemory<ReadBuffer>> takeUnreadData();
void assertCanBeDistructed() const;
void assertCanBeDestructed() const;
private:
@ -59,6 +59,7 @@ private:
inline bool currentlyReadFromOwnMemory() const;
inline bool checkpointInOwnMemory() const;
// TODO add unit test for PeekableReadBuffer and remove this method
void checkStateCorrect() const;
/// Makes possible to append `bytes_to_append` bytes to data in own memory.
@ -74,4 +75,14 @@ private:
bool checkpoint_in_own_memory = false;
};
class PeekableReadBufferCheckpoint : boost::noncopyable
{
PeekableReadBuffer & buf;
public:
explicit PeekableReadBufferCheckpoint(PeekableReadBuffer & buf_) : buf(buf_) { buf.setCheckpoint(); }
~PeekableReadBufferCheckpoint() { buf.dropCheckpoint(); }
};
}