2020-07-29 15:05:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Disks/IDisk.h"
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-10-20 01:29:13 +00:00
|
|
|
|
|
|
|
/** Forwards all methods to another disk.
|
|
|
|
* Methods can be overridden by descendants.
|
|
|
|
*/
|
2020-07-29 15:05:02 +00:00
|
|
|
class DiskDecorator : public IDisk
|
|
|
|
{
|
|
|
|
public:
|
2020-07-29 18:15:20 +00:00
|
|
|
explicit DiskDecorator(const DiskPtr & delegate_);
|
2020-07-29 15:05:02 +00:00
|
|
|
const String & getName() const override;
|
|
|
|
ReservationPtr reserve(UInt64 bytes) override;
|
|
|
|
~DiskDecorator() override = default;
|
|
|
|
const String & getPath() const override;
|
|
|
|
UInt64 getTotalSpace() const override;
|
|
|
|
UInt64 getAvailableSpace() const override;
|
|
|
|
UInt64 getUnreservedSpace() const override;
|
|
|
|
UInt64 getKeepingFreeSpace() const override;
|
|
|
|
bool exists(const String & path) const override;
|
|
|
|
bool isFile(const String & path) const override;
|
|
|
|
bool isDirectory(const String & path) const override;
|
|
|
|
size_t getFileSize(const String & path) const override;
|
|
|
|
void createDirectory(const String & path) override;
|
|
|
|
void createDirectories(const String & path) override;
|
2020-10-23 12:01:50 +00:00
|
|
|
void clearDirectory(const String & path) override;
|
2020-07-29 15:05:02 +00:00
|
|
|
void moveDirectory(const String & from_path, const String & to_path) override;
|
|
|
|
DiskDirectoryIteratorPtr iterateDirectory(const String & path) override;
|
|
|
|
void createFile(const String & path) override;
|
|
|
|
void moveFile(const String & from_path, const String & to_path) override;
|
|
|
|
void replaceFile(const String & from_path, const String & to_path) override;
|
|
|
|
void copy(const String & from_path, const std::shared_ptr<IDisk> & to_disk, const String & to_path) override;
|
|
|
|
void listFiles(const String & path, std::vector<String> & file_names) override;
|
2021-03-28 01:10:30 +00:00
|
|
|
|
|
|
|
std::unique_ptr<ReadBufferFromFileBase> readFile(
|
|
|
|
const String & path,
|
2021-08-16 00:00:32 +00:00
|
|
|
const ReadSettings & settings,
|
2022-01-03 18:36:34 +00:00
|
|
|
std::optional<size_t> read_hint,
|
|
|
|
std::optional<size_t> file_size) const override;
|
2021-03-28 01:10:30 +00:00
|
|
|
|
|
|
|
std::unique_ptr<WriteBufferFromFileBase> writeFile(
|
|
|
|
const String & path,
|
|
|
|
size_t buf_size,
|
|
|
|
WriteMode mode) override;
|
|
|
|
|
2021-01-14 16:24:13 +00:00
|
|
|
void removeFile(const String & path) override;
|
|
|
|
void removeFileIfExists(const String & path) override;
|
|
|
|
void removeDirectory(const String & path) override;
|
2020-10-23 12:01:50 +00:00
|
|
|
void removeRecursive(const String & path) override;
|
2021-01-20 09:48:22 +00:00
|
|
|
void removeSharedFile(const String & path, bool keep_s3) override;
|
2020-10-23 12:01:50 +00:00
|
|
|
void removeSharedRecursive(const String & path, bool keep_s3) override;
|
2020-07-29 15:05:02 +00:00
|
|
|
void setLastModified(const String & path, const Poco::Timestamp & timestamp) override;
|
|
|
|
Poco::Timestamp getLastModified(const String & path) override;
|
|
|
|
void setReadOnly(const String & path) override;
|
|
|
|
void createHardLink(const String & src_path, const String & dst_path) override;
|
|
|
|
void truncateFile(const String & path, size_t size) override;
|
2021-02-05 17:13:44 +00:00
|
|
|
int open(const String & path, mode_t mode) const;
|
|
|
|
void close(int fd) const;
|
|
|
|
void sync(int fd) const;
|
2020-10-22 09:32:05 +00:00
|
|
|
String getUniqueId(const String & path) const override { return delegate->getUniqueId(path); }
|
2020-11-03 08:58:26 +00:00
|
|
|
bool checkUniqueId(const String & id) const override { return delegate->checkUniqueId(id); }
|
2021-08-24 22:24:47 +00:00
|
|
|
DiskType getType() const override { return delegate->getType(); }
|
2021-08-24 23:27:20 +00:00
|
|
|
bool isRemote() const override { return delegate->isRemote(); }
|
2021-07-05 03:32:56 +00:00
|
|
|
bool supportZeroCopyReplication() const override { return delegate->supportZeroCopyReplication(); }
|
2021-01-12 17:18:40 +00:00
|
|
|
void onFreeze(const String & path) override;
|
2021-01-26 13:29:45 +00:00
|
|
|
SyncGuardPtr getDirectorySyncGuard(const String & path) const override;
|
2021-04-20 18:29:03 +00:00
|
|
|
void shutdown() override;
|
|
|
|
void startup() override;
|
2021-06-18 05:28:08 +00:00
|
|
|
void applyNewSettings(const Poco::Util::AbstractConfiguration & config, ContextPtr context, const String & config_prefix, const DisksMap & map) override;
|
2020-07-29 15:05:02 +00:00
|
|
|
|
2021-11-23 13:57:24 +00:00
|
|
|
std::unique_ptr<ReadBufferFromFileBase> readMetaFile(
|
|
|
|
const String & path,
|
|
|
|
const ReadSettings & settings,
|
|
|
|
std::optional<size_t> size) const override { return delegate->readMetaFile(path, settings, size); }
|
|
|
|
|
|
|
|
std::unique_ptr<WriteBufferFromFileBase> writeMetaFile(
|
|
|
|
const String & path,
|
|
|
|
size_t buf_size,
|
|
|
|
WriteMode mode) override { return delegate->writeMetaFile(path, buf_size, mode); }
|
|
|
|
|
2021-12-17 11:03:20 +00:00
|
|
|
void removeMetaFileIfExists(const String & path) override { delegate->removeMetaFileIfExists(path); }
|
|
|
|
|
2021-11-23 13:57:24 +00:00
|
|
|
UInt32 getRefCount(const String & path) const override { return delegate->getRefCount(path); }
|
|
|
|
|
2020-07-29 15:05:02 +00:00
|
|
|
protected:
|
2021-04-20 18:29:03 +00:00
|
|
|
Executor & getExecutor() override;
|
|
|
|
|
2020-07-29 15:05:02 +00:00
|
|
|
DiskPtr delegate;
|
|
|
|
};
|
|
|
|
|
2021-04-20 18:29:03 +00:00
|
|
|
/// TODO: Current reservation mechanism leaks IDisk abstraction details.
|
|
|
|
/// This hack is needed to return proper disk pointer (wrapper instead of implementation) from reservation object.
|
|
|
|
class ReservationDelegate : public IReservation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ReservationDelegate(ReservationPtr delegate_, DiskPtr wrapper_) : delegate(std::move(delegate_)), wrapper(wrapper_) { }
|
|
|
|
UInt64 getSize() const override { return delegate->getSize(); }
|
|
|
|
DiskPtr getDisk(size_t) const override { return wrapper; }
|
|
|
|
Disks getDisks() const override { return {wrapper}; }
|
|
|
|
void update(UInt64 new_size) override { delegate->update(new_size); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ReservationPtr delegate;
|
|
|
|
DiskPtr wrapper;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-07-29 15:05:02 +00:00
|
|
|
}
|