diff --git a/presto-native-execution/presto_cpp/main/PrestoTask.cpp b/presto-native-execution/presto_cpp/main/PrestoTask.cpp index 98a0c2498f6ea..780360ba034c2 100644 --- a/presto-native-execution/presto_cpp/main/PrestoTask.cpp +++ b/presto-native-execution/presto_cpp/main/PrestoTask.cpp @@ -149,9 +149,12 @@ uint64_t PrestoTask::timeSinceLastHeartbeatMs() const { } protocol::TaskStatus PrestoTask::updateStatusLocked() { - if (!taskStarted) { - info.taskStatus.state = protocol::TaskState::RUNNING; - return info.taskStatus; + if (!taskStarted and error == nullptr) { + protocol::TaskStatus ret = info.taskStatus; + if (ret.state != protocol::TaskState::ABORTED) { + ret.state = protocol::TaskState::PLANNED; + } + return ret; } // Error occurs when creating task or even before task is created. Set error diff --git a/presto-native-execution/presto_cpp/main/PrestoTask.h b/presto-native-execution/presto_cpp/main/PrestoTask.h index 47760f945ed4e..ab4453460ef1b 100644 --- a/presto-native-execution/presto_cpp/main/PrestoTask.h +++ b/presto-native-execution/presto_cpp/main/PrestoTask.h @@ -68,7 +68,14 @@ struct ResultRequest { struct PrestoTask { const PrestoTaskId id; std::shared_ptr task; + + // Has the task been normally created and started. + // When you create task with error - it has never been started. + // When you create task from 'delete task' - it has never been started. + // When you create task from any other endpoint, such as 'get result' - it has + // not been started, until the actual 'create task' message comes. bool taskStarted{false}; + uint64_t lastHeartbeatMs{0}; mutable std::mutex mutex; diff --git a/presto-native-execution/presto_cpp/main/TaskManager.cpp b/presto-native-execution/presto_cpp/main/TaskManager.cpp index c4b642701a0dc..3ebdc36e5a41a 100644 --- a/presto-native-execution/presto_cpp/main/TaskManager.cpp +++ b/presto-native-execution/presto_cpp/main/TaskManager.cpp @@ -169,8 +169,6 @@ std::unique_ptr TaskManager::createOrUpdateErrorTask( } prestoTask->info.needsPlan = false; } - // outside of prestoTask->mutex. - prestoTask->taskStarted = true; auto info = prestoTask->updateInfo(); return std::make_unique(info);