New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change ZooKeeper path for zero-copy locks for shared data #32061
Changes from 15 commits
827fa51
0f9038e
d409ab0
80ab73c
c8fe1dc
e0a16a4
0e685c1
98bae1b
f0b9a43
c724b07
f390111
0c0bf66
33cbfc8
e6fd4bf
e88b97d
0465aef
2d87f0a
7a3c874
8b331cd
cbdba89
92cb451
91e1ac4
b426cc4
6fcd5a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,9 @@ class IStorage : public std::enable_shared_from_this<IStorage>, public TypePromo | |
/// The name of the table. | ||
StorageID getStorageID() const; | ||
|
||
/// Unique ID, synchronized between replicas for replicated storage | ||
virtual String getTableUniqID() const { return ""; } | ||
|
||
/// Returns true if the storage receives data from a remote server or servers. | ||
virtual bool isRemote() const { return false; } | ||
|
||
|
@@ -138,6 +141,9 @@ class IStorage : public std::enable_shared_from_this<IStorage>, public TypePromo | |
/// Returns true if the storage replicates SELECT, INSERT and ALTER commands among replicas. | ||
virtual bool supportsReplication() const { return false; } | ||
|
||
/// Returns replica name for replicated storage | ||
virtual String getReplicaName() const { return ""; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used only in replicated storage. We don't need it here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
/// Returns true if the storage supports parallel insert. | ||
virtual bool supportsParallelInsert() const { return false; } | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -338,6 +338,9 @@ class IMergeTreeDataPart : public std::enable_shared_from_this<IMergeTreeDataPar | |
/// Changes only relative_dir_name, you need to update other metadata (name, is_temp) explicitly | ||
virtual void renameTo(const String & new_relative_path, bool remove_new_dir_if_exists) const; | ||
|
||
/// Cleanup after change part | ||
virtual void cleanupOldName(const String & old_part_name) const; | ||
|
||
/// Makes clone of a part in detached/ directory via hard links | ||
virtual void makeCloneInDetached(const String & prefix, const StorageMetadataPtr & metadata_snapshot) const; | ||
|
||
|
@@ -404,10 +407,14 @@ class IMergeTreeDataPart : public std::enable_shared_from_this<IMergeTreeDataPar | |
/// part creation (using alter query with materialize_ttl setting). | ||
bool checkAllTTLCalculated(const StorageMetadataPtr & metadata_snapshot) const; | ||
|
||
/// Return some uniq string for file | ||
/// Required for distinguish different copies of the same part on S3 | ||
/// Return some uniq string for file. | ||
/// Required for distinguish different copies of the same part on remote FS. | ||
String getUniqueId() const; | ||
|
||
/// Return hardlink count for part. | ||
/// Required for keep data on remote FS when part has shadow copies. | ||
UInt32 getRefCount() const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to clarify that it's not some general-purpose refcount. The name should be something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed to |
||
|
||
protected: | ||
|
||
/// Total size of all columns, calculated once in calcuateColumnSizesOnDisk | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ | |
|
||
#include <boost/range/adaptor/filtered.hpp> | ||
#include <boost/algorithm/string/join.hpp> | ||
#include <boost/algorithm/string/replace.hpp> | ||
|
||
#include <base/insertAtEnd.h> | ||
#include <base/scope_guard_safe.h> | ||
|
@@ -2457,6 +2458,8 @@ bool MergeTreeData::renameTempPartAndReplace( | |
MergeTreePartInfo part_info = part->info; | ||
String part_name; | ||
|
||
String old_part_name = part->name; | ||
|
||
if (DataPartPtr existing_part_in_partition = getAnyPartInPartition(part->info.partition_id, lock)) | ||
{ | ||
if (part->partition.value != existing_part_in_partition->partition.value) | ||
|
@@ -2520,6 +2523,7 @@ bool MergeTreeData::renameTempPartAndReplace( | |
/// So, we maintain invariant: if a non-temporary part in filesystem then it is in data_parts | ||
/// | ||
/// If out_transaction is null, we commit the part to the active set immediately, else add it to the transaction. | ||
|
||
part->name = part_name; | ||
part->info = part_info; | ||
part->is_temp = false; | ||
|
@@ -2568,6 +2572,8 @@ bool MergeTreeData::renameTempPartAndReplace( | |
out_covered_parts->emplace_back(std::move(covered_part)); | ||
} | ||
|
||
part->cleanupOldName(old_part_name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add something in changelog about it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
return true; | ||
} | ||
|
||
|
@@ -3906,8 +3912,8 @@ void MergeTreeData::dropDetached(const ASTPtr & partition, bool part, ContextPtr | |
|
||
for (auto & [old_name, new_name, disk] : renamed_parts.old_and_new_names) | ||
{ | ||
disk->removeRecursive(fs::path(relative_data_path) / "detached" / new_name / ""); | ||
LOG_DEBUG(log, "Dropped detached part {}", old_name); | ||
bool keep_shared = removeDetachedPart(disk, fs::path(relative_data_path) / "detached" / new_name / "", old_name, false); | ||
LOG_DEBUG(log, "Dropped detached part {}, keep shared data: {}", old_name, keep_shared); | ||
old_name.clear(); | ||
} | ||
} | ||
|
@@ -5195,7 +5201,9 @@ PartitionCommandsResultInfo MergeTreeData::freezePartitionsByMatcher( | |
|
||
LOG_DEBUG(log, "Freezing part {} snapshot will be placed at {}", part->name, backup_path); | ||
|
||
part->volume->getDisk()->createDirectories(backup_path); | ||
auto disk = part->volume->getDisk(); | ||
|
||
disk->createDirectories(backup_path); | ||
|
||
String src_part_path = part->getFullRelativePath(); | ||
String backup_part_path = fs::path(backup_path) / relative_data_path / part->relative_path; | ||
|
@@ -5206,16 +5214,18 @@ PartitionCommandsResultInfo MergeTreeData::freezePartitionsByMatcher( | |
src_part_path = fs::path(relative_data_path) / flushed_part_path / ""; | ||
} | ||
|
||
localBackup(part->volume->getDisk(), src_part_path, backup_part_path); | ||
localBackup(disk, src_part_path, backup_part_path); | ||
|
||
freezeMetaData(disk, part, backup_part_path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment -- "Store metadata for replicated tables and do nothing for ordinary merge tree" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
part->volume->getDisk()->removeFileIfExists(fs::path(backup_part_path) / IMergeTreeDataPart::DELETE_ON_DESTROY_MARKER_FILE_NAME); | ||
disk->removeFileIfExists(fs::path(backup_part_path) / IMergeTreeDataPart::DELETE_ON_DESTROY_MARKER_FILE_NAME); | ||
|
||
part->is_frozen.store(true, std::memory_order_relaxed); | ||
result.push_back(PartitionCommandResultInfo{ | ||
.partition_id = part->info.partition_id, | ||
.part_name = part->name, | ||
.backup_path = fs::path(part->volume->getDisk()->getPath()) / backup_path, | ||
.part_backup_path = fs::path(part->volume->getDisk()->getPath()) / backup_part_path, | ||
.backup_path = fs::path(disk->getPath()) / backup_path, | ||
.part_backup_path = fs::path(disk->getPath()) / backup_part_path, | ||
.backup_name = backup_name, | ||
}); | ||
++parts_processed; | ||
|
@@ -5225,6 +5235,11 @@ PartitionCommandsResultInfo MergeTreeData::freezePartitionsByMatcher( | |
return result; | ||
} | ||
|
||
void MergeTreeData::freezeMetaData(DiskPtr, DataPartPtr, String) const | ||
{ | ||
|
||
} | ||
|
||
PartitionCommandsResultInfo MergeTreeData::unfreezePartition( | ||
const ASTPtr & partition, | ||
const String & backup_name, | ||
|
@@ -5242,6 +5257,13 @@ PartitionCommandsResultInfo MergeTreeData::unfreezeAll( | |
return unfreezePartitionsByMatcher([] (const String &) { return true; }, backup_name, local_context); | ||
} | ||
|
||
bool MergeTreeData::removeDetachedPart(DiskPtr disk, const String & path, const String &, bool) | ||
{ | ||
disk->removeRecursive(path); | ||
|
||
return false; | ||
} | ||
|
||
PartitionCommandsResultInfo MergeTreeData::unfreezePartitionsByMatcher(MatcherFn matcher, const String & backup_name, ContextPtr) | ||
{ | ||
auto backup_path = fs::path("shadow") / escapeForFileName(backup_name) / relative_data_path; | ||
|
@@ -5270,7 +5292,7 @@ PartitionCommandsResultInfo MergeTreeData::unfreezePartitionsByMatcher(MatcherFn | |
|
||
const auto & path = it->path(); | ||
|
||
disk->removeRecursive(path); | ||
bool keep_shared = removeDetachedPart(disk, path, partition_directory, true); | ||
|
||
result.push_back(PartitionCommandResultInfo{ | ||
.partition_id = partition_id, | ||
|
@@ -5280,7 +5302,7 @@ PartitionCommandsResultInfo MergeTreeData::unfreezePartitionsByMatcher(MatcherFn | |
.backup_name = backup_name, | ||
}); | ||
|
||
LOG_DEBUG(log, "Unfreezed part by path {}", disk->getPath() + path); | ||
LOG_DEBUG(log, "Unfreezed part by path {}, keep shared data: {}", disk->getPath() + path, keep_shared); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove, only used for
StorageReplicatedMergeTree
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.