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

Check running job before create backup #5013

Merged
merged 5 commits into from
Dec 27, 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
4 changes: 2 additions & 2 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,8 @@ Status MetaClient::handleResponse(const RESP& resp) {
return Status::Error("Task report is out of date!");
case nebula::cpp2::ErrorCode::E_BACKUP_FAILED:
return Status::Error("Backup failure!");
case nebula::cpp2::ErrorCode::E_BACKUP_BUILDING_INDEX:
return Status::Error("Backup building indexes!");
case nebula::cpp2::ErrorCode::E_BACKUP_RUNNING_JOBS:
return Status::Error("Backup encounter running or queued jobs!");
case nebula::cpp2::ErrorCode::E_BACKUP_SPACE_NOT_FOUND:
return Status::Error("The space is not found when backup!");
case nebula::cpp2::ErrorCode::E_RESTORE_FAILURE:
Expand Down
2 changes: 1 addition & 1 deletion src/common/graph/Response.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
X(E_INVALID_JOB, -2065) \
\
/* Backup Failure */ \
X(E_BACKUP_BUILDING_INDEX, -2066) \
X(E_BACKUP_RUNNING_JOBS, -2066) \
X(E_BACKUP_SPACE_NOT_FOUND, -2067) \
\
/* RESTORE Failure */ \
Expand Down
2 changes: 1 addition & 1 deletion src/interface/common.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ enum ErrorCode {
E_INVALID_JOB = -2065, // Invalid task

// Backup Failure
E_BACKUP_BUILDING_INDEX = -2066, // Backup terminated (index being created)
E_BACKUP_RUNNING_JOBS = -2066, // Backup terminated (some data modification jobs running)
E_BACKUP_SPACE_NOT_FOUND = -2067, // Graph space does not exist at the time of backup

// RESTORE Failure
Expand Down
13 changes: 9 additions & 4 deletions src/meta/processors/admin/CreateBackupProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,22 @@ void CreateBackupProcessor::process(const cpp2::CreateBackupReq& req) {

// make sure there is no index job
std::unordered_set<cpp2::JobType> jobTypes{cpp2::JobType::REBUILD_TAG_INDEX,
cpp2::JobType::REBUILD_EDGE_INDEX};
cpp2::JobType::REBUILD_EDGE_INDEX,
cpp2::JobType::COMPACT,
cpp2::JobType::INGEST,
cpp2::JobType::DATA_BALANCE,
cpp2::JobType::LEADER_BALANCE};
auto result = jobMgr->checkTypeJobRunning(jobTypes);
if (!nebula::ok(result)) {
LOG(INFO) << "Get Index status failed, not allowed to create backup.";
LOG(INFO) << "Get running job status failed, not allowed to create backup.";
handleErrorCode(nebula::error(result));
onFinished();
return;
}
if (nebula::value(result)) {
LOG(INFO) << "Index is rebuilding, not allowed to create backup.";
handleErrorCode(nebula::cpp2::ErrorCode::E_BACKUP_BUILDING_INDEX);
LOG(INFO) << "There is some running or queued job mutating the data, not allowed to "
"create backup now.";
handleErrorCode(nebula::cpp2::ErrorCode::E_BACKUP_RUNNING_JOBS);
onFinished();
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/meta/processors/job/AdminJobProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ nebula::cpp2::ErrorCode AdminJobProcessor::addJobProcess(const cpp2::AdminJobReq
}

folly::SharedMutex::WriteHolder holder(LockUtils::lock());
folly::SharedMutex::ReadHolder snapHolder(LockUtils::snapshotLock());
auto jobId = autoIncrementId();
if (!nebula::ok(jobId)) {
return nebula::error(jobId);
Expand Down
4 changes: 4 additions & 0 deletions src/meta/processors/job/JobManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,10 @@ ErrorOr<nebula::cpp2::ErrorCode, bool> JobManager::checkTypeJobRunning(

auto status = jobDesc.getStatus();
if (status == cpp2::JobStatus::QUEUE || status == cpp2::JobStatus::RUNNING) {
LOG(INFO) << folly::sformat("The {} job is {} in space {}",
apache::thrift::util::enumNameSafe(jType),
apache::thrift::util::enumNameSafe(status),
spaceId);
return true;
}
}
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 @@ -29,6 +29,7 @@ extern stats::CounterId kNumRunningJobs;
class JobManager : public boost::noncopyable, public nebula::cpp::NonMovable {
friend class JobManagerTest;
friend class GetStatsTest;
friend class CreateBackupProcessorTest;
FRIEND_TEST(JobManagerTest, AddJob);
FRIEND_TEST(JobManagerTest, StatsJob);
FRIEND_TEST(JobManagerTest, JobPriority);
Expand Down
Loading