2015-03-04 10:47:53 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-03-06 16:16:10 +00:00
|
|
|
#include <DB/IO/IBufferAIO.h>
|
2015-03-04 10:47:53 +00:00
|
|
|
#include <DB/IO/ReadBuffer.h>
|
|
|
|
#include <DB/IO/BufferWithOwnMemory.h>
|
|
|
|
#include <statdaemons/AIO.h>
|
|
|
|
|
2015-03-05 16:20:15 +00:00
|
|
|
#include <limits>
|
|
|
|
|
2015-03-05 14:21:55 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2015-03-04 10:47:53 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
using ReadBufferWithOwnMemory = BufferWithOwnMemory<ReadBuffer>;
|
|
|
|
|
2015-03-06 16:16:10 +00:00
|
|
|
class ReadBufferAIO : public IBufferAIO, public ReadBufferWithOwnMemory
|
2015-03-04 10:47:53 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ReadBufferAIO(const std::string & filename_, size_t buffer_size_ = DBMS_DEFAULT_BUFFER_SIZE, int flags_ = -1, mode_t mode_ = 0666,
|
|
|
|
char * existing_memory_ = nullptr);
|
|
|
|
~ReadBufferAIO() override;
|
|
|
|
|
|
|
|
ReadBufferAIO(const ReadBufferAIO &) = delete;
|
|
|
|
ReadBufferAIO & operator=(const ReadBufferAIO &) = delete;
|
|
|
|
|
2015-03-05 16:20:15 +00:00
|
|
|
void setMaxBytes(size_t max_bytes_read_);
|
2015-03-05 14:21:55 +00:00
|
|
|
off_t seek(off_t off, int whence = SEEK_SET);
|
|
|
|
size_t getPositionInFile() const noexcept { return pos_in_file - (working_buffer.end() - pos); }
|
2015-03-06 16:19:01 +00:00
|
|
|
std::string getFileName() const noexcept override { return filename; }
|
|
|
|
int getFD() const noexcept override { return fd; }
|
2015-03-04 10:47:53 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool nextImpl() override;
|
2015-03-06 16:19:01 +00:00
|
|
|
void waitForCompletion() override;
|
|
|
|
void swapBuffers() noexcept override;
|
2015-03-04 10:47:53 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ReadBufferWithOwnMemory fill_buffer; // buffer asynchronously read from disk
|
|
|
|
const std::string filename;
|
2015-03-10 11:43:30 +00:00
|
|
|
|
2015-03-04 10:47:53 +00:00
|
|
|
AIOContext aio_context;
|
|
|
|
iocb cb;
|
|
|
|
std::vector<iocb *> request_ptrs;
|
|
|
|
std::vector<io_event> events;
|
2015-03-10 11:43:30 +00:00
|
|
|
|
|
|
|
int fd = -1; // file descriptor
|
2015-03-05 16:20:15 +00:00
|
|
|
size_t max_bytes_read = std::numeric_limits<size_t>::max();
|
2015-03-06 11:08:25 +00:00
|
|
|
size_t total_bytes_read = 0;
|
2015-03-05 14:21:55 +00:00
|
|
|
off_t pos_in_file = 0;
|
2015-03-10 11:43:30 +00:00
|
|
|
|
2015-03-04 10:47:53 +00:00
|
|
|
bool is_pending_read = false;
|
2015-03-05 11:57:54 +00:00
|
|
|
bool got_exception = false;
|
2015-03-05 14:21:55 +00:00
|
|
|
bool is_eof = false;
|
2015-03-05 16:20:15 +00:00
|
|
|
bool is_started = false;
|
2015-03-04 10:47:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|