2021-07-26 00:34:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-03-30 17:02:28 +00:00
|
|
|
#include <Common/Throttler_fwd.h>
|
2021-07-26 00:34:36 +00:00
|
|
|
#include <IO/AsynchronousReadBufferFromFileDescriptor.h>
|
|
|
|
#include <IO/OpenedFileCache.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2023-03-30 17:02:28 +00:00
|
|
|
/* NOTE: Unused */
|
2021-07-26 00:34:36 +00:00
|
|
|
class AsynchronousReadBufferFromFile : public AsynchronousReadBufferFromFileDescriptor
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
std::string file_name;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AsynchronousReadBufferFromFile(
|
2022-09-23 17:35:16 +00:00
|
|
|
IAsynchronousReader & reader_,
|
2023-05-26 13:55:30 +00:00
|
|
|
Priority priority_,
|
2022-01-03 16:05:46 +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,
|
|
|
|
std::optional<size_t> file_size_ = std::nullopt);
|
2021-07-26 00:34:36 +00:00
|
|
|
|
|
|
|
/// Use pre-opened file descriptor.
|
|
|
|
explicit AsynchronousReadBufferFromFile(
|
2022-09-23 17:35:16 +00:00
|
|
|
IAsynchronousReader & reader_,
|
2023-05-26 13:55:30 +00:00
|
|
|
Priority 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,
|
2022-01-03 16:05:46 +00:00
|
|
|
char * existing_memory = nullptr,
|
|
|
|
size_t alignment = 0,
|
|
|
|
std::optional<size_t> file_size_ = std::nullopt);
|
2021-07-26 00:34:36 +00:00
|
|
|
|
|
|
|
~AsynchronousReadBufferFromFile() override;
|
|
|
|
|
|
|
|
/// Close file before destruction of object.
|
|
|
|
void close();
|
|
|
|
|
|
|
|
std::string getFileName() const override
|
|
|
|
{
|
|
|
|
return file_name;
|
|
|
|
}
|
2023-10-17 00:00:07 +00:00
|
|
|
|
|
|
|
bool isRegularLocalFile(size_t * /* out_view_offset */) override { return true; }
|
2021-07-26 00:34:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Similar to AsynchronousReadBufferFromFile but also transparently shares open file descriptors.
|
|
|
|
*/
|
2021-08-27 22:32:35 +00:00
|
|
|
class AsynchronousReadBufferFromFileWithDescriptorsCache : public AsynchronousReadBufferFromFileDescriptor
|
2021-07-26 00:34:36 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::string file_name;
|
|
|
|
OpenedFileCache::OpenedFilePtr file;
|
|
|
|
|
|
|
|
public:
|
2021-08-27 22:32:35 +00:00
|
|
|
AsynchronousReadBufferFromFileWithDescriptorsCache(
|
2022-09-23 17:35:16 +00:00
|
|
|
IAsynchronousReader & reader_,
|
2023-05-26 13:55:30 +00:00
|
|
|
Priority priority_,
|
2022-01-03 16:05:46 +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,
|
2023-03-30 17:02:28 +00:00
|
|
|
std::optional<size_t> file_size_ = std::nullopt,
|
2023-12-20 14:57:52 +00:00
|
|
|
ThrottlerPtr throttler_ = {})
|
|
|
|
: AsynchronousReadBufferFromFileDescriptor(reader_, priority_, -1, buf_size, existing_memory, alignment, file_size_, throttler_)
|
2022-01-03 16:05:46 +00:00
|
|
|
, file_name(file_name_)
|
2021-07-26 00:34:36 +00:00
|
|
|
{
|
|
|
|
file = OpenedFileCache::instance().get(file_name, flags);
|
|
|
|
fd = file->getFD();
|
|
|
|
}
|
|
|
|
|
2021-08-27 22:32:35 +00:00
|
|
|
~AsynchronousReadBufferFromFileWithDescriptorsCache() override;
|
2021-07-27 23:47:28 +00:00
|
|
|
|
2021-07-26 00:34:36 +00:00
|
|
|
std::string getFileName() const override
|
|
|
|
{
|
|
|
|
return file_name;
|
|
|
|
}
|
2023-10-17 00:00:07 +00:00
|
|
|
|
|
|
|
bool isRegularLocalFile(size_t * /* out_view_offset */) override { return true; }
|
2021-07-26 00:34:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|