| 11101 | |
| 11102 | |
| 11103 | void Master::updateTask(Task* task, const StatusUpdate& update) |
| 11104 | { |
| 11105 | CHECK_NOTNULL(task); |
| 11106 | |
| 11107 | // Get the unacknowledged status. |
| 11108 | const TaskStatus& status = update.status(); |
| 11109 | |
| 11110 | // NOTE: Refer to comments on `StatusUpdate` message in messages.proto for |
| 11111 | // the difference between `update.latest_state()` and `status.state()`. |
| 11112 | |
| 11113 | // Updates from the slave have 'latest_state' set. |
| 11114 | Option<TaskState> latestState; |
| 11115 | if (update.has_latest_state()) { |
| 11116 | latestState = update.latest_state(); |
| 11117 | } |
| 11118 | |
| 11119 | const TaskState updateState = latestState.getOrElse(status.state()); |
| 11120 | |
| 11121 | // Determine whether the task transitioned to terminal or |
| 11122 | // unreachable prior to changing the task state. |
| 11123 | auto isTerminalOrUnreachableState = [](const TaskState& state) { |
| 11124 | return protobuf::isTerminalState(state) || state == TASK_UNREACHABLE; |
| 11125 | }; |
| 11126 | |
| 11127 | bool transitionedToTerminalOrUnreachable = |
| 11128 | !isTerminalOrUnreachableState(task->state()) && |
| 11129 | isTerminalOrUnreachableState(updateState); |
| 11130 | |
| 11131 | // Indicates whether we should send a notification to subscribers, |
| 11132 | // set if the task transitioned to a new state. |
| 11133 | bool sendSubscribersUpdate = false; |
| 11134 | |
| 11135 | Framework* framework = getFramework(task->framework_id()); |
| 11136 | |
| 11137 | // If the task has already transitioned to a terminal state, |
| 11138 | // do not update its state. Note that we are being defensive |
| 11139 | // here because this should not happen unless there is a bug |
| 11140 | // in the master code. |
| 11141 | // |
| 11142 | // TODO(bmahler): Check that we're not transitioning from |
| 11143 | // TASK_UNREACHABLE to another state. |
| 11144 | if (!protobuf::isTerminalState(task->state())) { |
| 11145 | if (task->state() != updateState && framework != nullptr) { |
| 11146 | // When we observe a transition away from a non-terminal state, |
| 11147 | // decrement the relevant metric. |
| 11148 | framework->metrics.decrementActiveTaskState(task->state()); |
| 11149 | |
| 11150 | framework->metrics.incrementTaskState(updateState); |
| 11151 | } |
| 11152 | |
| 11153 | task->set_state(updateState); |
| 11154 | } |
| 11155 | |
| 11156 | // If this is a (health) check status update, always forward it to |
| 11157 | // subscribers. |
| 11158 | if (status.reason() == TaskStatus::REASON_TASK_CHECK_STATUS_UPDATED || |
| 11159 | status.reason() == TaskStatus::REASON_TASK_HEALTH_CHECK_STATUS_UPDATED) { |
| 11160 | sendSubscribersUpdate = true; |
nothing calls this directly
no test coverage detected