ClickHouse/dbms/IO/ReadBufferFromFile.h

49 lines
1.2 KiB
C++
Raw Normal View History

2011-10-24 12:10:59 +00:00
#pragma once
#include <IO/ReadBufferFromFileDescriptor.h>
#include <Common/CurrentMetrics.h>
2011-10-24 12:10:59 +00:00
#ifndef O_DIRECT
#define O_DIRECT 00040000
#endif
2011-10-24 12:10:59 +00:00
namespace CurrentMetrics
{
extern const Metric OpenFileForRead;
}
2011-10-24 12:10:59 +00:00
namespace DB
{
/** 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
{
protected:
std::string file_name;
CurrentMetrics::Increment metric_increment{CurrentMetrics::OpenFileForRead};
2015-12-13 08:51:28 +00:00
2011-10-24 12:10:59 +00:00
public:
ReadBufferFromFile(const std::string & file_name_, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE, int flags = -1,
char * existing_memory = nullptr, size_t alignment = 0);
2011-10-24 12:10:59 +00:00
/// Use pre-opened file descriptor.
2017-12-01 17:49:12 +00:00
ReadBufferFromFile(int fd, const std::string & original_file_name = {}, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
char * existing_memory = nullptr, size_t alignment = 0);
2015-12-13 08:51:28 +00:00
ReadBufferFromFile(ReadBufferFromFile &&) = default;
~ReadBufferFromFile() override;
2015-12-13 08:51:28 +00:00
/// Close file before destruction of object.
void close();
2011-10-24 12:10:59 +00:00
std::string getFileName() const override
{
return file_name;
}
2011-10-24 12:10:59 +00:00
};
}