1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
#pragma once
#include <Storages/MergeTree/IDataPartStorage.h>
#include <Disks/IDisk.h>
#include <Disks/IVolume.h>
#include <memory>
#include <string>
namespace DB
{
class IVolume;
using VolumePtr = std::shared_ptr<IVolume>;
class DataPartStorageOnDiskBase : public IDataPartStorage
{
public:
DataPartStorageOnDiskBase(VolumePtr volume_, std::string root_path_, std::string part_dir_);
std::string getFullPath() const override;
std::string getRelativePath() const override;
std::string getPartDirectory() const override;
std::string getFullRootPath() const override;
Poco::Timestamp getLastModified() const override;
UInt64 calculateTotalSizeOnDisk() const override;
/// 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)
std::optional<String> getRelativePathForPrefix(Poco::Logger * log, const String & prefix, bool detached, bool broken) const override;
/// Returns true if detached part already exists and has the same content (compares checksums.txt and the list of files)
bool looksLikeBrokenDetachedPartHasTheSameContent(const String & detached_part_path, std::optional<String> & original_checksums_content,
std::optional<Strings> & original_files_list) const;
void setRelativePath(const std::string & path) override;
std::string getDiskName() const override;
std::string getDiskType() const override;
bool isStoredOnRemoteDisk() const override;
std::optional<String> getCacheName() const override;
bool supportZeroCopyReplication() const override;
bool supportParallelWrite() const override;
bool isBroken() const override;
bool isReadonly() const override;
void syncRevision(UInt64 revision) const override;
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;
void backup(
const MergeTreeDataPartChecksums & checksums,
const NameSet & files_without_checksums,
const String & path_in_backup,
const BackupSettings & backup_settings,
const ReadSettings & read_settings,
bool make_temporary_hard_links,
BackupEntries & backup_entries,
TemporaryFilesOnDisks * temp_dirs) const override;
MutableDataPartStoragePtr freeze(
const std::string & to,
const std::string & dir_path,
std::function<void(const DiskPtr &)> save_metadata_callback,
const ClonePartParams & params) const override;
MutableDataPartStoragePtr clonePart(
const std::string & to,
const std::string & dir_path,
const DiskPtr & dst_disk,
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;
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;
void createDirectories() override;
std::unique_ptr<WriteBufferFromFileBase> writeTransactionFile(WriteMode mode) const override;
void removeRecursive() override;
void removeSharedRecursive(bool keep_in_remote_fs) override;
SyncGuardPtr getDirectorySyncGuard() const override;
bool hasActiveTransaction() const override;
protected:
DiskPtr getDisk() const;
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;
VolumePtr volume;
std::string root_path;
std::string part_dir;
DiskTransactionPtr transaction;
bool has_shared_transaction = false;
template <typename Op>
void executeWriteOperation(Op && op)
{
if (transaction)
op(*transaction);
else
op(*volume->getDisk());
}
private:
void clearDirectory(
const std::string & dir,
const CanRemoveDescription & can_remove_description,
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;
};
}
|