2011-10-24 12:10:59 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/IO/ReadBufferFromFileDescriptor.h>
|
2016-01-21 01:47:28 +00:00
|
|
|
#include <DB/Common/CurrentMetrics.h>
|
2011-10-24 12:10:59 +00:00
|
|
|
|
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
namespace CurrentMetrics
|
|
|
|
{
|
|
|
|
extern const Metric OpenFileForRead;
|
|
|
|
}
|
|
|
|
|
2011-10-24 12:10:59 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
/** Accepts path to file and opens it, or pre-opened file descriptor.
|
|
|
|
* Closes file by himself (thus "owns" a file descriptor).
|
2011-10-24 12:10:59 +00:00
|
|
|
*/
|
|
|
|
class ReadBufferFromFile : public ReadBufferFromFileDescriptor
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::string file_name;
|
2016-01-21 01:47:28 +00:00
|
|
|
CurrentMetrics::Increment metric_increment{CurrentMetrics::OpenFileForRead};
|
2015-12-13 08:51:28 +00:00
|
|
|
|
2011-10-24 12:10:59 +00:00
|
|
|
public:
|
2014-01-04 04:52:22 +00:00
|
|
|
ReadBufferFromFile(const std::string & file_name_, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE, int flags = -1,
|
2016-10-25 06:49:24 +00:00
|
|
|
char * existing_memory = nullptr, size_t alignment = 0);
|
2011-10-24 12:10:59 +00:00
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
/// Use pre-opened file descriptor.
|
2015-12-13 08:51:28 +00:00
|
|
|
ReadBufferFromFile(int fd, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE, int flags = -1,
|
2016-10-25 06:49:24 +00:00
|
|
|
char * existing_memory = nullptr, size_t alignment = 0);
|
2015-12-13 08:51:28 +00:00
|
|
|
|
2016-10-25 06:49:24 +00:00
|
|
|
~ReadBufferFromFile() override;
|
2015-12-13 08:51:28 +00:00
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
/// Close file before destruction of object.
|
2016-10-25 06:49:24 +00:00
|
|
|
void close();
|
2011-10-24 12:10:59 +00:00
|
|
|
|
2016-03-07 04:36:54 +00:00
|
|
|
std::string getFileName() const override
|
2011-10-24 12:10:59 +00:00
|
|
|
{
|
|
|
|
return file_name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|