diff options
author | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-14 09:58:56 +0300 |
---|---|---|
committer | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-14 10:20:20 +0300 |
commit | c2b2dfd9827a400a8495e172a56343462e3ceb82 (patch) | |
tree | cd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/IO/MMappedFileDescriptor.h | |
parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
download | ydb-c2b2dfd9827a400a8495e172a56343462e3ceb82.tar.gz |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/IO/MMappedFileDescriptor.h')
-rw-r--r-- | contrib/clickhouse/src/IO/MMappedFileDescriptor.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/IO/MMappedFileDescriptor.h b/contrib/clickhouse/src/IO/MMappedFileDescriptor.h new file mode 100644 index 0000000000..2611093643 --- /dev/null +++ b/contrib/clickhouse/src/IO/MMappedFileDescriptor.h @@ -0,0 +1,60 @@ +#pragma once + +#include <cstddef> +#include <Common/CurrentMetrics.h> + +namespace CurrentMetrics +{ + extern const Metric MMappedFiles; + extern const Metric MMappedFileBytes; +} + + +namespace DB +{ + +/// MMaps a region in file (or a whole file) into memory. Unmaps in destructor. +/// Does not open or close file. +class MMappedFileDescriptor +{ +public: + MMappedFileDescriptor(int fd_, size_t offset_, size_t length_); + MMappedFileDescriptor(int fd_, size_t offset_); + + /// Makes empty object that can be initialized with `set`. + MMappedFileDescriptor() = default; + + virtual ~MMappedFileDescriptor(); + + char * getData() { return data; } + const char * getData() const { return data; } + + int getFD() const { return fd; } + size_t getOffset() const { return offset; } + size_t getLength() const { return length; } + + /// Unmap memory before call to destructor + void finish(); + + /// Initialize or reset to another fd. + void set(int fd_, size_t offset_, size_t length_); + void set(int fd_, size_t offset_); + + MMappedFileDescriptor(const MMappedFileDescriptor &) = delete; + MMappedFileDescriptor(MMappedFileDescriptor &&) = delete; + +protected: + + void init(); + + int fd = -1; + size_t offset = 0; + size_t length = 0; + char * data = nullptr; + + CurrentMetrics::Increment files_metric_increment{CurrentMetrics::MMappedFiles, 0}; + CurrentMetrics::Increment bytes_metric_increment{CurrentMetrics::MMappedFileBytes, 0}; +}; + +} + |