77#include < Common/ProfileEvents.h>
88#include " Storages/MergeTree/ExportPartitionUtils.h"
99#include " Storages/MergeTree/MergeTreePartExportManifest.h"
10+ #include " Storages/MergeTree/ExportPartFromPartitionExportTask.h"
11+ #include " Formats/FormatFactory.h"
12+ #include < Core/Settings.h>
1013
1114namespace ProfileEvents
1215{
@@ -24,6 +27,11 @@ namespace ProfileEvents
2427namespace DB
2528{
2629
30+ namespace Setting
31+ {
32+ extern const SettingsMergeTreePartExportFileAlreadyExistsPolicy export_merge_tree_part_file_already_exists_policy;
33+ }
34+
2735namespace ErrorCodes
2836{
2937 extern const int QUERY_WAS_CANCELLED;
@@ -156,41 +164,29 @@ void ExportPartitionTaskScheduler::run()
156164 continue ;
157165 }
158166
159- ProfileEvents::increment (ProfileEvents::ExportPartitionZooKeeperRequests);
160- ProfileEvents::increment (ProfileEvents::ExportPartitionZooKeeperCreate);
161- if (Coordination::Error::ZOK != zk->tryCreate (fs::path (storage.zookeeper_path ) / " exports" / key / " locks" / zk_part_name, storage.replica_name , zkutil::CreateMode::Ephemeral))
162- {
163- LOG_INFO (storage.log , " ExportPartition scheduler task: Failed to lock part {}, skipping" , zk_part_name);
164- continue ;
165- }
167+ std::lock_guard part_export_lock (storage.export_manifests_mutex );
166168
167- try
168- {
169- storage.exportPartToTable (
170- part->name ,
171- destination_storage_id,
172- manifest.transaction_id ,
173- getContextCopyWithTaskSettings (storage.getContext (), manifest),
174- /* allow_outdated_parts*/ true ,
175- [this , key, zk_part_name, manifest, destination_storage]
176- (MergeTreePartExportManifest::CompletionCallbackResult result)
177- {
178- handlePartExportCompletion (key, zk_part_name, manifest, destination_storage, result);
179- });
180- }
181- catch (const Exception &)
182- {
183- tryLogCurrentException (__PRETTY_FUNCTION__);
184- zk->tryRemove (fs::path (storage.zookeeper_path ) / " exports" / key / " locks" / zk_part_name);
185- ProfileEvents::increment (ProfileEvents::ExportPartitionZooKeeperRequests);
186- ProfileEvents::increment (ProfileEvents::ExportPartitionZooKeeperRemove);
187- // / we should not increment retry_count because the node might just be full
188- }
169+ auto context = getContextCopyWithTaskSettings (storage.getContext (), manifest);
170+
171+ const auto format_settings = getFormatSettings (context);
172+
173+ MergeTreePartExportManifest part_export_manifest (
174+ destination_storage->getStorageID (),
175+ part,
176+ manifest.transaction_id ,
177+ context->getSettingsRef ()[Setting::export_merge_tree_part_file_already_exists_policy].value ,
178+ format_settings,
179+ storage.getInMemoryMetadataPtr (),
180+ [this , key, zk_part_name, manifest, destination_storage]
181+ (MergeTreePartExportManifest::CompletionCallbackResult result)
182+ {
183+ handlePartExportCompletion (key, zk_part_name, manifest, destination_storage, result);
184+ });
185+
186+ storage.background_moves_assignee .scheduleMoveTask (
187+ std::make_shared<ExportPartFromPartitionExportTask>(storage, key, part_export_manifest, getContextCopyWithTaskSettings (storage.getContext (), manifest)));
189188 }
190189 }
191-
192- // / maybe we failed to schedule or failed to export, need to retry eventually
193- storage.export_merge_tree_partition_select_task ->scheduleAfter (1000 * 5 );
194190}
195191
196192void ExportPartitionTaskScheduler::handlePartExportCompletion (
0 commit comments