| 46 | } |
| 47 | |
| 48 | void CloudMergeTreeMergeTask::executeImpl() |
| 49 | { |
| 50 | auto heartbeat_timeout = getContext()->getSettingsRef().cloud_task_auto_stop_timeout.value; |
| 51 | auto lock = storage.lockForShare(RWLockImpl::NO_QUERY, storage.getSettings()->lock_acquire_timeout_for_background_operations); |
| 52 | |
| 53 | auto & cloud_table = dynamic_cast<StorageCloudMergeTree &>(*params.storage.get()); |
| 54 | MergeTreeDataMerger merger(cloud_table, params, getContext(), manipulation_entry->get(), [&]() { |
| 55 | return isCancelled(heartbeat_timeout); |
| 56 | }); |
| 57 | |
| 58 | auto merged_part = merger.mergePartsToTemporaryPart(); |
| 59 | |
| 60 | IMutableMergeTreeDataPartsVector temp_parts; |
| 61 | std::vector<ReservationPtr> reserved_spaces; // hold space |
| 62 | |
| 63 | for (auto & part : params.source_data_parts) |
| 64 | { |
| 65 | /// TODO: Double check, set drop part's mutation to current txnid and hint_mutation to corresponding part's mutation. |
| 66 | if (part->info.level == MergeTreePartInfo::MAX_LEVEL) |
| 67 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "Drop part info level is MAX_LEVEL"); |
| 68 | |
| 69 | MergeTreePartInfo drop_part_info( |
| 70 | part->info.partition_id, |
| 71 | part->info.min_block, |
| 72 | part->info.max_block, |
| 73 | part->info.level + 1, |
| 74 | getContext()->getCurrentTransactionID().toUInt64(), |
| 75 | 0 /* must be zero for drop part */); |
| 76 | |
| 77 | reserved_spaces.emplace_back(cloud_table.reserveSpace(0)); /// Drop part is empty part. |
| 78 | auto single_disk_volume = std::make_shared<SingleDiskVolume>("volume_" + part->name, reserved_spaces.back()->getDisk(), 0); |
| 79 | |
| 80 | auto drop_part = std::make_shared<MergeTreeDataPartCNCH>( |
| 81 | storage, drop_part_info.getPartName(), drop_part_info, single_disk_volume, std::nullopt); |
| 82 | |
| 83 | drop_part->partition.assign(part->partition); |
| 84 | drop_part->bucket_number = part->bucket_number; |
| 85 | drop_part->deleted = true; |
| 86 | /// rows_count and bytes_on_disk is required for parts info statistics. |
| 87 | drop_part->covered_parts_rows = part->rows_count; |
| 88 | drop_part->covered_parts_size = part->bytes_on_disk; |
| 89 | drop_part->last_modification_time = part->last_modification_time? part->last_modification_time : part->commit_time; |
| 90 | temp_parts.push_back(std::move(drop_part)); |
| 91 | } |
| 92 | |
| 93 | /// 0 rows part may come from unique table or DELETE mutation, and we can safely mark it as deleted. |
| 94 | if (merged_part->rows_count == 0) |
| 95 | merged_part->deleted = true; |
| 96 | |
| 97 | temp_parts.push_back(std::move(merged_part)); |
| 98 | |
| 99 | if (isCancelled(heartbeat_timeout)) |
| 100 | throw Exception("Merge task " + params.task_id + " is cancelled", ErrorCodes::ABORTED); |
| 101 | |
| 102 | UInt64 peak_memory_usage = 0; |
| 103 | |
| 104 | ManipulationListElement * manipulation_list_element = getManipulationListElement(); |
| 105 | if (manipulation_list_element) |
nothing calls this directly
no test coverage detected