@@ -5910,14 +5910,15 @@ void MergeTreeData::exportPartToTable(const PartitionCommand & command, ContextP
59105910
59115911 const auto database_name = query_context->resolveDatabase (command.to_database );
59125912
5913- exportPartToTable (part_name, StorageID{database_name, command.to_table }, query_context);
5913+ exportPartToTable (part_name, StorageID{database_name, command.to_table }, query_context-> getCurrentQueryId (), query_context );
59145914}
59155915
59165916void MergeTreeData::exportPartToTable (
59175917 const std::string & part_name,
59185918 const StorageID & destination_storage_id,
5919+ const String & transaction_id,
59195920 ContextPtr query_context,
5920- std::function<void (MergeTreeExportManifest ::CompletionCallbackResult)> completion_callback)
5921+ std::function<void (MergeTreePartExportManifest ::CompletionCallbackResult)> completion_callback)
59215922{
59225923 auto dest_storage = DatabaseCatalog::instance ().getTable (destination_storage_id, query_context);
59235924
@@ -5950,9 +5951,10 @@ void MergeTreeData::exportPartToTable(
59505951 part_name, getStorageID ().getFullTableName ());
59515952
59525953 {
5953- MergeTreeExportManifest manifest (
5954+ MergeTreePartExportManifest manifest (
59545955 dest_storage->getStorageID (),
59555956 part,
5957+ transaction_id,
59565958 query_context->getSettingsRef ()[Setting::export_merge_tree_part_overwrite_file_if_exists],
59575959 query_context->getSettingsRef ()[Setting::output_format_parallel_formatting],
59585960 completion_callback);
@@ -5970,7 +5972,7 @@ void MergeTreeData::exportPartToTable(
59705972}
59715973
59725974void MergeTreeData::exportPartToTableImpl (
5973- const MergeTreeExportManifest & manifest,
5975+ const MergeTreePartExportManifest & manifest,
59745976 ContextPtr local_context)
59755977{
59765978 auto metadata_snapshot = getInMemoryMetadataPtr ();
@@ -6027,7 +6029,7 @@ void MergeTreeData::exportPartToTableImpl(
60276029 export_manifests.erase (manifest);
60286030
60296031 if (manifest.completion_callback )
6030- manifest.completion_callback (MergeTreeExportManifest ::CompletionCallbackResult::createFailure (e.message ()));
6032+ manifest.completion_callback (MergeTreePartExportManifest ::CompletionCallbackResult::createFailure (e.message ()));
60316033 return ;
60326034 }
60336035
@@ -6096,6 +6098,9 @@ void MergeTreeData::exportPartToTableImpl(
60966098
60976099 pipeline.complete (sink);
60986100
6101+ // / oh boy, is there another way?
6102+ manifest.pipeline = &pipeline;
6103+
60996104 try
61006105 {
61016106 CompletedPipelineExecutor exec (pipeline);
@@ -6119,7 +6124,7 @@ void MergeTreeData::exportPartToTableImpl(
61196124 ProfileEvents::increment (ProfileEvents::PartsExportTotalMilliseconds, static_cast <UInt64>((*exports_list_entry)->elapsed * 1000 ));
61206125
61216126 if (manifest.completion_callback )
6122- manifest.completion_callback (MergeTreeExportManifest ::CompletionCallbackResult::createSuccess (destination_file_path));
6127+ manifest.completion_callback (MergeTreePartExportManifest ::CompletionCallbackResult::createSuccess (destination_file_path));
61236128 }
61246129 catch (const Exception & e)
61256130 {
@@ -6142,12 +6147,30 @@ void MergeTreeData::exportPartToTableImpl(
61426147 export_manifests.erase (manifest);
61436148
61446149 if (manifest.completion_callback )
6145- manifest.completion_callback (MergeTreeExportManifest ::CompletionCallbackResult::createFailure (e.message ()));
6150+ manifest.completion_callback (MergeTreePartExportManifest ::CompletionCallbackResult::createFailure (e.message ()));
61466151
61476152 throw ;
61486153 }
61496154}
61506155
6156+ void MergeTreeData::killExportPart (const String & query_id)
6157+ {
6158+ std::lock_guard lock (export_manifests_mutex);
6159+
6160+ const auto it = std::find_if (export_manifests.begin (), export_manifests.end (), [&](const auto & manifest)
6161+ {
6162+ return manifest.query_id == query_id;
6163+ });
6164+
6165+ if (it == export_manifests.end ())
6166+ return ;
6167+
6168+ if (it->pipeline )
6169+ it->pipeline ->cancel ();
6170+
6171+ export_manifests.erase (it);
6172+ }
6173+
61516174void MergeTreeData::movePartitionToShard (const ASTPtr & /* partition*/ , bool /* move_part*/ , const String & /* to*/ , ContextPtr /* query_context*/ )
61526175{
61536176 throw Exception (ErrorCodes::NOT_IMPLEMENTED, " MOVE PARTITION TO SHARD is not supported by storage {}" , getName ());
@@ -8881,7 +8904,9 @@ bool MergeTreeData::scheduleDataMovingJob(BackgroundJobsAssignee & assignee)
88818904 }
88828905
88838906 manifest.in_progress = assignee.scheduleMoveTask (std::make_shared<ExecutableLambdaAdapter>(
8884- [this , manifest] () mutable {
8907+ [this , &manifest] () mutable {
8908+ // / TODO arthur fix this: I need to be able to modify the real manifest
8909+ // / but grabbing it by reference is causing problems
88858910 exportPartToTableImpl (manifest, getContext ());
88868911 return true ;
88878912 },
0 commit comments