| 835 | } |
| 836 | |
| 837 | Status Coordinator::UpdateExecState(const Status& status, |
| 838 | const TUniqueId* failed_finst, const string& instance_hostname) { |
| 839 | Status ret_status; |
| 840 | ExecState old_state, new_state; |
| 841 | { |
| 842 | lock_guard<SpinLock> l(exec_state_lock_); |
| 843 | old_state = exec_state_.Load(); |
| 844 | if (old_state == ExecState::EXECUTING) { |
| 845 | DCHECK(exec_status_.ok()) << exec_status_; |
| 846 | if (!status.ok()) { |
| 847 | // Error while executing - go to ERROR state. |
| 848 | exec_status_ = status; |
| 849 | exec_state_.Store(ExecState::ERROR); |
| 850 | } |
| 851 | } else if (old_state == ExecState::RETURNED_RESULTS) { |
| 852 | // Already returned all results. Leave exec status as ok, stay in this state. |
| 853 | DCHECK(exec_status_.ok()) << exec_status_; |
| 854 | } else if (old_state == ExecState::CANCELLED) { |
| 855 | // Client requested cancellation already, stay in this state. Ignores errors |
| 856 | // after requested cancellations. |
| 857 | DCHECK(exec_status_.IsCancelled()) << exec_status_; |
| 858 | } else { |
| 859 | // Already in the ERROR state, stay in this state but update status to be the |
| 860 | // first non-cancelled status. |
| 861 | DCHECK_EQ(old_state, ExecState::ERROR); |
| 862 | DCHECK(!exec_status_.ok()); |
| 863 | if (!status.ok() && !status.IsCancelled() && exec_status_.IsCancelled()) { |
| 864 | exec_status_ = status; |
| 865 | } |
| 866 | } |
| 867 | new_state = exec_state_.Load(); |
| 868 | ret_status = exec_status_; |
| 869 | } |
| 870 | // Log interesting status: a non-cancelled error or a cancellation if was executing. |
| 871 | if (!status.ok() && (!status.IsCancelled() || old_state == ExecState::EXECUTING)) { |
| 872 | VLOG_QUERY << Substitute( |
| 873 | "ExecState: query id=$0 finstance=$1 on host=$2 ($3 -> $4) status=$5", |
| 874 | PrintId(query_id()), failed_finst != nullptr ? PrintId(*failed_finst) : "N/A", |
| 875 | instance_hostname, ExecStateToString(old_state), ExecStateToString(new_state), |
| 876 | status.GetDetail()); |
| 877 | } |
| 878 | // After dropping the lock, apply the state transition (if any) side-effects. |
| 879 | HandleExecStateTransition(old_state, new_state); |
| 880 | return ret_status; |
| 881 | } |
| 882 | |
| 883 | void Coordinator::HandleExecStateTransition( |
| 884 | const ExecState old_state, const ExecState new_state) { |
nothing calls this directly
no test coverage detected