1212#include < QueryPipeline/QueryPipelineBuilder.h>
1313#include " Common/Exception.h"
1414#include < Common/ProfileEventsScope.h>
15+ #include " Storages/MergeTree/ExportList.h"
1516
1617namespace ProfileEvents
1718{
@@ -68,8 +69,19 @@ bool ExportPartTask::executeStep()
6869 throw Exception (ErrorCodes::UNKNOWN_TABLE, " Failed to reconstruct destination storage: {}" , destination_storage_id_name);
6970 }
7071
72+ auto exports_list_entry = storage.getContext ()->getExportsList ().insert (
73+ getStorageID (),
74+ manifest.destination_storage_id ,
75+ manifest.data_part ->getBytesOnDisk (),
76+ manifest.data_part ->name ,
77+ " not_computed_yet" ,
78+ manifest.data_part ->rows_count ,
79+ manifest.data_part ->getBytesOnDisk (),
80+ manifest.data_part ->getBytesUncompressedOnDisk (),
81+ manifest.create_time ,
82+ local_context);
83+
7184 SinkToStoragePtr sink;
72- std::string destination_file_path;
7385
7486 try
7587 {
@@ -81,18 +93,44 @@ bool ExportPartTask::executeStep()
8193 sink = destination_storage->import (
8294 manifest.data_part ->name + " _" + manifest.data_part ->checksums .getTotalChecksumHex (),
8395 block_with_partition_values,
84- destination_file_path,
85- manifest.overwrite_file_if_exists ,
96+ (*exports_list_entry)-> destination_file_path ,
97+ manifest.file_already_exists_policy == MergeTreePartExportManifest::FileAlreadyExistsPolicy::OVERWRITE ,
8698 context_copy);
8799 }
88100 catch (const Exception & e)
89101 {
90- tryLogCurrentException (__PRETTY_FUNCTION__);
91102 if (e.code () == ErrorCodes::FILE_ALREADY_EXISTS)
92103 {
93104 ProfileEvents::increment (ProfileEvents::PartsExportDuplicated);
105+
106+ // / File already exists and the policy is NO_OP, treat it as success.
107+ if (manifest.file_already_exists_policy == MergeTreePartExportManifest::FileAlreadyExistsPolicy::NO_OP)
108+ {
109+ storage.writePartLog (
110+ PartLogElement::Type::EXPORT_PART,
111+ {},
112+ static_cast <UInt64>((*exports_list_entry)->elapsed * 1000000000 ),
113+ manifest.data_part ->name ,
114+ manifest.data_part ,
115+ {manifest.data_part },
116+ nullptr ,
117+ nullptr ,
118+ exports_list_entry.get ());
119+
120+ std::lock_guard inner_lock (storage.export_manifests_mutex );
121+ storage.export_manifests .erase (manifest);
122+
123+ ProfileEvents::increment (ProfileEvents::PartsExports);
124+ ProfileEvents::increment (ProfileEvents::PartsExportTotalMilliseconds, static_cast <UInt64>((*exports_list_entry)->elapsed * 1000 ));
125+
126+ if (manifest.completion_callback )
127+ manifest.completion_callback (MergeTreePartExportManifest::CompletionCallbackResult::createSuccess ((*exports_list_entry)->destination_file_path ));
128+ return false ;
129+ }
94130 }
95131
132+ tryLogCurrentException (__PRETTY_FUNCTION__);
133+
96134 ProfileEvents::increment (ProfileEvents::PartsExportFailures);
97135
98136 std::lock_guard inner_lock (storage.export_manifests_mutex );
@@ -139,17 +177,6 @@ bool ExportPartTask::executeStep()
139177 local_context,
140178 getLogger (" ExportPartition" ));
141179
142- auto exports_list_entry = storage.getContext ()->getExportsList ().insert (
143- getStorageID (),
144- manifest.destination_storage_id ,
145- manifest.data_part ->getBytesOnDisk (),
146- manifest.data_part ->name ,
147- destination_file_path,
148- manifest.data_part ->rows_count ,
149- manifest.data_part ->getBytesOnDisk (),
150- manifest.data_part ->getBytesUncompressedOnDisk (),
151- manifest.create_time ,
152- local_context);
153180
154181 ThreadGroupSwitcher switcher ((*exports_list_entry)->thread_group , " " );
155182
@@ -198,7 +225,7 @@ bool ExportPartTask::executeStep()
198225 ProfileEvents::increment (ProfileEvents::PartsExportTotalMilliseconds, static_cast <UInt64>((*exports_list_entry)->elapsed * 1000 ));
199226
200227 if (manifest.completion_callback )
201- manifest.completion_callback (MergeTreePartExportManifest::CompletionCallbackResult::createSuccess (destination_file_path));
228+ manifest.completion_callback (MergeTreePartExportManifest::CompletionCallbackResult::createSuccess ((*exports_list_entry)-> destination_file_path ));
202229 }
203230 catch (const Exception & e)
204231 {
0 commit comments