From d7fc7a429028b7ebf2910100834d87de91efc0e7 Mon Sep 17 00:00:00 2001 From: Smita Kulkarni Date: Fri, 15 Jul 2022 16:08:53 +0200 Subject: [PATCH] Addressed review comments - Removed first_buffer, finalizeImpl and logic to different buffer size from ForkWriteBuffer --- src/IO/ForkWriteBuffer.cpp | 37 ++++--------------------------------- src/IO/ForkWriteBuffer.h | 2 -- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/src/IO/ForkWriteBuffer.cpp b/src/IO/ForkWriteBuffer.cpp index b055ae588a9..e91f6ca433b 100644 --- a/src/IO/ForkWriteBuffer.cpp +++ b/src/IO/ForkWriteBuffer.cpp @@ -16,46 +16,23 @@ ForkWriteBuffer::ForkWriteBuffer(WriteBufferPtrs && sources_) { if (sources.empty()) { - first_buffer = nullptr; throw Exception("ForkWriteBuffer required WriteBuffer is not provided", ErrorCodes::CANNOT_CREATE_IO_BUFFER); } - else - { - first_buffer = sources.begin()->get(); - set(first_buffer->buffer().begin(), first_buffer->buffer().size()); - } + set(sources.front()->buffer().begin(), sources.front()->buffer().size()); } void ForkWriteBuffer::nextImpl() { - if (!first_buffer) - return; - - first_buffer->position() = position(); + sources.front()->position() = position(); try { for (const WriteBufferPtr & write_buffer : sources | std::views::reverse) { - if (write_buffer.get() != first_buffer) + if (write_buffer != sources.front()) { - //if buffer size if not enough to write, then split the message with buffer length - if (write_buffer->available() < first_buffer->offset()) - { - size_t bytes_written = 0; - auto to_be_written = first_buffer->offset(); - while (to_be_written != 0) - { - int bytes_to_copy = std::min(to_be_written, write_buffer->available()); - write_buffer->write(first_buffer->buffer().begin()+bytes_written, bytes_to_copy); - write_buffer->next(); - bytes_written += bytes_to_copy; - to_be_written -= bytes_to_copy; - } - } - else - write_buffer->write(first_buffer->buffer().begin(), first_buffer->offset()); + write_buffer->write(sources.front()->buffer().begin(), sources.front()->offset()); } write_buffer->next(); } @@ -68,12 +45,6 @@ void ForkWriteBuffer::nextImpl() } -void ForkWriteBuffer::finalizeImpl() -{ - next(); -} - - ForkWriteBuffer::~ForkWriteBuffer() { finalize(); diff --git a/src/IO/ForkWriteBuffer.h b/src/IO/ForkWriteBuffer.h index 63267fcd8d7..56e9c445842 100644 --- a/src/IO/ForkWriteBuffer.h +++ b/src/IO/ForkWriteBuffer.h @@ -25,11 +25,9 @@ public: protected: void nextImpl() override; - void finalizeImpl() override; private: WriteBufferPtrs sources; - WriteBuffer *first_buffer; }; }