Skip to content

Commit

Permalink
Check running job before create backup (#5013)
Browse files Browse the repository at this point in the history
* refactor create bakcup processor test

change back to snapshot lock and acquire lock when add job

* fix initialize

* improve log

* fix job manager

Co-authored-by: Sophie <[email protected]>
  • Loading branch information
pengweisong and Sophie-Xie authored Dec 27, 2022
1 parent 45f5bfd commit 23dc0d0
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 119 deletions.
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

0 comments on commit 23dc0d0

Please sign in to comment.