2021-07-26 00:34:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <IO/AsynchronousReadBufferFromFileDescriptor.h>
|
|
|
|
#include <IO/OpenedFileCache.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class AsynchronousReadBufferFromFile : public AsynchronousReadBufferFromFileDescriptor
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
std::string file_name;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AsynchronousReadBufferFromFile(
|
2021-08-16 00:00:32 +00:00
|
|
|
AsynchronousReaderPtr reader_, Int32 priority_,
|
2021-07-26 00:34:36 +00:00
|
|
|
const std::string & file_name_, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE, int flags = -1,
|
|
|
|
char * existing_memory = nullptr, size_t alignment = 0);
|
|
|
|
|
|
|
|
/// Use pre-opened file descriptor.
|
|
|
|
explicit AsynchronousReadBufferFromFile(
|
2021-08-16 00:00:32 +00:00
|
|
|
AsynchronousReaderPtr reader_, Int32 priority_,
|
2021-07-26 00:34:36 +00:00
|
|
|
int & fd, /// Will be set to -1 if constructor didn't throw and ownership of file descriptor is passed to the object.
|
|
|
|
const std::string & original_file_name = {},
|
|
|
|
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
|
|
|
|
char * existing_memory = nullptr, size_t alignment = 0);
|
|
|
|
|
|
|
|
~AsynchronousReadBufferFromFile() override;
|
|
|
|
|
|
|
|
/// Close file before destruction of object.
|
|
|
|
void close();
|
|
|
|
|
|
|
|
std::string getFileName() const override
|
|
|
|
{
|
|
|
|
return file_name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** Similar to AsynchronousReadBufferFromFile but also transparently shares open file descriptors.
|
|
|
|
*/
|
|
|
|
class AsynchronousReadBufferFromFileWithCache : public AsynchronousReadBufferFromFileDescriptor
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::string file_name;
|
|
|
|
OpenedFileCache::OpenedFilePtr file;
|
|
|
|
|
|
|
|
public:
|
|
|
|
AsynchronousReadBufferFromFileWithCache(
|
2021-08-16 00:00:32 +00:00
|
|
|
AsynchronousReaderPtr reader_, Int32 priority_,
|
2021-07-26 00:34:36 +00:00
|
|
|
const std::string & file_name_, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE, int flags = -1,
|
|
|
|
char * existing_memory = nullptr, size_t alignment = 0)
|
2021-08-16 00:00:32 +00:00
|
|
|
: AsynchronousReadBufferFromFileDescriptor(std::move(reader_), priority_, -1, buf_size, existing_memory, alignment),
|
2021-07-26 00:34:36 +00:00
|
|
|
file_name(file_name_)
|
|
|
|
{
|
|
|
|
file = OpenedFileCache::instance().get(file_name, flags);
|
|
|
|
fd = file->getFD();
|
|
|
|
}
|
|
|
|
|
2021-07-27 23:47:28 +00:00
|
|
|
~AsynchronousReadBufferFromFileWithCache() override;
|
|
|
|
|
2021-07-26 00:34:36 +00:00
|
|
|
std::string getFileName() const override
|
|
|
|
{
|
|
|
|
return file_name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|