ClickHouse/src/IO/MappedFile.h

41 lines
762 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>
#include <IO/MappedFileDescriptor.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.
class MappedFile : public MappedFileDescriptor
2021-03-26 20:51:46 +00:00
{
public:
2021-03-26 23:22:51 +00:00
MappedFile(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.
MappedFile(const std::string & file_name_, size_t offset_);
2021-03-26 20:51:46 +00:00
2021-03-27 22:57:59 +00:00
~MappedFile() 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
};
}