Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw CURRENT_WRITE_BUFFER_IS_EXHAUSTED for normal behaviour #48288

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/IO/CascadeWriteBuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <IO/CascadeWriteBuffer.h>
#include <IO/MemoryReadWriteBuffer.h>
#include <Common/Exception.h>

namespace DB
Expand Down Expand Up @@ -35,9 +36,9 @@ void CascadeWriteBuffer::nextImpl()
curr_buffer->position() = position();
curr_buffer->next();
}
catch (const Exception & e)
catch (const MemoryWriteBuffer::CurrentBufferExhausted &)
{
if (curr_buffer_num < num_sources && e.code() == ErrorCodes::CURRENT_WRITE_BUFFER_IS_EXHAUSTED)
if (curr_buffer_num < num_sources)
{
/// TODO: protocol should require set(position(), 0) before Exception

Expand All @@ -46,7 +47,7 @@ void CascadeWriteBuffer::nextImpl()
curr_buffer = setNextBuffer();
}
else
throw;
throw Exception(ErrorCodes::CURRENT_WRITE_BUFFER_IS_EXHAUSTED, "MemoryWriteBuffer limit is exhausted");
}

set(curr_buffer->position(), curr_buffer->buffer().end() - curr_buffer->position());
Expand Down
2 changes: 1 addition & 1 deletion src/IO/CascadeWriteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace ErrorCodes
* (lazy_sources contains not pointers themself, but their delayed constructors)
*
* Firtly, CascadeWriteBuffer redirects data to first buffer of the sequence
* If current WriteBuffer cannot receive data anymore, it throws special exception CURRENT_WRITE_BUFFER_IS_EXHAUSTED in nextImpl() body,
* If current WriteBuffer cannot receive data anymore, it throws special exception MemoryWriteBuffer::CurrentBufferExhausted in nextImpl() body,
* CascadeWriteBuffer prepare next buffer and continuously redirects data to it.
* If there are no buffers anymore CascadeWriteBuffer throws an exception.
*
Expand Down
8 changes: 1 addition & 7 deletions src/IO/MemoryReadWriteBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
namespace DB
{

namespace ErrorCodes
{
extern const int CURRENT_WRITE_BUFFER_IS_EXHAUSTED;
}


class ReadBufferFromMemoryWriteBuffer : public ReadBuffer, boost::noncopyable, private Allocator<false>
{
public:
Expand Down Expand Up @@ -118,7 +112,7 @@ void MemoryWriteBuffer::addChunk()
if (0 == next_chunk_size)
{
set(position(), 0);
throw Exception(ErrorCodes::CURRENT_WRITE_BUFFER_IS_EXHAUSTED, "MemoryWriteBuffer limit is exhausted");
throw MemoryWriteBuffer::CurrentBufferExhausted();
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/IO/MemoryReadWriteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ namespace DB
class MemoryWriteBuffer : public WriteBuffer, public IReadableWriteBuffer, boost::noncopyable, private Allocator<false>
{
public:
/// Special exception to throw when the current WriteBuffer cannot receive data
class CurrentBufferExhausted : public std::exception
{
public:
const char * what() const noexcept override { return "MemoryWriteBuffer limit is exhausted"; }
};

/// Use max_total_size_ = 0 for unlimited storage
explicit MemoryWriteBuffer(
Expand Down
2 changes: 1 addition & 1 deletion src/IO/tests/gtest_cascade_and_memory_write_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ TEST(MemoryWriteBuffer, WriteAndReread)
if (s > 1)
{
MemoryWriteBuffer buf(s - 1);
EXPECT_THROW(buf.write(data.data(), data.size()), DB::Exception);
EXPECT_THROW(buf.write(data.data(), data.size()), MemoryWriteBuffer::CurrentBufferExhausted);
}
}

Expand Down