了解备份逻辑前,先理解ob的几个执行线程以及线程入口:
1.root backup线程,ObRootBackup::run3
2.root balance线程,ObRootBalancer::run3
3.balance线程,ObRebalanceTaskMgr::run3
4.Dag调度线程,ObDagWorker::run1
由上而下执行过程
1/ 通过SQL指令执行alter system backup database
ALTER SYSTEM BACKUP DATABASE // SQL命令
-> ObCmdExecutor::execute // 执行器
-> ObBackupDatabaseExecutor::execute // 执行备份
-> common_proxy->backup_database // RPC call 调度到RS
2/ RS接收到RPC后,执行:
ObRootService::handle_backup_database
->ObBackupScheduler::start_schedule_backup
->ObBackupScheduler::schedule_backup
->ObBackupScheduler::start_backup
-> root_backup_->wakeup(); // 唤醒root_backup线程
3/ root backup线程被唤醒后,执行:
ObRootBackup::do_with_status
->ObRootBackup::do_scheduler
->ObRootBackup::do_backup
->ObRootBackup::do_tenant_backup
->ObTenantBackup::do_backup
->ObTenantBackup::do_generate
->root_balancer_->wakeup // 唤醒root_balance 线程
4/ root balance 被唤醒后,执行:
ObPartitionBackup::partition_backup // 执行backup
->ObPartitionBackup::backup_pg
->task_mgr_->add_task // 把task 加入到ObRebalanceTaskMgr调度队列
5/ balance 线程循环pop queue处理task
ObRebalanceTaskMgr::execute_task
-> task_executor_->execute
// 上面的task_executor_->execute 就是 下面的ObBackupTask::execute
ObBackupTask::execute
->rpc_proxy.to(dst_).backup_replica_batch
->ObRpcBackupReplicaBatchP::process
->ObService::backup_replica_batch
-> ObPartitionService::backup_replica_batch
->ObPartGroupMigrator::get_instance().schedule(task_list, arg.task_id_) // 将ObGroupMigrateExecuteTask加入Dag中
最终由Dag调度执行备份任务
ObDagWorker::run1
-> task_->do_work()
-> ObGroupMigrateExecuteTask::process()
-> group_task_->do_task() //执行具体的任务,此时执行的是ObPartGroupBackupTask::do_task()
当然上述过程涉及RS以及OBServer的状态机变迁以及许多细节过程,这点您自己研究下代码