ClickHouse/dbms/IO/WriteBufferFromFile.h

65 lines
1.3 KiB
C++
Raw Normal View History

2011-10-24 12:10:59 +00:00
#pragma once
#include <sys/types.h>
#include <Common/CurrentMetrics.h>
#include <IO/WriteBufferFromFileDescriptor.h>
2011-10-24 12:10:59 +00:00
namespace CurrentMetrics
{
extern const Metric OpenFileForWrite;
}
2011-10-24 12:10:59 +00:00
#ifndef O_DIRECT
#define O_DIRECT 00040000
#endif
2016-10-25 06:49:24 +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 WriteBufferFromFile : public WriteBufferFromFileDescriptor
{
protected:
std::string file_name;
CurrentMetrics::Increment metric_increment{CurrentMetrics::OpenFileForWrite};
2015-12-13 08:51:28 +00:00
2011-10-24 12:10:59 +00:00
public:
WriteBufferFromFile(
const std::string & file_name_,
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
int flags = -1,
mode_t mode = 0666,
char * existing_memory = nullptr,
size_t alignment = 0);
/// Use pre-opened file descriptor.
WriteBufferFromFile(
int fd,
const std::string & original_file_name = {},
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
char * existing_memory = nullptr,
size_t alignment = 0);
~WriteBufferFromFile() override;
/// Close file before destruction of object.
void close();
2020-01-10 21:42:26 +00:00
void finalize() override
{
close();
}
std::string getFileName() const override
{
return file_name;
}
2011-10-24 12:10:59 +00:00
};
}