ClickHouse/src/IO/WriteBufferFromFileDescriptor.h

63 lines
1.4 KiB
C++
Raw Normal View History

2011-10-24 12:10:59 +00:00
#pragma once
#include <IO/WriteBufferFromFileBase.h>
#include <Common/Throttler_fwd.h>
2011-10-24 12:10:59 +00:00
namespace DB
{
/** Use ready file descriptor. Does not open or close a file.
2011-10-24 12:10:59 +00:00
*/
class WriteBufferFromFileDescriptor : public WriteBufferFromFileBase
2011-10-24 12:10:59 +00:00
{
public:
explicit WriteBufferFromFileDescriptor(
int fd_ = -1,
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
char * existing_memory = nullptr,
ThrottlerPtr throttler_ = {},
size_t alignment = 0,
2021-09-06 10:35:37 +00:00
std::string file_name_ = "");
2011-10-24 12:10:59 +00:00
/** Could be used before initialization if needed 'fd' was not passed to constructor.
* It's not possible to change 'fd' during work.
*/
void setFD(int fd_)
{
fd = fd_;
}
~WriteBufferFromFileDescriptor() override;
int getFD() const
{
return fd;
}
void sync() override;
/// clang-tidy wants these methods to be const, but
/// they are not const semantically
off_t seek(off_t offset, int whence); // NOLINT
void truncate(off_t length); // NOLINT
/// Name or some description of file.
2021-09-06 10:35:37 +00:00
std::string getFileName() const override;
2020-07-07 11:45:20 +00:00
off_t size() const;
2021-11-10 22:58:56 +00:00
protected:
void nextImpl() override;
int fd;
ThrottlerPtr throttler;
2021-11-10 22:58:56 +00:00
/// If file has name contains filename, otherwise contains string "(fd=...)"
std::string file_name;
2021-11-11 17:27:23 +00:00
2021-11-10 22:58:56 +00:00
void finalizeImpl() override;
2011-10-24 12:10:59 +00:00
};
}