2011-10-24 12:10:59 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteBufferFromFileBase.h>
|
2023-03-30 17:02:28 +00:00
|
|
|
#include <Common/Throttler_fwd.h>
|
2016-10-24 02:02:37 +00:00
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
|
2011-10-24 12:10:59 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
/** Use ready file descriptor. Does not open or close a file.
|
2011-10-24 12:10:59 +00:00
|
|
|
*/
|
2015-03-30 15:39:55 +00:00
|
|
|
class WriteBufferFromFileDescriptor : public WriteBufferFromFileBase
|
2011-10-24 12:10:59 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-03-13 11:59:20 +00:00
|
|
|
explicit WriteBufferFromFileDescriptor(
|
2016-10-25 06:49:24 +00:00
|
|
|
int fd_ = -1,
|
|
|
|
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
|
|
|
|
char * existing_memory = nullptr,
|
2023-03-30 17:02:28 +00:00
|
|
|
ThrottlerPtr throttler_ = {},
|
2021-09-06 09:16:52 +00:00
|
|
|
size_t alignment = 0,
|
2021-09-06 10:35:37 +00:00
|
|
|
std::string file_name_ = "");
|
2011-10-24 12:10:59 +00:00
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
/** Could be used before initialization if needed 'fd' was not passed to constructor.
|
|
|
|
* It's not possible to change 'fd' during work.
|
2012-02-24 19:21:38 +00:00
|
|
|
*/
|
|
|
|
void setFD(int fd_)
|
|
|
|
{
|
|
|
|
fd = fd_;
|
|
|
|
}
|
|
|
|
|
2017-03-09 04:26:17 +00:00
|
|
|
~WriteBufferFromFileDescriptor() override;
|
2011-12-28 20:01:41 +00:00
|
|
|
|
2020-02-20 16:39:32 +00:00
|
|
|
int getFD() const
|
2011-12-28 20:01:41 +00:00
|
|
|
{
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2016-10-25 06:49:24 +00:00
|
|
|
void sync() override;
|
2015-04-03 13:45:44 +00:00
|
|
|
|
2021-09-06 09:16:52 +00:00
|
|
|
/// 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
|
|
|
|
2021-09-06 09:16:52 +00:00
|
|
|
off_t size() const;
|
2021-11-10 22:58:56 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void nextImpl() override;
|
|
|
|
|
|
|
|
int fd;
|
2023-03-30 17:02:28 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|