Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get job fail status for show job commands #3112

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions src/sdk/sql_cluster_router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,13 @@ std::shared_ptr<hybridse::sdk::ResultSet> SQLClusterRouter::HandleSQLCmd(const h
*status = {StatusCode::kCmdError, "Failed to parse job id: " + cmd_node->GetArgs()[0]};
return {};
}
return this->GetJobResultSet(job_id);

auto rs = this->GetJobResultSet(job_id, status);
if (status->IsOK()) {
tobegit3hub marked this conversation as resolved.
Show resolved Hide resolved
return rs;
} else {
return {};
}
}
case hybridse::node::kCmdShowJobLog: {
int job_id;
Expand Down Expand Up @@ -1873,7 +1879,13 @@ std::shared_ptr<hybridse::sdk::ResultSet> SQLClusterRouter::HandleSQLCmd(const h

::openmldb::taskmanager::JobInfo job_info;
StopJob(job_id, &job_info);
return this->GetJobResultSet(job_id);

auto rs = this->GetJobResultSet(job_id, status);
if (status->IsOK()) {
return rs;
} else {
return {};
}
}
case hybridse::node::kCmdDropTable: {
*status = {};
Expand Down Expand Up @@ -2563,7 +2575,12 @@ std::shared_ptr<hybridse::sdk::ResultSet> SQLClusterRouter::ExecuteSQL(
ReadSparkConfFromFile(std::dynamic_pointer_cast<SQLRouterOptions>(options_)->spark_conf_path, &config);
auto base_status = ExportOfflineData(sql, config, db, is_sync_job, offline_job_timeout, &job_info);
if (base_status.OK()) {
return this->GetJobResultSet(job_info.id());
auto rs = this->GetJobResultSet(job_info.id(), status);
if (status->IsOK()) {
return rs;
} else {
return {};
}
} else {
*status = {StatusCode::kCmdError, base_status.msg};
}
Expand Down Expand Up @@ -2617,7 +2634,12 @@ std::shared_ptr<hybridse::sdk::ResultSet> SQLClusterRouter::ExecuteSQL(
base_status = ImportOfflineData(sql, config, database, is_sync_job, offline_job_timeout, &job_info);
}
if (base_status.OK() && job_info.id() > 0) {
return this->GetJobResultSet(job_info.id());
auto rs = this->GetJobResultSet(job_info.id(), status);
if (status->IsOK()) {
return rs;
} else {
return {};
}
} else {
APPEND_FROM_BASE_AND_WARN(status, base_status, "taskmanager load data failed");
}
Expand Down Expand Up @@ -2675,7 +2697,13 @@ std::shared_ptr<hybridse::sdk::ResultSet> SQLClusterRouter::ExecuteOfflineQuery(
APPEND_FROM_BASE_AND_WARN(status, base_status, "async offline query failed");
return {};
}
return this->GetJobResultSet(job_info.id());

auto rs = this->GetJobResultSet(job_info.id(), status);
if (status->IsOK()) {
return rs;
} else {
return {};
}
}
}

Expand Down Expand Up @@ -4191,19 +4219,18 @@ void SQLClusterRouter::ReadSparkConfFromFile(std::string conf_file_path, std::ma
}
}

std::shared_ptr<hybridse::sdk::ResultSet> SQLClusterRouter::GetJobResultSet(int job_id) {
hybridse::sdk::Status status;

std::shared_ptr<hybridse::sdk::ResultSet> SQLClusterRouter::GetJobResultSet(int job_id,
::hybridse::sdk::Status* status) {
std::string db = openmldb::nameserver::INTERNAL_DB;
std::string sql = "SELECT * FROM JOB_INFO WHERE id = " + std::to_string(job_id);

auto rs = ExecuteSQLParameterized(db, sql, {}, &status);
if (!status.IsOK()) {
auto rs = ExecuteSQLParameterized(db, sql, {}, status);
if (!status->IsOK()) {
return {};
}
if (rs->Size() == 0) {
status.code = ::hybridse::common::StatusCode::kCmdError;
status.msg = "Job not found: " + std::to_string(job_id);
status->SetCode(::hybridse::common::StatusCode::kCmdError);
status->SetMsg("Job not found: " + std::to_string(job_id));
return {};
}
if (FLAGS_role == "sql_client") {
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/sql_cluster_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class SQLClusterRouter : public SQLRouter {
const std::string& pattern,
hybridse::sdk::Status* status);

std::shared_ptr<hybridse::sdk::ResultSet> GetJobResultSet(int job_id);
std::shared_ptr<hybridse::sdk::ResultSet> GetJobResultSet(int job_id, ::hybridse::sdk::Status* status);

bool CheckTableStatus(const std::string& db, const std::string& table_name, uint32_t tid,
const nameserver::TablePartition& partition_info, uint32_t replica_num,
Expand Down