From cdfb096f8f38c15ee93567faf8228631eb6d9c2e Mon Sep 17 00:00:00 2001 From: Alexey Arno Date: Fri, 6 Mar 2015 14:08:25 +0300 Subject: [PATCH] dbms: Server: feature development. [#METR-15090] --- dbms/include/DB/IO/ReadBufferAIO.h | 1 + dbms/src/IO/ReadBufferAIO.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dbms/include/DB/IO/ReadBufferAIO.h b/dbms/include/DB/IO/ReadBufferAIO.h index 3dcfaaa8dc8..cb134b417c6 100644 --- a/dbms/include/DB/IO/ReadBufferAIO.h +++ b/dbms/include/DB/IO/ReadBufferAIO.h @@ -46,6 +46,7 @@ private: std::vector request_ptrs; std::vector events; size_t max_bytes_read = std::numeric_limits::max(); + size_t total_bytes_read = 0; int fd = -1; // file descriptor off_t pos_in_file = 0; bool is_pending_read = false; diff --git a/dbms/src/IO/ReadBufferAIO.cpp b/dbms/src/IO/ReadBufferAIO.cpp index a3d3afdda68..79b83ce77c9 100644 --- a/dbms/src/IO/ReadBufferAIO.cpp +++ b/dbms/src/IO/ReadBufferAIO.cpp @@ -118,7 +118,7 @@ bool ReadBufferAIO::nextImpl() cb.aio_lio_opcode = IOCB_CMD_PREAD; cb.aio_fildes = fd; cb.aio_buf = reinterpret_cast(fill_buffer.internalBuffer().begin()); - cb.aio_nbytes = fill_buffer.internalBuffer().size(); + cb.aio_nbytes = std::min(fill_buffer.internalBuffer().size(), max_bytes_read); cb.aio_offset = 0; cb.aio_reqprio = 0; @@ -154,11 +154,18 @@ void ReadBufferAIO::waitForCompletion() is_pending_read = false; size_t bytes_read = (events[0].res > 0) ? static_cast(events[0].res) : 0; + if ((bytes_read % BLOCK_SIZE) != 0) + { + got_exception = true; + throw Exception("Received unaligned number of bytes from file " + filename, ErrorCodes::AIO_UNALIGNED_BUFFER_ERROR); + } + pos_in_file += bytes_read; + total_bytes_read += bytes_read; if (bytes_read > 0) fill_buffer.buffer().resize(bytes_read); - if (bytes_read < fill_buffer.internalBuffer().size()) + if ((bytes_read < fill_buffer.internalBuffer().size()) || (total_bytes_read == max_bytes_read)) is_eof = true; } }