| 163 | } |
| 164 | |
| 165 | void CloudUniqueMergeTreeMergeTask::executeImpl() |
| 166 | { |
| 167 | Stopwatch watch; |
| 168 | |
| 169 | auto txn = getContext()->getCurrentTransaction(); |
| 170 | if (!txn) |
| 171 | throw Exception("Transaction is not set", ErrorCodes::LOGICAL_ERROR); |
| 172 | auto txn_id = txn->getTransactionID(); |
| 173 | |
| 174 | auto lock = storage.lockForShare(RWLockImpl::NO_QUERY, storage.getSettings()->lock_acquire_timeout_for_background_operations); |
| 175 | |
| 176 | LOG_TRACE(log, "Begin to execute merge task {}", params.task_id); |
| 177 | |
| 178 | auto catalog = getContext()->getCnchCatalog(); |
| 179 | auto t1 = getContext()->getTimestamp(); |
| 180 | /// get and set src part's bitmap meta at t1 |
| 181 | curr_bitmap_metas = getDeleteBitmapMetas(*catalog, params.source_data_parts, t1); |
| 182 | for (size_t i = 0; i < curr_bitmap_metas.size(); ++i) |
| 183 | { |
| 184 | params.source_data_parts[i]->setDeleteBitmapMeta(curr_bitmap_metas[i]); |
| 185 | curr_bitmaps.push_back(params.source_data_parts[i]->getDeleteBitmap()); |
| 186 | } |
| 187 | |
| 188 | LOG_TRACE(log, "Prepared delete bitmap for source parts"); |
| 189 | |
| 190 | /// merge src parts using delete bitmap at t1 |
| 191 | MergeTreeDataMerger merger( |
| 192 | storage, |
| 193 | params, |
| 194 | getContext(), |
| 195 | getManipulationListElement(), |
| 196 | [&, this] { |
| 197 | if (isCancelled()) |
| 198 | return true; |
| 199 | |
| 200 | /// TODO: refactor this |
| 201 | auto last_touch_time = getManipulationListElement()->last_touch_time.load(std::memory_order_relaxed); |
| 202 | if (UInt64(time(nullptr) - last_touch_time) > getContext()->getSettingsRef().cloud_task_auto_stop_timeout) |
| 203 | { |
| 204 | LOG_TRACE( |
| 205 | &Poco::Logger::get("CloudUniqueMergeTreeMergeTask"), |
| 206 | "Task {} doesn't receive heartbeat from server, stop it self.", |
| 207 | params.task_id); |
| 208 | setCancelled(); |
| 209 | } |
| 210 | return isCancelled(); |
| 211 | }, |
| 212 | /*build_rowid_mappings*/ true); |
| 213 | /// data of temp part will be removed in dtor |
| 214 | auto merged_part = merger.mergePartsToTemporaryPart(); |
| 215 | |
| 216 | DeleteBitmapPtr merged_part_bitmap = std::make_shared<Roaring>(); |
| 217 | /// t2: convert any new deletes of src part into deletes on merged part |
| 218 | updateDeleteBitmap(*catalog, merger, merged_part_bitmap); |
| 219 | |
| 220 | /// prepare parts and bitmaps to dump |
| 221 | std::vector<ReservationPtr> reservations; |
| 222 | IMutableMergeTreeDataPartsVector parts_to_dump; |
nothing calls this directly
no test coverage detected