diff --git a/dbms/include/DB/IO/WriteBufferAIO.h b/dbms/include/DB/IO/WriteBufferAIO.h index 331e6ff042d..fabf48819c6 100644 --- a/dbms/include/DB/IO/WriteBufferAIO.h +++ b/dbms/include/DB/IO/WriteBufferAIO.h @@ -43,6 +43,7 @@ private: iocb cb; std::vector request_ptrs; std::vector events; + size_t total_bytes_written = 0; int fd = -1; // file descriptor bool is_pending_write = false; bool got_exception = false; diff --git a/dbms/src/IO/WriteBufferAIO.cpp b/dbms/src/IO/WriteBufferAIO.cpp index c8eeee54812..bae483b29d3 100644 --- a/dbms/src/IO/WriteBufferAIO.cpp +++ b/dbms/src/IO/WriteBufferAIO.cpp @@ -91,7 +91,7 @@ void WriteBufferAIO::nextImpl() cb.aio_fildes = fd; cb.aio_buf = reinterpret_cast(flush_buffer.buffer().begin()); cb.aio_nbytes = flush_buffer.offset(); - cb.aio_offset = 0; + cb.aio_offset = total_bytes_written; cb.aio_reqprio = 0; if ((cb.aio_nbytes % BLOCK_SIZE) != 0) @@ -130,6 +130,7 @@ void WriteBufferAIO::waitForCompletion() got_exception = true; throw Exception("Asynchronous write error on file " + filename, ErrorCodes::AIO_WRITE_ERROR); } + total_bytes_written += bytes_written; is_pending_write = false; }