every failed call on BackgroundJob in this function will be retried on next time
| 618 | |
| 619 | /// every failed call on BackgroundJob in this function will be retried on next time |
| 620 | bool DaemonJobServerBGThread::executeImpl() |
| 621 | { |
| 622 | if (suspended()) |
| 623 | { |
| 624 | LOG_DEBUG(log, "thread suspended"); |
| 625 | std::unique_lock lock(bg_jobs_mutex); |
| 626 | background_jobs.clear(); |
| 627 | return true; |
| 628 | } |
| 629 | |
| 630 | Context & context = *getContext(); |
| 631 | std::shared_ptr<CnchTopologyMaster> topology_master = context.getCnchTopologyMaster(); |
| 632 | if (!topology_master) |
| 633 | { |
| 634 | LOG_ERROR(log, "Failed to get topology master"); |
| 635 | return false; |
| 636 | } |
| 637 | |
| 638 | UInt64 milliseconds = 0; |
| 639 | Stopwatch watch; |
| 640 | BackgroundJobs background_jobs_clone; |
| 641 | { |
| 642 | std::shared_lock shared_lock(bg_jobs_mutex); |
| 643 | background_jobs_clone = background_jobs; |
| 644 | } |
| 645 | |
| 646 | milliseconds = watch.elapsedMilliseconds(); |
| 647 | if (milliseconds >= SLOW_EXECUTION_THRESHOLD_MS) |
| 648 | LOG_DEBUG(log, "copy background jobs took {} ms.", milliseconds); |
| 649 | |
| 650 | watch.restart(); |
| 651 | std::unordered_map<UUID, StorageID> new_uuid_map = getUUIDsFromCatalog(*this); |
| 652 | milliseconds = watch.elapsedMilliseconds(); |
| 653 | if (milliseconds >= SLOW_EXECUTION_THRESHOLD_MS) |
| 654 | LOG_DEBUG(log, "getUUIDsFromCatalog with size {} took {} ms.", new_uuid_map.size(), milliseconds); |
| 655 | |
| 656 | std::map<String, UInt64> new_server_start_times = fetchServerStartTimes(context, *topology_master, log); |
| 657 | if (new_server_start_times.empty()) |
| 658 | { |
| 659 | LOG_WARNING(log, "There are network partition, skip this iteration"); |
| 660 | return false; |
| 661 | } |
| 662 | |
| 663 | const std::vector<String> alive_servers = findAliveServers(new_server_start_times); |
| 664 | watch.restart(); |
| 665 | UpdateResult update_res = getUpdateBGJobs(background_jobs_clone, new_uuid_map, alive_servers); |
| 666 | milliseconds = watch.elapsedMilliseconds(); |
| 667 | if (milliseconds >= SLOW_EXECUTION_THRESHOLD_MS) |
| 668 | LOG_DEBUG(log, "getUpdateBGJobs took {} ms.", milliseconds); |
| 669 | |
| 670 | const UUIDs & remove_uuids = update_res.remove_uuids; |
| 671 | for (auto uuid : remove_uuids) |
| 672 | LOG_DEBUG(log, "UUID: {} will be removed from background jobs", UUIDHelpers::UUIDToString(uuid)); |
| 673 | |
| 674 | const UUIDs & add_uuids = update_res.add_uuids; |
| 675 | for (auto uuid : add_uuids) |
| 676 | LOG_DEBUG(log, "UUID: {} will be added into background jobs", UUIDHelpers::UUIDToString(uuid)); |
| 677 |
nothing calls this directly
no test coverage detected