ClickHouse/src/IO/MMappedFile.h

41 lines
768 B
C++
Raw Normal View History

2021-03-26 20:51:46 +00:00
#pragma once
2021-03-26 23:22:51 +00:00
#include <Common/CurrentMetrics.h>
2021-03-28 19:24:28 +00:00
#include <IO/MMappedFileDescriptor.h>
2021-03-26 20:51:46 +00:00
#include <cstddef>
2021-03-26 23:22:51 +00:00
namespace CurrentMetrics
{
extern const Metric OpenFileForRead;
}
2021-03-26 20:51:46 +00:00
namespace DB
{
2021-03-26 23:22:51 +00:00
/// Opens a file and mmaps a region in it (or a whole file) into memory. Unmaps and closes in destructor.
2021-03-28 19:24:28 +00:00
class MMappedFile : public MMappedFileDescriptor
2021-03-26 20:51:46 +00:00
{
public:
2021-03-28 19:24:28 +00:00
MMappedFile(const std::string & file_name_, size_t offset_, size_t length_);
2021-03-26 20:51:46 +00:00
2021-03-26 23:22:51 +00:00
/// Map till end of file.
2021-03-28 19:24:28 +00:00
MMappedFile(const std::string & file_name_, size_t offset_);
2021-03-26 20:51:46 +00:00
2021-03-28 19:24:28 +00:00
~MMappedFile() override;
2021-03-26 20:51:46 +00:00
2021-03-26 23:22:51 +00:00
void close();
2021-03-26 20:51:46 +00:00
2021-03-26 23:22:51 +00:00
std::string getFileName() const;
2021-03-26 20:51:46 +00:00
private:
2021-03-26 23:22:51 +00:00
std::string file_name;
2021-03-26 20:51:46 +00:00
2021-03-26 23:22:51 +00:00
CurrentMetrics::Increment metric_increment{CurrentMetrics::OpenFileForRead};
2021-03-26 20:51:46 +00:00
2021-03-26 23:22:51 +00:00
void open();
2021-03-26 20:51:46 +00:00
};
}