ClickHouse/src/Storages/MergeTree/DataPartStorageOnDisk.h

175 lines
6.1 KiB
C++
Raw Normal View History

2022-04-05 19:12:48 +00:00
#pragma once
#include <Storages/MergeTree/IDataPartStorage.h>
#include <memory>
#include <string>
namespace DB
{
class IVolume;
using VolumePtr = std::shared_ptr<IVolume>;
class DataPartStorageOnDisk final : public IDataPartStorage
{
public:
2022-04-12 18:59:49 +00:00
DataPartStorageOnDisk(VolumePtr volume_, std::string root_path_, std::string part_dir_);
2022-04-05 19:12:48 +00:00
std::unique_ptr<ReadBufferFromFileBase> readFile(
const std::string & path,
const ReadSettings & settings,
std::optional<size_t> read_hint,
std::optional<size_t> file_size) const override;
bool exists() const override;
2022-04-19 19:34:41 +00:00
bool exists(const std::string & path) const override;
2022-04-22 16:58:09 +00:00
bool isDirectory(const std::string & path) const override;
2022-04-05 19:12:48 +00:00
2022-04-08 18:56:08 +00:00
Poco::Timestamp getLastModified() const override;
2022-04-05 19:12:48 +00:00
size_t getFileSize(const std::string & path) const override;
2022-04-21 19:19:13 +00:00
UInt32 getRefCount(const String & path) const override;
2022-04-05 19:12:48 +00:00
2022-04-21 19:19:13 +00:00
DataPartStorageIteratorPtr iterate() const override;
DataPartStorageIteratorPtr iterateDirectory(const std::string & path) const override;
2022-04-05 19:12:48 +00:00
2022-04-19 19:34:41 +00:00
void remove(
2022-05-03 15:48:05 +00:00
bool can_remove_shared_data,
const NameSet & names_not_to_remove,
2022-04-19 19:34:41 +00:00
const MergeTreeDataPartChecksums & checksums,
std::list<ProjectionChecksums> projections,
Poco::Logger * log) const override;
void setRelativePath(const std::string & path) override;
std::string getRelativePathForPrefix(Poco::Logger * log, const String & prefix, bool detached) const override;
2022-05-03 19:32:24 +00:00
std::string getPartDirectory() const override { return part_dir; }
2022-04-07 11:58:38 +00:00
std::string getFullPath() const override;
2022-04-19 19:34:41 +00:00
std::string getFullRootPath() const override;
2022-04-12 18:59:49 +00:00
std::string getFullRelativePath() const override;
2022-04-05 19:12:48 +00:00
UInt64 calculateTotalSizeOnDisk() const override;
2022-04-07 17:44:49 +00:00
bool isStoredOnRemoteDisk() const override;
2022-04-08 18:56:08 +00:00
bool supportZeroCopyReplication() const override;
2022-04-22 16:58:09 +00:00
bool supportParallelWrite() const override;
2022-04-19 19:34:41 +00:00
bool isBroken() const override;
std::string getDiskPathForLogs() const override;
2022-04-07 17:44:49 +00:00
2022-05-03 15:48:05 +00:00
void writeChecksums(const MergeTreeDataPartChecksums & checksums, const WriteSettings & settings) const override;
void writeColumns(const NamesAndTypesList & columns, const WriteSettings & settings) const override;
void writeVersionMetadata(const VersionMetadata & version, bool fsync_part_dir) const override;
void appendCSNToVersionMetadata(const VersionMetadata & version, VersionMetadata::WhichCSN which_csn) const override;
void appendRemovalTIDToVersionMetadata(const VersionMetadata & version, bool clear) const override;
2022-04-08 18:56:08 +00:00
void writeDeleteOnDestroyMarker(Poco::Logger * log) const override;
2022-04-05 19:12:48 +00:00
2022-05-03 15:48:05 +00:00
void removeDeleteOnDestroyMarker() const override;
void removeVersionMetadata() const override;
void loadVersionMetadata(VersionMetadata & version, Poco::Logger * log) const override;
2022-04-19 19:34:41 +00:00
void checkConsistency(const MergeTreeDataPartChecksums & checksums) const override;
2022-04-22 16:58:09 +00:00
ReservationPtr reserve(UInt64 bytes) const override;
ReservationPtr tryReserve(UInt64 bytes) const override;
2022-04-19 19:34:41 +00:00
String getUniqueId() const override;
2022-04-07 17:44:49 +00:00
bool shallParticipateInMerges(const IStoragePolicy &) const override;
2022-04-22 16:58:09 +00:00
size_t getVolumeIndex(const IStoragePolicy &) const override;
2022-04-07 11:58:38 +00:00
2022-04-19 19:34:41 +00:00
void backup(
TemporaryFilesOnDisks & temp_dirs,
const MergeTreeDataPartChecksums & checksums,
const NameSet & files_without_checksums,
BackupEntries & backup_entries) const override;
DataPartStoragePtr freeze(
const std::string & to,
const std::string & dir_path,
2022-05-03 15:48:05 +00:00
bool make_source_readonly,
std::function<void(const DiskPtr &)> save_metadata_callback,
bool copy_instead_of_hardlink) const override;
2022-04-19 19:34:41 +00:00
DataPartStoragePtr clone(
const std::string & to,
const std::string & dir_path,
Poco::Logger * log) const override;
2022-05-03 15:48:05 +00:00
void rename(const String & new_relative_path, Poco::Logger * log, bool remove_new_dir_if_exists, bool fsync_part_dir) override;
2022-04-07 11:58:38 +00:00
2022-04-05 19:12:48 +00:00
std::string getName() const override;
2022-04-21 19:19:13 +00:00
std::string getDiskType() const override;
2022-04-05 19:12:48 +00:00
2022-04-22 16:58:09 +00:00
DisksSet::const_iterator isStoredOnDisk(const DisksSet & disks) const override;
2022-04-05 19:12:48 +00:00
DataPartStoragePtr getProjection(const std::string & name) const override;
2022-04-21 19:19:13 +00:00
DiskPtr getDisk() const;
2022-04-05 19:12:48 +00:00
private:
VolumePtr volume;
std::string root_path;
2022-04-12 18:59:49 +00:00
std::string part_dir;
2022-04-19 19:34:41 +00:00
void clearDirectory(
const std::string & dir,
2022-05-03 15:48:05 +00:00
bool can_remove_shared_data,
const NameSet & names_not_to_remove,
2022-04-19 19:34:41 +00:00
const MergeTreeDataPartChecksums & checksums,
const std::unordered_set<String> & skip_directories,
Poco::Logger * log,
bool is_projection) const;
2022-04-12 18:59:49 +00:00
};
class DataPartStorageBuilderOnDisk final : public IDataPartStorageBuilder
{
2022-04-21 19:19:13 +00:00
public:
2022-04-12 18:59:49 +00:00
DataPartStorageBuilderOnDisk(VolumePtr volume_, std::string root_path_, std::string part_dir_);
2022-04-19 19:34:41 +00:00
void setRelativePath(const std::string & path) override;
2022-04-12 18:59:49 +00:00
bool exists() const override;
bool exists(const std::string & path) const override;
void createDirectories() override;
2022-04-21 19:19:13 +00:00
void createProjection(const std::string & name) override;
2022-04-12 18:59:49 +00:00
2022-05-03 19:32:24 +00:00
std::string getPartDirectory() const override { return part_dir; }
2022-04-12 18:59:49 +00:00
std::string getFullPath() const override;
2022-04-21 19:19:13 +00:00
std::string getFullRelativePath() const override;
2022-04-12 18:59:49 +00:00
std::unique_ptr<ReadBufferFromFileBase> readFile(
const std::string & path,
const ReadSettings & settings,
std::optional<size_t> read_hint,
std::optional<size_t> file_size) const override;
std::unique_ptr<WriteBufferFromFileBase> writeFile(
const String & path,
2022-05-03 15:48:05 +00:00
size_t buf_size,
const WriteSettings & settings) override;
2022-04-12 18:59:49 +00:00
void removeFile(const String & path) override;
void removeRecursive() override;
2022-04-21 19:19:13 +00:00
void removeSharedRecursive(bool keep_in_remote_fs) override;
SyncGuardPtr getDirectorySyncGuard() const override;
void createHardLinkFrom(const IDataPartStorage & source, const std::string & from, const std::string & to) const override;
2022-04-12 18:59:49 +00:00
ReservationPtr reserve(UInt64 bytes) override;
DataPartStorageBuilderPtr getProjection(const std::string & name) const override;
2022-04-19 19:34:41 +00:00
DataPartStoragePtr getStorage() const override;
2022-04-12 18:59:49 +00:00
private:
VolumePtr volume;
std::string root_path;
std::string part_dir;
2022-04-05 19:12:48 +00:00
};
}