@@ -6272,182 +6272,6 @@ void MergeTreeData::exportPartToTable(
62726272 background_moves_assignee.trigger ();
62736273}
62746274
6275- void MergeTreeData::exportPartToTableImpl (
6276- const MergeTreePartExportManifest & manifest,
6277- ContextPtr local_context)
6278- {
6279- auto metadata_snapshot = getInMemoryMetadataPtr ();
6280- Names columns_to_read = metadata_snapshot->getColumns ().getNamesOfPhysical ();
6281- StorageSnapshotPtr storage_snapshot = getStorageSnapshot (metadata_snapshot, local_context);
6282-
6283- MergeTreeSequentialSourceType read_type = MergeTreeSequentialSourceType::Export;
6284-
6285- Block block_with_partition_values;
6286- if (metadata_snapshot->hasPartitionKey ())
6287- {
6288- // / todo arthur do I need to init minmax_idx?
6289- block_with_partition_values = manifest.data_part ->minmax_idx ->getBlock (*this );
6290- }
6291-
6292- auto destination_storage = DatabaseCatalog::instance ().tryGetTable (manifest.destination_storage_id , getContext ());
6293- if (!destination_storage)
6294- {
6295- std::lock_guard inner_lock (export_manifests_mutex);
6296-
6297- const auto destination_storage_id_name = manifest.destination_storage_id .getNameForLogs ();
6298- export_manifests.erase (manifest);
6299- throw Exception (ErrorCodes::UNKNOWN_TABLE, " Failed to reconstruct destination storage: {}" , destination_storage_id_name);
6300- }
6301-
6302- SinkToStoragePtr sink;
6303- std::string destination_file_path;
6304-
6305- try
6306- {
6307- auto context_copy = Context::createCopy (local_context);
6308- context_copy->setSetting (" output_format_parallel_formatting" , manifest.parallel_formatting );
6309-
6310- sink = destination_storage->import (
6311- manifest.data_part ->name + " _" + manifest.data_part ->checksums .getTotalChecksumHex (),
6312- block_with_partition_values,
6313- destination_file_path,
6314- manifest.overwrite_file_if_exists ,
6315- context_copy);
6316- }
6317- catch (const Exception & e)
6318- {
6319- if (e.code () == ErrorCodes::FILE_ALREADY_EXISTS)
6320- {
6321- ProfileEvents::increment (ProfileEvents::PartsExportDuplicated);
6322- }
6323-
6324- ProfileEvents::increment (ProfileEvents::PartsExportFailures);
6325-
6326- std::lock_guard inner_lock (export_manifests_mutex);
6327- export_manifests.erase (manifest);
6328-
6329- if (manifest.completion_callback )
6330- manifest.completion_callback (MergeTreePartExportManifest::CompletionCallbackResult::createFailure (e.message ()));
6331- return ;
6332- }
6333-
6334- bool apply_deleted_mask = true ;
6335- bool read_with_direct_io = local_context->getSettingsRef ()[Setting::min_bytes_to_use_direct_io] > manifest.data_part ->getBytesOnDisk ();
6336- bool prefetch = false ;
6337-
6338- MergeTreeData::IMutationsSnapshot::Params params
6339- {
6340- .metadata_version = metadata_snapshot->getMetadataVersion (),
6341- .min_part_metadata_version = manifest.data_part ->getMetadataVersion (),
6342- };
6343-
6344- auto mutations_snapshot = getMutationsSnapshot (params);
6345-
6346- auto alter_conversions = MergeTreeData::getAlterConversionsForPart (
6347- manifest.data_part ,
6348- mutations_snapshot,
6349- local_context);
6350-
6351- QueryPlan plan_for_part;
6352-
6353- createReadFromPartStep (
6354- read_type,
6355- plan_for_part,
6356- *this ,
6357- storage_snapshot,
6358- RangesInDataPart (manifest.data_part ),
6359- alter_conversions,
6360- nullptr ,
6361- columns_to_read,
6362- nullptr ,
6363- apply_deleted_mask,
6364- std::nullopt ,
6365- read_with_direct_io,
6366- prefetch,
6367- local_context,
6368- getLogger (" ExportPartition" ));
6369-
6370- auto exports_list_entry = getContext ()->getExportsList ().insert (
6371- getStorageID (),
6372- manifest.destination_storage_id ,
6373- manifest.data_part ->getBytesOnDisk (),
6374- manifest.data_part ->name ,
6375- destination_file_path,
6376- manifest.data_part ->rows_count ,
6377- manifest.data_part ->getBytesOnDisk (),
6378- manifest.data_part ->getBytesUncompressedOnDisk (),
6379- manifest.create_time ,
6380- local_context);
6381-
6382- ThreadGroupSwitcher switcher ((*exports_list_entry)->thread_group , " " );
6383-
6384- QueryPlanOptimizationSettings optimization_settings (local_context);
6385- auto pipeline_settings = BuildQueryPipelineSettings (local_context);
6386- auto builder = plan_for_part.buildQueryPipeline (optimization_settings, pipeline_settings);
6387-
6388- builder->setProgressCallback ([&exports_list_entry](const Progress & progress)
6389- {
6390- (*exports_list_entry)->bytes_read_uncompressed += progress.read_bytes ;
6391- (*exports_list_entry)->rows_read += progress.read_rows ;
6392- (*exports_list_entry)->elapsed = (*exports_list_entry)->watch .elapsedSeconds ();
6393- });
6394-
6395- auto pipeline = QueryPipelineBuilder::getPipeline (std::move (*builder));
6396-
6397- pipeline.complete (sink);
6398-
6399- try
6400- {
6401- CompletedPipelineExecutor exec (pipeline);
6402- exec.execute ();
6403-
6404- std::lock_guard inner_lock (export_manifests_mutex);
6405- writePartLog (
6406- PartLogElement::Type::EXPORT_PART,
6407- {},
6408- static_cast <UInt64>((*exports_list_entry)->elapsed * 1000000000 ),
6409- manifest.data_part ->name ,
6410- manifest.data_part ,
6411- {manifest.data_part },
6412- nullptr ,
6413- nullptr ,
6414- exports_list_entry.get ());
6415-
6416- export_manifests.erase (manifest);
6417-
6418- ProfileEvents::increment (ProfileEvents::PartsExports);
6419- ProfileEvents::increment (ProfileEvents::PartsExportTotalMilliseconds, static_cast <UInt64>((*exports_list_entry)->elapsed * 1000 ));
6420-
6421- if (manifest.completion_callback )
6422- manifest.completion_callback (MergeTreePartExportManifest::CompletionCallbackResult::createSuccess (destination_file_path));
6423- }
6424- catch (const Exception & e)
6425- {
6426- tryLogCurrentException (__PRETTY_FUNCTION__, fmt::format (" while exporting the part {}. User should retry." , manifest.data_part ->name ));
6427-
6428- ProfileEvents::increment (ProfileEvents::PartsExportFailures);
6429-
6430- std::lock_guard inner_lock (export_manifests_mutex);
6431- writePartLog (
6432- PartLogElement::Type::EXPORT_PART,
6433- ExecutionStatus::fromCurrentException (" " , true ),
6434- static_cast <UInt64>((*exports_list_entry)->elapsed * 1000000000 ),
6435- manifest.data_part ->name ,
6436- manifest.data_part ,
6437- {manifest.data_part },
6438- nullptr ,
6439- nullptr ,
6440- exports_list_entry.get ());
6441-
6442- export_manifests.erase (manifest);
6443-
6444- if (manifest.completion_callback )
6445- manifest.completion_callback (MergeTreePartExportManifest::CompletionCallbackResult::createFailure (e.message ()));
6446-
6447- throw ;
6448- }
6449- }
6450-
64516275void MergeTreeData::killExportPart (const String & query_id)
64526276{
64536277 std::lock_guard lock (export_manifests_mutex);
0 commit comments