| 301 | } |
| 302 | |
| 303 | bool AutoStatisticsManager::executeOneTask(const std::shared_ptr<TaskInfo> & chosen_task) |
| 304 | { |
| 305 | auto catalog = createCatalogAdaptor(context); |
| 306 | |
| 307 | auto uuid = chosen_task->getTableUUID(); |
| 308 | auto table_opt = catalog->getTableIdByUUID(uuid); |
| 309 | |
| 310 | if (!table_opt) |
| 311 | { |
| 312 | // uuid is invalid, possibly due to table is dropped |
| 313 | auto err_msg = fmt::format(FMT_STRING("uuid {} is no longer valid, skip auto stats task"), toString(uuid)); |
| 314 | LOG_WARNING(logger, err_msg); |
| 315 | chosen_task->setStatus(Status::Failed); |
| 316 | writeTaskLog(context, *chosen_task, err_msg); |
| 317 | task_queue.erase(uuid); |
| 318 | return true; |
| 319 | } |
| 320 | |
| 321 | StatsTableIdentifier table = table_opt.value(); |
| 322 | try |
| 323 | { |
| 324 | LOG_INFO(logger, fmt::format(FMT_STRING("start auto stats on {}"), table.getNameForLogs())); |
| 325 | |
| 326 | chosen_task->setStatus(Status::Running); |
| 327 | writeTaskLog(context, *chosen_task); |
| 328 | |
| 329 | auto settings = internal_config.collector_settings; |
| 330 | auto columns_name = chosen_task->getColumnsName(); |
| 331 | |
| 332 | if (!chosen_task->getSettingsJson().empty()) |
| 333 | { |
| 334 | settings.fromJsonStr(chosen_task->getSettingsJson()); |
| 335 | } |
| 336 | |
| 337 | CollectTarget target(context, table, settings, columns_name); |
| 338 | auto row_count_opt = collectStatsOnTarget(context, target); |
| 339 | |
| 340 | if (row_count_opt.has_value()) |
| 341 | { |
| 342 | // normal execution finishes |
| 343 | auto row_count = row_count_opt.value(); |
| 344 | LOG_INFO(logger, fmt::format(FMT_STRING("finish auto stats on {}"), table.getNameForLogs())); |
| 345 | chosen_task->setStatus(Status::Success); |
| 346 | chosen_task->setParams(0, row_count, 0); |
| 347 | writeTaskLog(context, *chosen_task); |
| 348 | task_queue.erase(uuid); |
| 349 | } |
| 350 | else |
| 351 | { |
| 352 | // trigger if_not_exists and skip collection due to stats exists |
| 353 | // task is still successful |
| 354 | LOG_INFO(logger, fmt::format(FMT_STRING("skip auto stats on {} since stats exists"), table.getNameForLogs())); |
| 355 | chosen_task->setStatus(Status::Success); |
| 356 | chosen_task->setParams(0, 0, 0); |
| 357 | writeTaskLog(context, *chosen_task, "skip since stats exists"); |
| 358 | task_queue.erase(uuid); |
| 359 | } |
| 360 |
nothing calls this directly
no test coverage detected