forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 12
Improvements to partition export #1177
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
Open
arthurpassos
wants to merge
17
commits into
antalya-25.8
Choose a base branch
from
export_replicated_mt_partition_v2
base: antalya-25.8
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+852
−228
Open
Changes from 11 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3158c06
keep track of export partition zk requests
arthurpassos ba581eb
vibe coded getexportpartitioninfo
arthurpassos efa0b03
move vibe coded getpartitionexports inside the updating task
arthurpassos acf5fd1
rmv unexistent increment
arthurpassos fadf2f7
lock part inside task
arthurpassos d51d703
tmp
arthurpassos ef5807b
okish
arthurpassos 64accc3
add setting to control locking behavior (inside/outside task), deny e…
arthurpassos a63e05d
Merge branch 'antalya-25.8' into export_replicated_mt_partition_v2
arthurpassos 3817e50
clear part references from partition task when status changes, proper…
arthurpassos 85e14f9
settings history
arthurpassos 0d183bf
improvements
arthurpassos 76b3bd6
Merge branch 'antalya-25.8' into export_replicated_mt_partition_v2
arthurpassos 651d6e4
implement local query to system replicated partition exports
arthurpassos 7a1e741
address comments
arthurpassos 1962e19
glitch
arthurpassos 77c64be
Merge branch 'antalya-25.8' into export_replicated_mt_partition_v2
arthurpassos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/Storages/MergeTree/ExportPartFromPartitionExportTask.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #include <Storages/MergeTree/ExportPartFromPartitionExportTask.h> | ||
| #include <Common/ProfileEvents.h> | ||
|
|
||
| namespace ProfileEvents | ||
| { | ||
| extern const Event ExportPartitionZooKeeperRequests; | ||
| extern const Event ExportPartitionZooKeeperGetChildren; | ||
| extern const Event ExportPartitionZooKeeperCreate; | ||
| } | ||
| namespace DB | ||
| { | ||
|
|
||
| ExportPartFromPartitionExportTask::ExportPartFromPartitionExportTask( | ||
| StorageReplicatedMergeTree & storage_, | ||
| const std::string & key_, | ||
| const MergeTreePartExportManifest & manifest_) | ||
| : storage(storage_), | ||
| key(key_), | ||
| manifest(manifest_) | ||
| { | ||
| export_part_task = std::make_shared<ExportPartTask>(storage, manifest); | ||
| } | ||
|
|
||
| bool ExportPartFromPartitionExportTask::executeStep() | ||
| { | ||
| const auto zk = storage.getZooKeeper(); | ||
| const auto part_name = manifest.data_part->name; | ||
|
|
||
| LOG_INFO(storage.log, "ExportPartFromPartitionExportTask: Attempting to lock part: {}", part_name); | ||
|
|
||
| ProfileEvents::increment(ProfileEvents::ExportPartitionZooKeeperRequests); | ||
| ProfileEvents::increment(ProfileEvents::ExportPartitionZooKeeperCreate); | ||
| if (Coordination::Error::ZOK == zk->tryCreate(fs::path(storage.zookeeper_path) / "exports" / key / "locks" / part_name, storage.replica_name, zkutil::CreateMode::Ephemeral)) | ||
| { | ||
| LOG_INFO(storage.log, "ExportPartFromPartitionExportTask: Locked part: {}", part_name); | ||
| export_part_task->executeStep(); | ||
| return false; | ||
| } | ||
|
|
||
| LOG_INFO(storage.log, "ExportPartFromPartitionExportTask: Failed to lock part {}, skipping", part_name); | ||
| return false; | ||
| } | ||
|
|
||
| void ExportPartFromPartitionExportTask::cancel() noexcept | ||
| { | ||
| export_part_task->cancel(); | ||
| } | ||
|
|
||
| void ExportPartFromPartitionExportTask::onCompleted() | ||
| { | ||
| export_part_task->onCompleted(); | ||
| } | ||
|
|
||
| StorageID ExportPartFromPartitionExportTask::getStorageID() const | ||
| { | ||
| return export_part_task->getStorageID(); | ||
| } | ||
|
|
||
| Priority ExportPartFromPartitionExportTask::getPriority() const | ||
| { | ||
| return export_part_task->getPriority(); | ||
| } | ||
|
|
||
| String ExportPartFromPartitionExportTask::getQueryId() const | ||
| { | ||
| return export_part_task->getQueryId(); | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
src/Storages/MergeTree/ExportPartFromPartitionExportTask.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #pragma once | ||
|
|
||
| #include <Storages/MergeTree/IExecutableTask.h> | ||
| #include <Storages/MergeTree/MergeTreePartExportManifest.h> | ||
| #include <Storages/StorageReplicatedMergeTree.h> | ||
| #include <Storages/MergeTree/ExportPartTask.h> | ||
|
|
||
| namespace DB | ||
| { | ||
|
|
||
| class ExportPartFromPartitionExportTask : public IExecutableTask | ||
| { | ||
| public: | ||
| explicit ExportPartFromPartitionExportTask( | ||
| StorageReplicatedMergeTree & storage_, | ||
| const std::string & key_, | ||
| const MergeTreePartExportManifest & manifest_); | ||
| bool executeStep() override; | ||
| void onCompleted() override; | ||
| StorageID getStorageID() const override; | ||
| Priority getPriority() const override; | ||
| String getQueryId() const override; | ||
|
|
||
| void cancel() noexcept override; | ||
|
|
||
| private: | ||
| StorageReplicatedMergeTree & storage; | ||
| std::string key; | ||
| MergeTreePartExportManifest manifest; | ||
| std::shared_ptr<ExportPartTask> export_part_task; | ||
| }; | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| #include <Common/Exception.h> | ||
| #include <Common/ProfileEventsScope.h> | ||
| #include <Storages/MergeTree/ExportList.h> | ||
| #include <Formats/FormatFactory.h> | ||
|
|
||
| namespace ProfileEvents | ||
| { | ||
|
|
@@ -38,15 +39,25 @@ namespace Setting | |
| extern const SettingsUInt64 min_bytes_to_use_direct_io; | ||
| } | ||
|
|
||
| ExportPartTask::ExportPartTask(MergeTreeData & storage_, const MergeTreePartExportManifest & manifest_, ContextPtr context_) | ||
| ExportPartTask::ExportPartTask(MergeTreeData & storage_, const MergeTreePartExportManifest & manifest_) | ||
| : storage(storage_), | ||
| manifest(manifest_), | ||
| local_context(context_) | ||
| manifest(manifest_) | ||
| { | ||
| } | ||
|
|
||
| const MergeTreePartExportManifest & ExportPartTask::getManifest() const | ||
| { | ||
| return manifest; | ||
| } | ||
|
|
||
| bool ExportPartTask::executeStep() | ||
| { | ||
| auto local_context = Context::createCopy(storage.getContext()); | ||
| local_context->makeQueryContextForExportPart(); | ||
| local_context->setCurrentQueryId(manifest.transaction_id); | ||
| local_context->setBackgroundOperationTypeForContext(ClientInfo::BackgroundOperationType::EXPORT_PART); | ||
| local_context->setSettings(manifest.settings); | ||
|
|
||
| const auto & metadata_snapshot = manifest.metadata_snapshot; | ||
|
|
||
| Names columns_to_read = metadata_snapshot->getColumns().getNamesOfPhysical(); | ||
|
|
@@ -91,7 +102,7 @@ bool ExportPartTask::executeStep() | |
| block_with_partition_values, | ||
| (*exports_list_entry)->destination_file_path, | ||
| manifest.file_already_exists_policy == MergeTreePartExportManifest::FileAlreadyExistsPolicy::overwrite, | ||
| manifest.format_settings, | ||
| getFormatSettings(local_context), | ||
| local_context); | ||
| } | ||
| catch (const Exception & e) | ||
|
|
@@ -126,10 +137,21 @@ bool ExportPartTask::executeStep() | |
| } | ||
| } | ||
|
|
||
| tryLogCurrentException(__PRETTY_FUNCTION__); | ||
| LOG_INFO(getLogger("ExportPartTask"), "Export part {} failed: {}", manifest.data_part->name, e.message()); | ||
|
||
|
|
||
| ProfileEvents::increment(ProfileEvents::PartsExportFailures); | ||
|
|
||
| storage.writePartLog( | ||
| PartLogElement::Type::EXPORT_PART, | ||
| ExecutionStatus::fromCurrentException("", true), | ||
| static_cast<UInt64>((*exports_list_entry)->elapsed * 1000000000), | ||
| manifest.data_part->name, | ||
| manifest.data_part, | ||
| {manifest.data_part}, | ||
| nullptr, | ||
| nullptr, | ||
| exports_list_entry.get()); | ||
|
|
||
| std::lock_guard inner_lock(storage.export_manifests_mutex); | ||
| storage.export_manifests.erase(manifest); | ||
|
|
||
|
|
@@ -259,6 +281,7 @@ bool ExportPartTask::executeStep() | |
|
|
||
| void ExportPartTask::cancel() noexcept | ||
| { | ||
| LOG_INFO(getLogger("ExportPartTask"), "Export part {} task cancel() method called", manifest.data_part->name); | ||
| cancel_requested.store(true); | ||
| pipeline.cancel(); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.