avoid using task pointers outside the backup task queue.

This commit is contained in:
hamstersox
2023-02-09 18:19:00 +00:00
committed by ob-robot
parent 16428a2609
commit 7f1eeb45ee
2 changed files with 31 additions and 43 deletions

View File

@ -256,10 +256,11 @@ int ObBackupTaskSchedulerQueue::dump_statistics()
return ret; return ret;
} }
int ObBackupTaskSchedulerQueue::pop_task(ObBackupScheduleTask *&task) int ObBackupTaskSchedulerQueue::pop_task(ObBackupScheduleTask *&output_task, common::ObArenaAllocator &allocator)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
task = nullptr; ObBackupScheduleTask *task = nullptr;
output_task = nullptr;
ObArray<ObBackupZone> backup_zone; ObArray<ObBackupZone> backup_zone;
ObArray<ObBackupRegion> backup_region; ObArray<ObBackupRegion> backup_region;
ObArray<ObBackupServer> all_servers; ObArray<ObBackupServer> all_servers;
@ -356,6 +357,24 @@ int ObBackupTaskSchedulerQueue::pop_task(ObBackupScheduleTask *&task)
task = nullptr; task = nullptr;
} }
} }
if (OB_FAIL(ret) || OB_ISNULL(task)) {
} else {
void *raw_ptr = nullptr;
const int64_t task_deep_copy_size = task->get_deep_copy_size();
if (OB_ISNULL(raw_ptr = allocator.alloc(task_deep_copy_size))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("fail to allocate task", K(ret));
} else if (OB_FAIL(task->clone(raw_ptr, output_task))) {
LOG_WARN("fail to clone input task", K(ret));
} else if (OB_ISNULL(output_task)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("input task ptr is null", K(ret));
} else {
task->set_executor_time(ObTimeUtility::current_time());
}
raw_ptr = nullptr;
}
} }
return ret; return ret;
} }
@ -1234,36 +1253,19 @@ int ObBackupTaskScheduler::reload_task_(int64_t &last_reload_task_ts, bool &relo
int ObBackupTaskScheduler::pop_and_send_task_() int ObBackupTaskScheduler::pop_and_send_task_()
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
common::ObArenaAllocator allocator;
ObBackupScheduleTask *task = nullptr; ObBackupScheduleTask *task = nullptr;
if (OB_FAIL(pop_task_(task))) { if (OB_FAIL(queue_.pop_task(task, allocator))) {
LOG_WARN("pop task for execute failed", K(ret)); LOG_WARN("pop_task failed", K(ret));
} }
// execute task // execute task
if (OB_SUCC(ret) && nullptr != task) { if (OB_SUCC(ret) && nullptr != task) {
void *raw_ptr = nullptr; if (OB_FAIL(execute_task_(*task))) {
ObBackupScheduleTask *input_task = nullptr; LOG_WARN("send task to execute failed", K(ret), KPC(task));
common::ObArenaAllocator allocator;
const int64_t task_deep_copy_size = task->get_deep_copy_size();
if (nullptr == (raw_ptr = allocator.alloc(task_deep_copy_size))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("fail to allocate task", K(ret));
} else if (OB_FAIL(task->clone(raw_ptr, input_task))) {
LOG_WARN("fail to clone input task", K(ret));
} else if (nullptr == input_task) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("input task ptr is null", K(ret));
} else if (OB_FAIL(execute_task_(*input_task))) {
LOG_WARN("send task to execute failed", K(ret), KPC(input_task));
} else {
int64_t now = ObTimeUtility::current_time();
task->set_executor_time(now);
} }
if (nullptr != input_task) { if (nullptr != task) {
input_task->~ObBackupScheduleTask(); task->~ObBackupScheduleTask();
input_task = nullptr; task = nullptr;
}
if (nullptr != raw_ptr) {
raw_ptr = nullptr;
} }
} }
return ret; return ret;
@ -1401,18 +1403,6 @@ int ObBackupTaskScheduler::do_execute_(const ObBackupScheduleTask &task)
return ret; return ret;
} }
int ObBackupTaskScheduler::pop_task_(ObBackupScheduleTask *&task)
{
int ret = OB_SUCCESS;
task = nullptr;
if (OB_FAIL(queue_.pop_task(task))) {
LOG_WARN("pop_task failed", K(ret));
} else if (nullptr != task) {
LOG_INFO("pop_task succeed", KPC(task));
}
return ret;
}
int ObBackupTaskScheduler::add_task(const ObBackupScheduleTask &task) int ObBackupTaskScheduler::add_task(const ObBackupScheduleTask &task)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;

View File

@ -63,7 +63,7 @@ public:
// get one task from wait_list_, for per task choosing a server to execute, // get one task from wait_list_, for per task choosing a server to execute,
// then set to scheduler state and move to schedule_list; // then set to scheduler state and move to schedule_list;
// return OB_SUCCESS or assign NULL to task, if no task can be scheduled // return OB_SUCCESS or assign NULL to task, if no task can be scheduled
int pop_task(ObBackupScheduleTask *&task); int pop_task(ObBackupScheduleTask *&output_task, common::ObArenaAllocator &allocator);
int execute_over(const ObBackupScheduleTask &task, const int execute_ret); int execute_over(const ObBackupScheduleTask &task, const int execute_ret);
// remove task // remove task
// When finished, task memory will be released and %task can not be used again. // When finished, task memory will be released and %task can not be used again.
@ -184,8 +184,6 @@ public:
int reload_task_(int64_t &last_reload_task_ts, bool &reload_flag); int reload_task_(int64_t &last_reload_task_ts, bool &reload_flag);
share::schema::ObMultiVersionSchemaService &get_schema_service() { return *schema_service_; } share::schema::ObMultiVersionSchemaService &get_schema_service() { return *schema_service_; }
private: private:
// Return OB_SUCCESS or assign NULL to %task, if no task can be scheduled
int pop_task_(ObBackupScheduleTask *&task);
// Send task to execute. // Send task to execute.
int execute_task_(const ObBackupScheduleTask &task); int execute_task_(const ObBackupScheduleTask &task);
int do_execute_(const ObBackupScheduleTask &task); int do_execute_(const ObBackupScheduleTask &task);