ClickHouse/dbms/src/Disks/DiskLocal.h

103 lines
2.8 KiB
C++
Raw Normal View History

2019-11-27 09:39:44 +00:00
#pragma once
#include <Disks/IDisk.h>
#include <IO/ReadBufferFromFile.h>
#include <IO/ReadBufferFromFileBase.h>
2019-11-27 09:39:44 +00:00
#include <IO/WriteBufferFromFile.h>
#include <Poco/DirectoryIterator.h>
#include <Poco/File.h>
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
class DiskLocalReservation;
class DiskLocal : public IDisk
{
public:
friend class DiskLocalReservation;
DiskLocal(const String & name_, const String & path_, UInt64 keep_free_space_bytes_)
2019-12-03 13:37:40 +00:00
: name(name_), disk_path(path_), keep_free_space_bytes(keep_free_space_bytes_)
2019-11-27 09:39:44 +00:00
{
2019-12-03 13:37:40 +00:00
if (disk_path.back() != '/')
2019-12-09 05:47:12 +00:00
throw Exception("Disk path must ends with '/', but '" + disk_path + "' doesn't.", ErrorCodes::LOGICAL_ERROR);
2019-11-27 09:39:44 +00:00
}
const String & getName() const override { return name; }
2019-12-03 13:37:40 +00:00
const String & getPath() const override { return disk_path; }
2019-11-27 09:39:44 +00:00
2019-12-03 13:37:40 +00:00
ReservationPtr reserve(UInt64 bytes) override;
2019-11-27 09:39:44 +00:00
UInt64 getTotalSpace() const override;
UInt64 getAvailableSpace() const override;
UInt64 getUnreservedSpace() const override;
UInt64 getKeepingFreeSpace() const override { return keep_free_space_bytes; }
2019-12-03 13:37:40 +00:00
bool exists(const String & path) const override;
2019-11-27 09:39:44 +00:00
2019-12-03 13:37:40 +00:00
bool isFile(const String & path) const override;
2019-11-27 09:39:44 +00:00
2019-12-03 13:37:40 +00:00
bool isDirectory(const String & path) const override;
2019-11-27 09:39:44 +00:00
size_t getFileSize(const String & path) const override;
2019-12-03 13:37:40 +00:00
void createDirectory(const String & path) override;
2019-11-27 09:39:44 +00:00
2019-12-03 13:37:40 +00:00
void createDirectories(const String & path) override;
2019-11-27 09:39:44 +00:00
void clearDirectory(const String & path) override;
void moveDirectory(const String & from_path, const String & to_path) override;
2019-12-03 13:37:40 +00:00
DiskDirectoryIteratorPtr iterateDirectory(const String & path) override;
2019-11-27 09:39:44 +00:00
2019-12-03 13:37:40 +00:00
void moveFile(const String & from_path, const String & to_path) override;
2019-11-27 09:39:44 +00:00
2020-01-02 14:37:31 +00:00
void replaceFile(const String & from_path, const String & to_path) override;
2019-12-03 13:37:40 +00:00
void copyFile(const String & from_path, const String & to_path) override;
2019-11-27 09:39:44 +00:00
std::unique_ptr<ReadBufferFromFileBase> readFile(
const String & path,
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
size_t estimated_size = 0,
size_t aio_threshold = 0,
size_t mmap_threshold = 0) const override;
std::unique_ptr<WriteBufferFromFileBase> writeFile(
const String & path,
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
WriteMode mode = WriteMode::Rewrite,
size_t estimated_size = 0,
size_t aio_threshold = 0) override;
2019-11-27 09:39:44 +00:00
2020-01-18 23:18:23 +00:00
void remove(const String & path) override;
void removeRecursive(const String & path) override;
2019-11-27 09:39:44 +00:00
private:
2019-12-03 13:37:40 +00:00
bool tryReserve(UInt64 bytes);
2019-11-27 09:39:44 +00:00
private:
2019-12-03 13:37:40 +00:00
const String name;
const String disk_path;
const UInt64 keep_free_space_bytes;
UInt64 reserved_bytes = 0;
UInt64 reservation_count = 0;
2019-11-27 09:39:44 +00:00
2020-01-18 23:42:46 +00:00
static std::mutex reservation_mutex;
2019-11-27 09:39:44 +00:00
};
}