From c7a4225f0ea3d74c0a42e68f0b337c1ff59e0c3c Mon Sep 17 00:00:00 2001 From: Alexey Arno Date: Tue, 7 Apr 2015 02:21:20 +0300 Subject: [PATCH] dbms: Server: feature development. [#METR-15090] --- dbms/include/DB/IO/WriteBufferAIO.h | 2 +- dbms/src/IO/WriteBufferAIO.cpp | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/dbms/include/DB/IO/WriteBufferAIO.h b/dbms/include/DB/IO/WriteBufferAIO.h index 2379942be70..ba8fa7330b6 100644 --- a/dbms/include/DB/IO/WriteBufferAIO.h +++ b/dbms/include/DB/IO/WriteBufferAIO.h @@ -40,7 +40,7 @@ private: /// void nextImpl() override; /// Ждать окончания текущей асинхронной задачи. - void waitForAIOCompletion(); + bool waitForAIOCompletion(); /// Менять местами основной и дублирующий буферы. void swapBuffers() noexcept; /// diff --git a/dbms/src/IO/WriteBufferAIO.cpp b/dbms/src/IO/WriteBufferAIO.cpp index 596bdb80184..24ae404b4ec 100644 --- a/dbms/src/IO/WriteBufferAIO.cpp +++ b/dbms/src/IO/WriteBufferAIO.cpp @@ -136,7 +136,8 @@ void WriteBufferAIO::sync() void WriteBufferAIO::flush() { next(); - waitForAIOCompletion(); + if (waitForAIOCompletion()) + finalize(); } void WriteBufferAIO::nextImpl() @@ -144,7 +145,8 @@ void WriteBufferAIO::nextImpl() if (!offset()) return; - waitForAIOCompletion(); + if (waitForAIOCompletion()) + finalize(); swapBuffers(); prepare(); @@ -195,10 +197,10 @@ void WriteBufferAIO::nextImpl() is_pending_write = true; } -void WriteBufferAIO::waitForAIOCompletion() +bool WriteBufferAIO::waitForAIOCompletion() { if (!is_pending_write) - return; + return false; while (io_getevents(aio_context.ctx, events.size(), events.size(), &events[0], nullptr) < 0) { @@ -212,13 +214,7 @@ void WriteBufferAIO::waitForAIOCompletion() is_pending_write = false; bytes_written = events[0].res; - if (bytes_written < bytes_to_write) - { - got_exception = true; - throw Exception("Asynchronous write error on file " + filename, ErrorCodes::AIO_WRITE_ERROR); - } - - finalize(); + return true; } void WriteBufferAIO::swapBuffers() noexcept @@ -423,6 +419,12 @@ void WriteBufferAIO::prepare() void WriteBufferAIO::finalize() { + if (bytes_written < bytes_to_write) + { + got_exception = true; + throw Exception("Asynchronous write error on file " + filename, ErrorCodes::AIO_WRITE_ERROR); + } + bytes_written -= truncation_count; off_t pos_offset = bytes_written - (pos_in_file - request.aio_offset);