diff --git a/dbms/src/IO/PeekableReadBuffer.cpp b/dbms/src/IO/PeekableReadBuffer.cpp index 6d70f790b54..f624d8b8104 100644 --- a/dbms/src/IO/PeekableReadBuffer.cpp +++ b/dbms/src/IO/PeekableReadBuffer.cpp @@ -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: " diff --git a/dbms/src/IO/PeekableReadBuffer.h b/dbms/src/IO/PeekableReadBuffer.h index d36bb544940..e6079c4f33e 100644 --- a/dbms/src/IO/PeekableReadBuffer.h +++ b/dbms/src/IO/PeekableReadBuffer.h @@ -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> 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(); } + +}; + }