| 80 | } |
| 81 | |
| 82 | void TaskQueue::updateTasksFromLogIfNeeded(const TaskInfoLog & log) |
| 83 | { |
| 84 | std::unique_lock lck(mtx); |
| 85 | auto context = getContext(); |
| 86 | auto table_uuid = log.table_uuid; |
| 87 | auto min_start_lease = nowTimePoint() + internal_config.schedule_period; |
| 88 | |
| 89 | if (task_infos.count(table_uuid)) |
| 90 | { |
| 91 | auto old_task_info = task_infos.at(table_uuid); |
| 92 | |
| 93 | if (old_task_info->getTaskUUID() != log.task_uuid) |
| 94 | { |
| 95 | // here two tasks working on a same table |
| 96 | |
| 97 | bool choose_old = false; |
| 98 | auto core_old = old_task_info->getCore(); |
| 99 | auto core_new = static_cast<TaskInfoCore>(log); |
| 100 | |
| 101 | // users may submit a new manual task, and the AutoStatsManager may submit a new auto task |
| 102 | // that duplicates with existing auto task or old manual task |
| 103 | // we should keep the oldest manual task |
| 104 | if (core_old.task_type == TaskType::Manual) |
| 105 | { |
| 106 | // if the old is manual, we just keep it, and cancel the new one |
| 107 | // wherever the new one is auto task or manual task |
| 108 | choose_old = true; |
| 109 | } |
| 110 | else if (core_new.task_type == TaskType::Manual) |
| 111 | { |
| 112 | // cancel the existing auto task |
| 113 | choose_old = false; |
| 114 | } |
| 115 | else |
| 116 | { |
| 117 | // duplicated auto task |
| 118 | // it should be not possible |
| 119 | // but here we just choose the higher priority one |
| 120 | choose_old = core_old.priority >= core_new.priority; |
| 121 | } |
| 122 | |
| 123 | if (choose_old) |
| 124 | { |
| 125 | core_new.status = Status::Cancelled; |
| 126 | auto info = fmt::format(FMT_STRING("Replaced by another task {}"), toString(core_old.task_uuid)); |
| 127 | writeTaskLog(context, core_new, info); |
| 128 | return; |
| 129 | } |
| 130 | else |
| 131 | { |
| 132 | core_old.status = Status::Cancelled; |
| 133 | auto info = fmt::format(FMT_STRING("Replaced by another task {}"), toString(core_new.task_uuid)); |
| 134 | writeTaskLog(context, core_old, info); |
| 135 | task_infos.erase(table_uuid); |
| 136 | // continue execution as if we have no old task |
| 137 | } |
| 138 | } |
| 139 | else |
no test coverage detected