ClickHouse/src/Storages/MergeTree/DataPartStorageOnDiskBase.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

139 lines
5.1 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>
#include <Disks/IVolume.h>
2022-04-05 19:12:48 +00:00
#include <memory>
#include <string>
namespace DB
{
class IVolume;
using VolumePtr = std::shared_ptr<IVolume>;
class DataPartStorageOnDiskBase : public IDataPartStorage
2022-04-05 19:12:48 +00:00
{
public:
DataPartStorageOnDiskBase(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;
2022-06-20 18:18:17 +00:00
std::string getFullRootPath() const override;
2022-04-08 18:56:08 +00:00
Poco::Timestamp getLastModified() const override;
2022-06-20 18:18:17 +00:00
UInt64 calculateTotalSizeOnDisk() const override;
2022-10-18 16:13:18 +00:00
/// Returns path to place detached part in or nullopt if we don't need to detach part (if it already exists and has the same content)
2022-09-30 18:09:18 +00:00
std::optional<String> getRelativePathForPrefix(Poco::Logger * log, const String & prefix, bool detached, bool broken) const override;
2022-10-18 16:13:18 +00:00
/// Returns true if detached part already exists and has the same content (compares checksums.txt and the list of files)
2022-09-30 18:09:18 +00:00
bool looksLikeBrokenDetachedPartHasTheSameContent(const String & detached_part_path, std::optional<String> & original_checksums_content,
2022-10-18 16:13:18 +00:00
std::optional<Strings> & original_files_list) const;
2022-04-19 19:34:41 +00:00
2022-06-20 18:18:17 +00:00
void setRelativePath(const std::string & path) 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;
2023-06-01 22:02:17 +00:00
std::optional<String> getCacheName() 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;
2023-02-28 11:17:43 +00:00
bool isReadonly() const override;
void syncRevision(UInt64 revision) const override;
2022-06-20 18:18:17 +00:00
UInt64 getRevision() const override;
std::string getDiskPath() const override;
ReservationPtr reserve(UInt64 bytes) const override;
ReservationPtr tryReserve(UInt64 bytes) const override;
ReplicatedFilesDescription getReplicatedFilesDescription(const NameSet & file_names) const override;
ReplicatedFilesDescription getReplicatedFilesDescriptionForRemoteDisk(const NameSet & file_names) const override;
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,
const BackupSettings & backup_settings,
bool make_temporary_hard_links,
BackupEntries & backup_entries,
TemporaryFilesOnDisks * temp_dirs) const override;
2022-04-19 19:34:41 +00:00
2022-10-22 22:51:59 +00:00
MutableDataPartStoragePtr freeze(
2022-04-19 19:34:41 +00:00
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,
DiskTransactionPtr external_transaction) const override;
2022-04-19 19:34:41 +00:00
2022-10-22 22:51:59 +00:00
MutableDataPartStoragePtr clonePart(
2022-04-19 19:34:41 +00:00
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;
void rename(
std::string new_root_path,
std::string new_part_dir,
Poco::Logger * log,
bool remove_new_dir_if_exists,
bool fsync_part_dir) override;
2022-05-05 09:19:12 +00:00
void remove(
CanRemoveCallback && can_remove_callback,
const MergeTreeDataPartChecksums & checksums,
std::list<ProjectionChecksums> projections,
bool is_temp,
Poco::Logger * log) override;
void changeRootPath(const std::string & from_root, const std::string & to_root) override;
2022-04-12 18:59:49 +00:00
void createDirectories() override;
2022-10-23 22:29:24 +00:00
std::unique_ptr<WriteBufferFromFileBase> writeTransactionFile(WriteMode mode) const 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;
bool hasActiveTransaction() const override;
2022-04-21 19:19:13 +00:00
protected:
DiskPtr getDisk() const;
2022-06-27 19:41:29 +00:00
DataPartStorageOnDiskBase(VolumePtr volume_, std::string root_path_, std::string part_dir_, DiskTransactionPtr transaction_);
virtual MutableDataPartStoragePtr create(VolumePtr volume_, std::string root_path_, std::string part_dir_, bool initialize_) const = 0;
2022-06-23 16:21:46 +00:00
2022-04-12 18:59:49 +00:00
VolumePtr volume;
std::string root_path;
std::string part_dir;
2022-06-23 16:21:46 +00:00
DiskTransactionPtr transaction;
2022-10-24 15:08:51 +00:00
bool has_shared_transaction = false;
2022-10-22 22:51:59 +00:00
template <typename Op>
void executeWriteOperation(Op && op)
{
if (transaction)
op(*transaction);
else
op(*volume->getDisk());
}
2022-10-22 22:51:59 +00:00
private:
2022-10-22 22:51:59 +00:00
void clearDirectory(
const std::string & dir,
const CanRemoveDescription & can_remove_description,
2022-10-22 22:51:59 +00:00
const MergeTreeDataPartChecksums & checksums,
bool is_temp,
Poco::Logger * log);
/// For names of expected data part files returns the actual names
/// of files in filesystem to which data of these files is written.
/// Actual file name may be the same as expected
/// or be the name of the file with packed data.
virtual NameSet getActualFileNamesOnDisk(const NameSet & file_names) const = 0;
2022-04-05 19:12:48 +00:00
};
2022-04-05 19:12:48 +00:00
}