ClickHouse/src/Storages/MergeTree/DataPartStorageOnDisk.h

185 lines
6.6 KiB
C++
Raw Normal View History

2022-04-05 19:12:48 +00:00
#pragma once
#include <Storages/MergeTree/IDataPartStorage.h>
2022-06-23 16:21:46 +00:00
#include <Disks/IDisk.h>
2022-04-05 19:12:48 +00:00
#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
2022-06-20 18:18:17 +00:00
std::string getFullPath() const override;
std::string getRelativePath() const override;
std::string getPartDirectory() const override { return part_dir; }
std::string getFullRootPath() const override;
DataPartStoragePtr getProjection(const std::string & name) const override;
2022-04-05 19:12:48 +00:00
bool exists() const override;
2022-06-20 18:18:17 +00:00
bool exists(const std::string & name) const override;
bool isDirectory(const std::string & name) const override;
2022-04-05 19:12:48 +00:00
2022-04-08 18:56:08 +00:00
Poco::Timestamp getLastModified() const override;
2022-06-20 18:18:17 +00:00
DataPartStorageIteratorPtr iterate() const override;
2022-04-08 18:56:08 +00:00
2022-06-20 18:18:17 +00:00
size_t getFileSize(const std::string & file_name) const override;
UInt32 getRefCount(const std::string & file_name) const override;
2022-04-05 19:12:48 +00:00
2022-06-20 18:18:17 +00:00
UInt64 calculateTotalSizeOnDisk() const override;
std::unique_ptr<ReadBufferFromFileBase> readFile(
const std::string & name,
const ReadSettings & settings,
std::optional<size_t> read_hint,
std::optional<size_t> file_size) const override;
void loadVersionMetadata(VersionMetadata & version, Poco::Logger * log) const override;
void checkConsistency(const MergeTreeDataPartChecksums & checksums) const override;
2022-04-05 19:12:48 +00:00
2022-04-19 19:34:41 +00:00
void remove(
2022-09-15 12:49:31 +00:00
CanRemoveCallback && can_remove_callback,
2022-05-05 09:23:23 +00:00
const MergeTreeDataPartChecksums & checksums,
2022-04-19 19:34:41 +00:00
std::list<ProjectionChecksums> projections,
2022-08-12 10:47:25 +00:00
bool is_temp,
MergeTreeDataPartState state,
2022-09-16 11:49:39 +00:00
Poco::Logger * log) override;
2022-04-19 19:34:41 +00:00
std::string getRelativePathForPrefix(Poco::Logger * log, const String & prefix, bool detached) const override;
2022-06-20 18:18:17 +00:00
void setRelativePath(const std::string & path) override;
2022-06-27 19:41:29 +00:00
void onRename(const std::string & new_root_path, const std::string & new_part_dir) override;
2022-04-05 19:12:48 +00:00
2022-06-20 18:18:17 +00:00
std::string getDiskName() const override;
std::string getDiskType() 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;
2022-06-20 18:18:17 +00:00
void syncRevision(UInt64 revision) override;
UInt64 getRevision() const override;
std::unordered_map<String, String> getSerializedMetadata(const std::vector<String> & paths) const override;
std::string getDiskPath() const override;
DisksSet::const_iterator isStoredOnDisk(const DisksSet & disks) const override;
ReservationPtr reserve(UInt64 bytes) const override;
ReservationPtr tryReserve(UInt64 bytes) const override;
size_t getVolumeIndex(const IStoragePolicy &) 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-05-03 15:48:05 +00:00
void removeDeleteOnDestroyMarker() const override;
void removeVersionMetadata() 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-07 11:58:38 +00:00
2022-04-19 19:34:41 +00:00
void backup(
const MergeTreeDataPartChecksums & checksums,
const NameSet & files_without_checksums,
2022-06-22 20:30:50 +00:00
const String & path_in_backup,
BackupEntries & backup_entries,
bool make_temporary_hard_links,
TemporaryFilesOnDisks * temp_dirs) const override;
2022-04-19 19:34:41 +00:00
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,
2022-09-27 13:50:25 +00:00
bool copy_instead_of_hardlink,
const NameSet & files_to_copy_instead_of_hardlinks) const override;
2022-04-19 19:34:41 +00:00
DataPartStoragePtr clone(
const std::string & to,
const std::string & dir_path,
2022-06-15 11:41:08 +00:00
const DiskPtr & disk,
2022-04-19 19:34:41 +00:00
Poco::Logger * log) const override;
2022-05-05 09:19:12 +00:00
void changeRootPath(const std::string & from_root, const std::string & to_root) override;
2022-06-27 19:41:29 +00:00
DataPartStorageBuilderPtr getBuilder() const override;
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-05-05 09:23:23 +00:00
const MergeTreeDataPartChecksums & checksums,
const std::unordered_set<String> & skip_directories,
2022-08-12 10:47:25 +00:00
bool is_temp,
MergeTreeDataPartState state,
2022-04-19 19:34:41 +00:00
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;
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-06-20 18:18:17 +00:00
std::string getRelativePath() const override;
2022-04-12 18:59:49 +00:00
std::unique_ptr<WriteBufferFromFileBase> writeFile(
2022-06-20 18:18:17 +00:00
const String & name,
2022-05-03 15:48:05 +00:00
size_t buf_size,
const WriteSettings & settings) override;
2022-04-12 18:59:49 +00:00
2022-06-20 18:18:17 +00:00
void removeFile(const String & name) override;
2022-06-23 12:01:26 +00:00
void removeFileIfExists(const String & name) override;
2022-04-12 18:59:49 +00:00
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-06-27 19:41:29 +00:00
void rename(
const std::string & new_root_path,
const std::string & new_part_dir,
Poco::Logger * log,
bool remove_new_dir_if_exists,
bool fsync_part_dir) override;
2022-06-23 16:21:46 +00:00
void commit() override;
2022-04-12 18:59:49 +00:00
private:
VolumePtr volume;
std::string root_path;
std::string part_dir;
2022-06-23 16:21:46 +00:00
DiskTransactionPtr transaction;
2022-04-05 19:12:48 +00:00
};
}