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

fix bug stop job before it start #4061

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/meta/processors/job/JobDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool JobDescription::setStatus(Status newStatus, bool force) {
return false;
}
status_ = newStatus;
if (newStatus == Status::RUNNING) {
if (newStatus == Status::RUNNING || (newStatus == Status::STOPPED && startTime_ == 0)) {
startTime_ = std::time(nullptr);
}
if (JobStatus::laterThan(newStatus, Status::RUNNING)) {
Expand Down
9 changes: 5 additions & 4 deletions src/meta/processors/job/JobManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void JobManager::scheduleThread() {
auto jobOp = std::get<0>(opJobId);
auto jodId = std::get<1>(opJobId);
auto spaceId = std::get<2>(opJobId);
std::lock_guard<std::recursive_mutex> lk(muJobFinished_[spaceId]);
auto jobDescRet = JobDescription::loadJobDescription(spaceId, jodId, kvStore_);
if (!nebula::ok(jobDescRet)) {
LOG(INFO) << "[JobManager] load an invalid job from space " << spaceId << " jodId " << jodId;
Expand All @@ -152,8 +153,6 @@ void JobManager::scheduleThread() {
}

bool JobManager::runJobInternal(const JobDescription& jobDesc, JbOp op) {
auto spaceId = jobDesc.getSpace();
std::lock_guard<std::recursive_mutex> lk(muJobFinished_[spaceId]);
std::unique_ptr<JobExecutor> je =
JobExecutorFactory::createJobExecutor(jobDesc, kvStore_, adminClient_);
JobExecutor* jobExec = je.get();
Expand Down Expand Up @@ -257,8 +256,10 @@ nebula::cpp2::ErrorCode JobManager::jobFinished(GraphSpaceID spaceId,

auto it = runningJobs_.find(jobId);
if (it == runningJobs_.end()) {
LOG(INFO) << folly::sformat("Can't find jobExecutor, jobId={}", jobId);
return nebula::cpp2::ErrorCode::E_UNKNOWN;
// the job has not started yet
panda-sheep marked this conversation as resolved.
Show resolved Hide resolved
// TODO job not existing in runningJobs_ also means leader changed, we handle it later
cleanJob(jobId);
return nebula::cpp2::ErrorCode::SUCCEEDED;
}
std::unique_ptr<JobExecutor>& jobExec = it->second;
if (jobStatus == cpp2::JobStatus::STOPPED) {
Expand Down
1 change: 1 addition & 0 deletions src/meta/processors/job/JobManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class JobManager : public boost::noncopyable, public nebula::cpp::NonMovable {
AdminClient* adminClient_{nullptr};

std::map<GraphSpaceID, std::mutex> muReportFinish_;
// Start & stop & finish a job need mutual exclusion
// The reason of using recursive_mutex is that, it's possible for a meta job try to get this lock
// in finish-callback in the same thread with runJobInternal
std::map<GraphSpaceID, std::recursive_mutex> muJobFinished_;
Expand Down