From 7e9c3f20222395ac72f0f8e7189ef9249b35d5d4 Mon Sep 17 00:00:00 2001 From: Alexander Tokmakov Date: Fri, 17 May 2019 04:12:32 +0300 Subject: [PATCH] PeekableReadBufferCheckpoint --- dbms/src/IO/PeekableReadBuffer.cpp | 2 +- dbms/src/IO/PeekableReadBuffer.h | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) 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(); } + +}; + }