diff --git a/dbms/src/IO/AIO.cpp b/dbms/src/IO/AIO.cpp index 5b684e8ef60..ed22b263a94 100644 --- a/dbms/src/IO/AIO.cpp +++ b/dbms/src/IO/AIO.cpp @@ -55,14 +55,14 @@ AIOContext::~AIOContext() #elif defined(__FreeBSD__) -#include -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include +# include -#include +# include /** Small wrappers for asynchronous I/O. @@ -70,10 +70,10 @@ AIOContext::~AIOContext() namespace DB { - namespace ErrorCodes - { - extern const int CANNOT_IOSETUP; - } +namespace ErrorCodes +{ + extern const int CANNOT_IOSETUP; +} } @@ -89,47 +89,46 @@ int io_destroy(int ctx) int io_submit(int ctx, long nr, struct iocb * iocbpp[]) { - long i; - int r; - struct sigevent *se; - struct aiocb *iocb; + for (long i = 0; i < nr; i++) + { + struct aiocb * iocb = &iocbpp[i]->aio; - for (i = 0; i < nr; i ++) { - iocb = &iocbpp[i]->aio; + struct sigevent * se = &iocb->aio_sigevent; + se->sigev_notify_kqueue = ctx; + se->sigev_notify_kevent_flags = 0; + se->sigev_notify = SIGEV_KEVENT; + se->sigev_value.sival_ptr = iocbpp[i]; - se = &iocb->aio_sigevent; - se->sigev_notify_kqueue = ctx; - se->sigev_notify_kevent_flags = 0; - se->sigev_notify = SIGEV_KEVENT; - se->sigev_value.sival_ptr = iocbpp[i]; - - switch(iocb->aio_lio_opcode) { - case LIO_READ: - r = aio_read(iocb); - break; - case LIO_WRITE: - r = aio_write(iocb); - break; - default: break; - } - if (r < 0) { - return r; - } + switch (iocb->aio_lio_opcode) + { + case LIO_READ: + { + int r = aio_read(iocb); + if (r < 0) + return r; + break; + } + case LIO_WRITE: + { + int r = aio_write(iocb); + if (r < 0) + return r; + break; + } + } } - return i; + return nr; } -int io_getevents(int ctx, long min_nr, long max_nr, struct kevent * events, struct timespec * timeout) +int io_getevents(int ctx, long, long max_nr, struct kevent * events, struct timespec * timeout) { - min_nr = 0; return kevent(ctx, NULL, 0, events, max_nr, timeout); } -AIOContext::AIOContext(unsigned int nr_events) +AIOContext::AIOContext(unsigned int) { - nr_events = 0; ctx = io_setup(); if (ctx < 0) DB::throwFromErrno("io_setup failed", DB::ErrorCodes::CANNOT_IOSETUP); diff --git a/dbms/src/IO/AIO.h b/dbms/src/IO/AIO.h index 09363838aac..5813fea038f 100644 --- a/dbms/src/IO/AIO.h +++ b/dbms/src/IO/AIO.h @@ -50,7 +50,8 @@ struct AIOContext : private boost::noncopyable typedef struct kevent io_event; typedef int aio_context_t; -struct iocb { +struct iocb +{ struct aiocb aio; long aio_data; }; diff --git a/dbms/src/IO/AIOContextPool.cpp b/dbms/src/IO/AIOContextPool.cpp index db73e29fee6..7453452ea39 100644 --- a/dbms/src/IO/AIOContextPool.cpp +++ b/dbms/src/IO/AIOContextPool.cpp @@ -95,7 +95,7 @@ void AIOContextPool::fulfillPromises(const io_event events[], const int num_even } #if defined(__FreeBSD__) - it->second.set_value(aio_return((struct aiocb *)event.udata)); + it->second.set_value(aio_return(reinterpret_cast(event.udata))); #else it->second.set_value(event.res); #endif diff --git a/dbms/src/IO/ReadBufferAIO.cpp b/dbms/src/IO/ReadBufferAIO.cpp index 78e11ed367d..ccbc0dfe818 100644 --- a/dbms/src/IO/ReadBufferAIO.cpp +++ b/dbms/src/IO/ReadBufferAIO.cpp @@ -122,14 +122,17 @@ bool ReadBufferAIO::nextImpl() #if defined(__FreeBSD__) request.aio.aio_lio_opcode = LIO_READ; - request.aio.aio_buf = reinterpret_cast(buffer_begin); -#else - request.aio_lio_opcode = IOCB_CMD_PREAD; - request.aio_buf = reinterpret_cast(buffer_begin); -#endif request.aio.aio_fildes = fd; + request.aio.aio_buf = reinterpret_cast(buffer_begin); request.aio.aio_nbytes = region_aligned_size; request.aio.aio_offset = region_aligned_begin; +#else + request.aio_lio_opcode = IOCB_CMD_PREAD; + request.aio_fildes = fd; + request.aio_buf = reinterpret_cast(buffer_begin); + request.aio_nbytes = region_aligned_size; + request.aio_offset = region_aligned_begin; +#endif /// Send the request. try diff --git a/dbms/src/IO/WriteBufferAIO.cpp b/dbms/src/IO/WriteBufferAIO.cpp index d22e1cf5412..2fe7da27809 100644 --- a/dbms/src/IO/WriteBufferAIO.cpp +++ b/dbms/src/IO/WriteBufferAIO.cpp @@ -112,14 +112,17 @@ void WriteBufferAIO::nextImpl() #if defined(__FreeBSD__) request.aio.aio_lio_opcode = LIO_WRITE; - request.aio.aio_buf = reinterpret_cast(buffer_begin); -#else - request.aio_lio_opcode = IOCB_CMD_PWRITE; - request.aio_buf = reinterpret_cast(buffer_begin); -#endif request.aio.aio_fildes = fd; + request.aio.aio_buf = reinterpret_cast(buffer_begin); request.aio.aio_nbytes = region_aligned_size; request.aio.aio_offset = region_aligned_begin; +#else + request.aio_lio_opcode = IOCB_CMD_PWRITE; + request.aio_fildes = fd; + request.aio_buf = reinterpret_cast(buffer_begin); + request.aio_nbytes = region_aligned_size; + request.aio_offset = region_aligned_begin; +#endif /// Send the request. while (io_submit(aio_context.ctx, 1, &request_ptr) < 0) @@ -199,7 +202,7 @@ bool WriteBufferAIO::waitForAIOCompletion() is_pending_write = false; #if defined(__FreeBSD__) - bytes_written = aio_return((struct aiocb *)event.udata); + bytes_written = aio_return(reinterpret_cast(event.udata)); #else bytes_written = event.res; #endif @@ -405,7 +408,13 @@ void WriteBufferAIO::finalize() bytes_written -= truncation_count; - off_t pos_offset = bytes_written - (pos_in_file - request.aio.aio_offset); +#if defined(__FreeBSD__) + off_t aio_offset = request.aio.aio_offset; +#else + off_t aio_offset = request.aio_offset; +#endif + off_t pos_offset = bytes_written - (pos_in_file - aio_offset); + if (pos_in_file > (std::numeric_limits::max() - pos_offset)) throw Exception("An overflow occurred during file operation", ErrorCodes::LOGICAL_ERROR); pos_in_file += pos_offset;