2015-03-30 15:39:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2017-01-17 18:03:32 +00:00
|
|
|
#include <ctime>
|
2017-04-11 12:57:31 +00:00
|
|
|
#include <functional>
|
2015-03-30 15:39:55 +00:00
|
|
|
#include <fcntl.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBuffer.h>
|
|
|
|
#include <IO/BufferWithOwnMemory.h>
|
2018-06-19 18:09:09 +00:00
|
|
|
#include <port/clock.h>
|
2016-10-26 22:27:38 +00:00
|
|
|
|
2015-03-30 15:39:55 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class ReadBufferFromFileBase : public BufferWithOwnMemory<ReadBuffer>
|
|
|
|
{
|
|
|
|
public:
|
2020-01-04 05:46:50 +00:00
|
|
|
ReadBufferFromFileBase();
|
2017-04-01 07:20:54 +00:00
|
|
|
ReadBufferFromFileBase(size_t buf_size, char * existing_memory, size_t alignment);
|
2017-08-30 20:23:29 +00:00
|
|
|
ReadBufferFromFileBase(ReadBufferFromFileBase &&) = default;
|
2018-06-13 02:52:03 +00:00
|
|
|
~ReadBufferFromFileBase() override;
|
2017-04-01 07:20:54 +00:00
|
|
|
off_t seek(off_t off, int whence = SEEK_SET);
|
|
|
|
virtual off_t getPositionInFile() = 0;
|
|
|
|
virtual std::string getFileName() const = 0;
|
|
|
|
virtual int getFD() const = 0;
|
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/// It is possible to get information about the time of each reading.
|
2017-04-01 07:20:54 +00:00
|
|
|
struct ProfileInfo
|
|
|
|
{
|
|
|
|
size_t bytes_requested;
|
|
|
|
size_t bytes_read;
|
|
|
|
size_t nanoseconds;
|
|
|
|
};
|
|
|
|
|
|
|
|
using ProfileCallback = std::function<void(ProfileInfo)>;
|
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/// CLOCK_MONOTONIC_COARSE is more than enough to track long reads - for example, hanging for a second.
|
2017-04-01 07:20:54 +00:00
|
|
|
void setProfileCallback(const ProfileCallback & profile_callback_, clockid_t clock_type_ = CLOCK_MONOTONIC_COARSE)
|
|
|
|
{
|
|
|
|
profile_callback = profile_callback_;
|
|
|
|
clock_type = clock_type_;
|
|
|
|
}
|
2015-12-13 04:52:13 +00:00
|
|
|
|
2015-04-03 13:45:44 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
ProfileCallback profile_callback;
|
2019-06-16 18:12:14 +00:00
|
|
|
clockid_t clock_type{};
|
2015-12-13 04:52:13 +00:00
|
|
|
|
2019-04-03 14:28:39 +00:00
|
|
|
/// Children implementation should be able to seek backwards
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual off_t doSeek(off_t off, int whence) = 0;
|
2015-03-30 15:39:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|