From f51dd07dba8935d56823d026cd7bb36f4e426fb2 Mon Sep 17 00:00:00 2001 From: WenJinyu <596324105@qq.com> Date: Mon, 31 Jan 2022 15:02:00 +0800 Subject: [PATCH] delete backup clean redundant code --- .../ob_tenant_backup_data_clean_mgr.cpp | 430 ------- .../backup/ob_tenant_backup_data_clean_mgr.h | 28 - src/rootserver/ob_backup_data_clean.cpp | 1099 ++--------------- src/rootserver/ob_backup_data_clean.h | 67 - .../ob_backup_data_clean_scheduler.cpp | 201 --- .../ob_backup_data_clean_scheduler.h | 9 +- 6 files changed, 106 insertions(+), 1728 deletions(-) diff --git a/src/rootserver/backup/ob_tenant_backup_data_clean_mgr.cpp b/src/rootserver/backup/ob_tenant_backup_data_clean_mgr.cpp index 60eed64835..be2f8c9fae 100644 --- a/src/rootserver/backup/ob_tenant_backup_data_clean_mgr.cpp +++ b/src/rootserver/backup/ob_tenant_backup_data_clean_mgr.cpp @@ -158,33 +158,6 @@ bool ObBackupDataCleanElement::is_same_element( return cluster_id_ == cluster_id && incarnation_ == incarnation && backup_dest_ == backup_dest; } -int ObBackupDataCleanElement::set_backup_set_id(const ObBackupSetId &backup_set_id) -{ - int ret = OB_SUCCESS; - if (!is_valid()) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("can not set backup id", K(ret), K(*this)); - } else if (!backup_set_id.is_valid()) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("set backup set id get invalid argument", K(ret), K(backup_set_id)); - } else if (OB_FAIL(backup_set_id_array_.push_back(backup_set_id))) { - LOG_WARN("failed to set backup set id", K(ret), K(backup_set_id)); - } - return ret; -} - -int ObBackupDataCleanElement::set_log_archive_round(const ObLogArchiveRound &log_archive_round) -{ - int ret = OB_SUCCESS; - if (!log_archive_round.is_valid()) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("set log archive round get invalid argument", K(ret), K(log_archive_round)); - } else if (OB_FAIL(log_archive_round_array_.push_back(log_archive_round))) { - LOG_WARN("failed to set log archive round", K(ret), K(log_archive_round)); - } - return ret; -} - bool ObSimpleBackupDataCleanTenant::is_valid() const { return OB_INVALID_ID != tenant_id_; @@ -1089,31 +1062,6 @@ int ObTenantBackupBaseDataCleanTask::delete_backup_set_meta( return ret; } -int ObTenantBackupBaseDataCleanTask::get_table_id_list( - const storage::ObPhyRestoreMetaIndexStore::MetaIndexMap &meta_index_map, hash::ObHashSet &table_id_set) -{ - int ret = OB_SUCCESS; - const int overwrite_key = 1; - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("tenant backup base data clean task do not init", K(ret)); - } else { - storage::ObPhyRestoreMetaIndexStore::MetaIndexMap::const_iterator iter; - for (iter = meta_index_map.begin(); OB_SUCC(ret) && iter != meta_index_map.end(); ++iter) { - const ObMetaIndexKey &meta_index_key = iter->first; - const int64_t table_id = meta_index_key.table_id_; - if (OB_FAIL(data_clean_->check_can_do_task())) { - LOG_WARN("failed to check can do task", K(ret)); - } else if (ObBackupMetaType::PARTITION_GROUP_META != meta_index_key.meta_type_) { - // do nothing - } else if (OB_FAIL(table_id_set.set_refactored_1(table_id, overwrite_key))) { - LOG_WARN("failed to set table id into set", K(ret), K(table_id)); - } - } - } - return ret; -} - int ObTenantBackupBaseDataCleanTask::try_clean_backup_set_dir(const uint64_t tenant_id, const ObBackupDataCleanElement &clean_element, const ObBackupSetId &backup_set_id, const ObExternBackupInfo &extern_backup_info) @@ -1409,350 +1357,6 @@ int ObTenantBackupClogDataCleanTask::do_inner_clean(const ObSimpleBackupDataClea return ret; } -/*delete it later*/ -int ObTenantBackupClogDataCleanTask::do_inner_clean(const ObSimpleBackupDataCleanTenant &simple_clean_tenant, - const ObBackupDataCleanElement &clean_element, const ObTenantBackupTaskInfo &clog_data_clean_point) -{ - int ret = OB_SUCCESS; - // const uint64_t tenant_id = simple_clean_tenant.tenant_id_; - // const int64_t full_backup_set_id = clog_data_clean_point.backup_set_id_; - // const int64_t inc_backup_set_id = clog_data_clean_point.backup_set_id_; - ObBackupDataMgr backup_data_mgr; - ObClusterBackupDest cluster_backup_dest; - ObArray table_id_array; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("tenant backup clog data clean task do not init", K(ret)); - } else if (!simple_clean_tenant.is_valid() || !clean_element.is_valid()) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("inner do clean get invalid argument", K(ret), K(simple_clean_tenant), K(clean_element)); - } else if (!clog_data_clean_point.is_valid()) { - // do nothing - } else if (OB_FAIL(cluster_backup_dest.set(clog_data_clean_point.backup_dest_, clog_data_clean_point.incarnation_))) { - LOG_WARN("failed to set cluster backup destt", K(ret), K(clean_element)); - //} else if (OB_FAIL(backup_data_mgr.init(cluster_backup_dest, - // tenant_id, full_backup_set_id, inc_backup_set_id))) { - // LOG_WARN("failed to init backup data mgr", K(ret), K(cluster_backup_dest), - // K(full_backup_set_id), K(inc_backup_set_id)); - } else if (OB_FAIL(backup_data_mgr.get_base_data_table_id_list(table_id_array))) { - LOG_WARN("failed ot get base data table id list", K(ret)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < clean_element.log_archive_round_array_.count(); ++i) { - const ObLogArchiveRound &log_archive_round = clean_element.log_archive_round_array_.at(i); - if (OB_FAIL(data_clean_->check_can_do_task())) { - LOG_WARN("failed to check can do task", K(ret)); - } else if (ObLogArchiveStatus::STOP == log_archive_round.log_archive_status_) { - if (log_archive_round.start_ts_ > clog_data_clean_point.snapshot_version_ || - log_archive_round.checkpoint_ts_ > clog_data_clean_point.snapshot_version_) { - // clean set - if (OB_FAIL(clean_clog_data(simple_clean_tenant, - clean_element, - clog_data_clean_point, - log_archive_round, - table_id_array, - backup_data_mgr))) { - LOG_WARN("failed to clean clog data", K(ret), K(simple_clean_tenant), K(clog_data_clean_point)); - } - } else { - // log_archive_status.start_ts <= snapshot_version && - // log_archive_status.check_point_ts <= snapshot_version - // clean clog archive round directly - if (OB_FAIL(clean_interrputed_clog_data(simple_clean_tenant, clean_element, log_archive_round))) { - LOG_WARN("failed to clean interrputed clog data", K(ret), K(simple_clean_tenant)); - } - } - } else { - // clean set - if (OB_FAIL(clean_clog_data(simple_clean_tenant, - clean_element, - clog_data_clean_point, - log_archive_round, - table_id_array, - backup_data_mgr))) { - LOG_WARN("failed to clean clog data", K(ret), K(simple_clean_tenant), K(clog_data_clean_point)); - } - } - } - } - return ret; -} - -/*delete it later*/ -int ObTenantBackupClogDataCleanTask::clean_clog_data(const ObSimpleBackupDataCleanTenant &simple_clean_tenant, - const ObBackupDataCleanElement &clean_element, const ObTenantBackupTaskInfo &clog_data_clean_point, - const ObLogArchiveRound &log_archive_round, const common::ObIArray &table_id_array, - ObBackupDataMgr &backup_data_mgr) -{ - int ret = OB_SUCCESS; - ObArray meta_index_array; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("tenant backup clog data clean task do not init", K(ret)); - } else if (!simple_clean_tenant.is_valid() || !clean_element.is_valid() || !log_archive_round.is_valid()) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN( - "clean clog data get invalid argument", K(ret), K(simple_clean_tenant), K(clean_element), K(log_archive_round)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < table_id_array.count(); ++i) { - meta_index_array.reset(); - const int64_t table_id = table_id_array.at(i); - ObTableClogDataCleanMgr table_clog_data_clean_mgr; - ObBackupDataCleanStatics clean_statics; - if (OB_FAIL(data_clean_->check_can_do_task())) { - LOG_WARN("failed to check can do task", K(ret)); - } else if (OB_FAIL(backup_data_mgr.get_table_pg_meta_index(table_id, meta_index_array))) { - LOG_WARN("failed to get table meta index", K(ret), K(table_id)); - } else if (OB_FAIL(table_clog_data_clean_mgr.init(table_id, - clean_element, - log_archive_round, - clog_data_clean_point, - meta_index_array, - *data_clean_))) { - LOG_WARN("failed to init table data clean mgr", K(ret)); - } else if (OB_FAIL(table_clog_data_clean_mgr.do_clean())) { - LOG_WARN("failed to do table data clean", K(ret)); - } else if (OB_FAIL(set_partition_into_set(meta_index_array))) { - LOG_WARN("failed to set partition into set", K(ret)); - } else if (OB_FAIL(table_clog_data_clean_mgr.get_clean_statics(clean_statics))) { - LOG_WARN("failed to get table clgo data clean statics", K(ret)); - } else { - clean_statics_ += clean_statics; - LOG_INFO("table clog data clean statis", K(table_id), K(log_archive_round), K(clean_statics)); - } - } - } - return ret; -} - -/*delete it later*/ -int ObTenantBackupClogDataCleanTask::set_partition_into_set(const ObIArray &meta_index_array) -{ - int ret = OB_SUCCESS; - if (!is_inited_) { - LOG_WARN("tenant backup clog data clean mgr do not init", K(ret)); - } else { - const int flag = 1; - for (int64_t i = 0; OB_SUCC(ret) && i < meta_index_array.count(); ++i) { - const ObBackupMetaIndex &meta_index = meta_index_array.at(i); - const int64_t table_id = meta_index.table_id_; - const int64_t partition_id = meta_index.partition_id_; - ObPartitionKey pkey(table_id, partition_id, 0); - if (OB_FAIL(pkey_set_.set_refactored_1(pkey, flag))) { - LOG_WARN("failed to set pkey into set", K(ret), K(pkey)); - } - } - } - return ret; -} - -/*delete it later*/ -int ObTenantBackupClogDataCleanTask::check_and_delete_clog_data( - const ObSimpleBackupDataCleanTenant &simple_clean_tenant, const ObBackupDataCleanElement &backup_clean_element, - const int64_t clog_gc_snapshot) -{ - int ret = OB_SUCCESS; - const ObBackupDest &backup_dest = backup_clean_element.backup_dest_; - const int64_t incarnation = backup_clean_element.incarnation_; - ObClusterBackupDest cluster_backup_dest; - ObBackupListDataMgr backup_list_data_mgr; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("tenant backup data clean mgr do not init", K(ret)); - } else if (OB_FAIL(cluster_backup_dest.set(backup_dest, incarnation))) { - LOG_WARN("failed to set cluster backup dest", K(ret), K(backup_dest)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < backup_clean_element.log_archive_round_array_.count(); ++i) { - const ObLogArchiveRound &log_archive_round = backup_clean_element.log_archive_round_array_.at(i); - if (OB_FAIL(data_clean_->check_can_do_task())) { - LOG_WARN("failed to check can do task", K(ret)); - } else if (OB_FAIL(check_and_delete_clog_data_with_round( - simple_clean_tenant, cluster_backup_dest, log_archive_round, clog_gc_snapshot))) { - LOG_WARN("failed to check and delete clog data with round", K(ret), K(log_archive_round)); - } - } - } - return ret; -} - -/*delete it later*/ -int ObTenantBackupClogDataCleanTask::check_and_delete_clog_data_with_round( - const ObSimpleBackupDataCleanTenant &simple_clean_tenant, const ObClusterBackupDest &cluster_backup_dest, - const ObLogArchiveRound &log_archive_round, const int64_t max_clean_clog_snapshot) -{ - int ret = OB_SUCCESS; - ObArray pkey_list; - const int64_t archive_round = log_archive_round.log_archive_round_; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("failed ot check and delete clog data with round", K(ret), K(simple_clean_tenant)); - } else if (OB_FAIL(get_clog_pkey_list_not_in_base_data(cluster_backup_dest, - log_archive_round.log_archive_round_, - simple_clean_tenant.tenant_id_, - pkey_list))) { - LOG_WARN("failed to get clog pkey list not in base data", K(ret), K(cluster_backup_dest), K(log_archive_round)); - } else { - // TODO(muwei) - const int64_t fake_piece_id = 0; - const int64_t fake_piece_create_date = 0; - ObSimplePieceInfo fake_backup_piece_info; - for (int64_t i = 0; OB_SUCC(ret) && i < pkey_list.count(); ++i) { - const ObPartitionKey &pkey = pkey_list.at(i); - ObPartitionClogDataCleanMgr clog_data_clean_mgr; - archive::ObArchiveClear archive_clear; - uint64_t data_file_id = 0; - uint64_t index_file_id = 0; - const int64_t unused_retention_timestamp = INT64_MAX; - const bool is_backup_backup = false; - if (OB_FAIL(data_clean_->check_can_do_task())) { - LOG_WARN("failed to check can do task", K(ret)); - } else if (OB_FAIL(archive_clear.get_clean_max_clog_file_id_by_log_ts(cluster_backup_dest, - archive_round, - fake_piece_id, - fake_piece_create_date, - pkey, - max_clean_clog_snapshot, - unused_retention_timestamp, - index_file_id, - data_file_id))) { - LOG_WARN("failed to get clean max clog file id by log ts", - K(ret), - K(pkey), - K(log_archive_round), - K(max_clean_clog_snapshot)); - } else if (OB_FAIL(clog_data_clean_mgr.init(cluster_backup_dest, - fake_backup_piece_info, - pkey, - data_file_id, - index_file_id, - is_backup_backup, - *data_clean_))) { - LOG_WARN("failed to init clog data clean mgr", K(ret), K(cluster_backup_dest), K(log_archive_round), K(pkey)); - } else if (OB_FAIL(clog_data_clean_mgr.touch_clog_backup_data())) { - LOG_WARN("failed to touch clog backup data", K(ret), K(pkey), K(cluster_backup_dest)); - } else if (OB_FAIL(clog_data_clean_mgr.clean_clog_backup_data())) { - LOG_WARN("failed to clean clog backup data", K(ret), K(pkey), K(cluster_backup_dest)); - } else { - LOG_INFO("check and delete clog data", K(pkey), K(log_archive_round)); - } - } - } - return ret; -} - -/*delete it later*/ -int ObTenantBackupClogDataCleanTask::get_clog_pkey_list_not_in_base_data(const ObClusterBackupDest &cluster_backup_dest, - const int64_t log_archive_round, const uint64_t tenant_id, common::ObIArray &pkey_list) -{ - int ret = OB_SUCCESS; - ObBackupListDataMgr backup_list_data_mgr; - ObArray clog_pkey_list; - UNUSED(cluster_backup_dest); - UNUSED(log_archive_round); - UNUSED(tenant_id); - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("tenant backup data clean mgr do not init", K(ret)); - //} else if (OB_FAIL(backup_list_data_mgr.init( - // cluster_backup_dest, log_archive_round, tenant_id))) { - // LOG_WARN("failed to init backup list data mgr", K(ret), - // K(cluster_backup_dest), K(log_archive_round)); - } else if (OB_FAIL(backup_list_data_mgr.get_clog_pkey_list(clog_pkey_list))) { - LOG_WARN("failed to get clog pkey list", K(ret)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < clog_pkey_list.count(); ++i) { - const ObPartitionKey &pkey = clog_pkey_list.at(i); - int hash_ret = pkey_set_.exist_refactored(pkey); - if (OB_HASH_NOT_EXIST == hash_ret) { - if (OB_FAIL(pkey_list.push_back(pkey))) { - LOG_WARN("failed to push pkey into list", K(ret), K(pkey)); - } - } else if (OB_HASH_EXIST == hash_ret) { - // do nothing - } else { - ret = OB_SUCCESS == hash_ret ? OB_ERR_UNEXPECTED : hash_ret; - LOG_WARN("failed to check exist from set", K(ret), K(pkey)); - } - } - } - return ret; -} - -/*delete it later*/ -int ObTenantBackupClogDataCleanTask::clean_interrputed_clog_data( - const ObSimpleBackupDataCleanTenant &simple_clean_tenant, const ObBackupDataCleanElement &clean_element, - const ObLogArchiveRound &log_archive_round) -{ - int ret = OB_SUCCESS; - const uint64_t tenant_id = simple_clean_tenant.tenant_id_; - const int64_t round = log_archive_round.log_archive_round_; - const char *storage_info = clean_element.backup_dest_.storage_info_; - const ObStorageType &storage_type = clean_element.backup_dest_.device_type_; - ObClusterBackupDest cluster_backup_dest; - ObBackupListDataMgr backup_list_data_mgr; - ObArray clog_pkey_list; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("tenant backup data clean mgr do not init", K(ret)); - } else if (ObLogArchiveStatus::STOP != log_archive_round.log_archive_status_) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("clean interrputed clog data get invalid argument", K(ret), K(log_archive_round)); - } else if (data_clean_->is_update_reserved_backup_timestamp()) { - LOG_INFO("update reserved backup timestamp, skip clean interrputed clog data", K(log_archive_round)); - } else if (OB_FAIL(cluster_backup_dest.set(clean_element.backup_dest_, clean_element.incarnation_))) { - LOG_WARN("failed to set cluster backup dest", K(ret), K(clean_element)); - // } else if (OB_FAIL(backup_list_data_mgr.init( - // cluster_backup_dest, round, tenant_id))) { - // LOG_WARN("failed to init backup list data mgr", K(ret), - // K(cluster_backup_dest), K(log_archive_round)); - } else if (OB_FAIL(backup_list_data_mgr.get_clog_pkey_list(clog_pkey_list))) { - LOG_WARN("failed to get clog pkey list", K(ret), K(cluster_backup_dest)); - } else { - LOG_INFO("start clean interruped clog data", K(clean_element), K(log_archive_round)); - const uint64_t data_file_id = UINT64_MAX; - const uint64_t index_file_id = UINT64_MAX; - ObSimplePieceInfo fake_backup_piece_info; - const bool is_backup_backup = false; - - for (int64_t i = 0; OB_SUCC(ret) && i < clog_pkey_list.count(); ++i) { - const ObPartitionKey &pkey = clog_pkey_list.at(i); - ObPartitionClogDataCleanMgr partition_clog_data_clean_mgr; - ObBackupDataCleanStatics clean_statics; - if (OB_FAIL(data_clean_->check_can_do_task())) { - LOG_WARN("failed to check can do task", K(ret)); - } else if (OB_FAIL(partition_clog_data_clean_mgr.init(cluster_backup_dest, - fake_backup_piece_info, - pkey, - data_file_id, - index_file_id, - is_backup_backup, - *data_clean_))) { - LOG_WARN("failed to init partition clog data clean mgr", K(ret), K(pkey), K(cluster_backup_dest)); - } else if (OB_FAIL(partition_clog_data_clean_mgr.clean_clog_backup_data())) { - LOG_WARN("failed to clean clog backup data", K(ret), K(pkey)); - } else if (OB_FAIL(try_clean_table_clog_data_dir( - cluster_backup_dest, tenant_id, round, pkey.get_table_id(), storage_info, storage_type))) { - LOG_WARN("failed to try clean clog data dir", K(ret), K(pkey)); - } else if (OB_FAIL(partition_clog_data_clean_mgr.get_clean_statics(clean_statics))) { - LOG_WARN("failed to get partition clog data clean statics", K(ret)); - } else { - clean_statics_ += clean_statics; - } - } - - if (OB_SUCC(ret)) { - if (OB_FAIL(try_clean_clog_data_dir(cluster_backup_dest, tenant_id, round, storage_info, storage_type))) { - LOG_WARN("failed to try clean clog data dir", K(ret), K(cluster_backup_dest)); - } - } - } - return ret; -} - int ObTenantBackupClogDataCleanTask::try_clean_table_clog_data_dir(const ObClusterBackupDest &cluster_backup_dest, const uint64_t tenant_id, const int64_t log_archive_round, const int64_t table_id, const char *storage_info, const common::ObStorageType &device_type) @@ -1784,40 +1388,6 @@ int ObTenantBackupClogDataCleanTask::try_clean_table_clog_data_dir(const ObClust return ret; } -int ObTenantBackupClogDataCleanTask::try_clean_clog_data_dir(const ObClusterBackupDest &cluster_backup_dest, - const uint64_t tenant_id, const int64_t log_archive_round, const char *storage_info, - const common::ObStorageType &device_type) -{ - int ret = OB_SUCCESS; - ObBackupPath path; - // TODO(muwei) - const int64_t fake_piece_id = 0; - const int64_t fake_piece_create_date = 0; - - if (!cluster_backup_dest.is_valid() || log_archive_round <= 0 || OB_ISNULL(storage_info)) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("try clean clog data dir get invlaid argument", K(ret), K(cluster_backup_dest), KP(storage_info)); - } else if (OB_FAIL(ObBackupPathUtil::get_tenant_clog_data_path( - cluster_backup_dest, tenant_id, log_archive_round, fake_piece_id, fake_piece_create_date, path))) { - LOG_WARN("fail to get meta file path", K(ret)); - } else if (OB_FAIL(ObBackupDataCleanUtil::delete_backup_dir(path, storage_info, device_type))) { - LOG_WARN("failed to delete backup dir", K(ret), K(storage_info), K(device_type)); - } else if (FALSE_IT(path.reset())) { - } else if (OB_FAIL(ObBackupPathUtil::get_tenant_clog_index_path( - cluster_backup_dest, tenant_id, log_archive_round, fake_piece_id, fake_piece_create_date, path))) { - LOG_WARN("fail to get meta file path", K(ret)); - } else if (OB_FAIL(ObBackupDataCleanUtil::delete_backup_dir(path, storage_info, device_type))) { - LOG_WARN("failed to delete backup dir", K(ret), K(storage_info), K(device_type)); - } else if (FALSE_IT(path.reset())) { - } else if (OB_FAIL(ObBackupPathUtil::get_cluster_clog_prefix_path( - cluster_backup_dest, tenant_id, log_archive_round, fake_piece_id, fake_piece_create_date, path))) { - LOG_WARN("failed to get cluster clog prefix path", K(ret), K(cluster_backup_dest)); - } else if (OB_FAIL(ObBackupDataCleanUtil::delete_backup_dir(path, storage_info, device_type))) { - LOG_WARN("failed to delete backup dir", K(ret), K(storage_info), K(device_type)); - } - return ret; -} - int ObTenantBackupClogDataCleanTask::get_clean_statics(ObBackupDataCleanStatics &clean_statics) { int ret = OB_SUCCESS; diff --git a/src/rootserver/backup/ob_tenant_backup_data_clean_mgr.h b/src/rootserver/backup/ob_tenant_backup_data_clean_mgr.h index 067d26650c..984331bab4 100644 --- a/src/rootserver/backup/ob_tenant_backup_data_clean_mgr.h +++ b/src/rootserver/backup/ob_tenant_backup_data_clean_mgr.h @@ -107,8 +107,6 @@ struct ObBackupDataCleanElement { void reset(); bool is_same_element( const int64_t cluster_id, const int64_t incarnation, const share::ObBackupDest &backup_dest) const; - int set_backup_set_id(const ObBackupSetId &backup_set_id); - int set_log_archive_round(const ObLogArchiveRound &log_archive_round); TO_STRING_KV(K_(cluster_id), K_(incarnation), K_(backup_dest), K_(backup_set_id_array), K_(log_archive_round_array), K_(backup_dest_option)); @@ -295,8 +293,6 @@ private: const ObExternBackupInfo &extern_backup_info); int touch_backup_set_meta(const ObBackupDataCleanElement &clean_element, const ObBackupPath &path); int delete_backup_set_meta(const ObBackupDataCleanElement &clean_element, const ObBackupPath &path); - int get_table_id_list( - const storage::ObPhyRestoreMetaIndexStore::MetaIndexMap &index_map, hash::ObHashSet &table_id_set); // clean backup set int try_clean_backup_set_dir(const uint64_t tenant_id, const ObBackupDataCleanElement &clean_element, @@ -333,30 +329,6 @@ public: private: int do_inner_clean(const ObSimpleBackupDataCleanTenant &simple_clean_tenant, const ObBackupDataCleanElement &clean_element, const int64_t start_replay_log_ts); - // TODO(muwei.ym) delete later - // do_inner_clean ~ try_clean_clog_data_dir - int do_inner_clean(const ObSimpleBackupDataCleanTenant &simple_clean_tenant, - const ObBackupDataCleanElement &clean_element, const ObTenantBackupTaskInfo &clog_data_clean_point); - int clean_clog_data(const ObSimpleBackupDataCleanTenant &simple_clean_tenant, - const ObBackupDataCleanElement &clean_element, const ObTenantBackupTaskInfo &clog_data_clean_point, - const ObLogArchiveRound &log_archive_round, const common::ObIArray &table_id_array, - ObBackupDataMgr &backup_data_mgr); - int do_clean_table_clog_data(const ObSimpleBackupDataCleanTenant &simple_clean_tenant, - const ObBackupDataCleanElement &clean_element, const ObTenantBackupTaskInfo &clog_data_clean_point, - const ObLogArchiveRound &log_archive_round, const common::ObIArray &table_id, - ObBackupDataMgr &backup_data_mgr); - int set_partition_into_set(const common::ObIArray &meta_index_array); - int check_and_delete_clog_data(const ObSimpleBackupDataCleanTenant &simple_clean_tenant, - const ObBackupDataCleanElement &backup_clean_element, const int64_t clog_gc_snapshot); - int check_and_delete_clog_data_with_round(const ObSimpleBackupDataCleanTenant &simple_clean_tenant, - const ObClusterBackupDest &cluster_backup_dest, const ObLogArchiveRound &log_archive_round, - const int64_t max_clean_clog_snapshot); - int get_clog_pkey_list_not_in_base_data(const ObClusterBackupDest &cluster_backup_dest, - const int64_t log_archive_round, const uint64_t tenant_id, common::ObIArray &pkey_list); - int clean_interrputed_clog_data(const ObSimpleBackupDataCleanTenant &simple_clean_tenant, - const ObBackupDataCleanElement &clean_element, const ObLogArchiveRound &log_archive_round); - int try_clean_clog_data_dir(const ObClusterBackupDest &cluster_backup_dest, const uint64_t tenant_id, - const int64_t log_archive_round, const char *storage_info, const common::ObStorageType &device_type); int generate_backup_piece_tasks(const ObSimpleBackupDataCleanTenant &simple_clean_tenant, const ObBackupDataCleanElement &clean_element, const ObLogArchiveRound &log_archive_round, const int64_t start_replay_log_ts); diff --git a/src/rootserver/ob_backup_data_clean.cpp b/src/rootserver/ob_backup_data_clean.cpp index b87e1bdd59..0c77d2926b 100644 --- a/src/rootserver/ob_backup_data_clean.cpp +++ b/src/rootserver/ob_backup_data_clean.cpp @@ -438,56 +438,6 @@ int ObBackupDataClean::get_server_need_clean_info(const uint64_t tenant_id, bool return ret; } -int ObBackupDataClean::get_tenant_backup_task_his_info(const share::ObBackupCleanInfo &clean_info, - common::ObISQLClient &trans, common::ObIArray &tenant_infos) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (!clean_info.is_valid()) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("get tenant backup task his info get invalid argument", K(ret), K(clean_info)); - } else { - if (clean_info.is_clean_copy()) { - ObArray backup_backupset_tasks; - if (OB_FAIL(get_tenant_backup_backupset_task_his_info(clean_info, trans, backup_backupset_tasks))) { - LOG_WARN("failed to get tenant backup backupset task history info", KR(ret), K(clean_info)); - } else if (OB_FAIL(convert_backup_backupset_task_to_backup_task(backup_backupset_tasks, tenant_infos))) { - LOG_WARN("failed to convert tasks", KR(ret), K(backup_backupset_tasks), K(tenant_infos)); - } - } else { - if (OB_FAIL(inner_get_tenant_backup_task_his_info(clean_info, trans, tenant_infos))) { - LOG_WARN("failed to inner get tenant backup task history info", KR(ret), K(clean_info)); - } - } - } - return ret; -} - -int ObBackupDataClean::inner_get_tenant_backup_task_his_info(const ObBackupCleanInfo &clean_info, - common::ObISQLClient &trans, common::ObIArray &tenant_infos) -{ - int ret = OB_SUCCESS; - tenant_infos.reset(); - ObBackupTaskHistoryUpdater updater; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (!clean_info.is_valid()) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("get tenant backup task his info get invalid argument", K(ret), K(clean_info)); - } else if (OB_FAIL(updater.init(trans))) { - LOG_WARN("failed to init backup task history updater", K(ret)); - } else if (OB_FAIL(updater.get_tenant_full_backup_tasks(clean_info.tenant_id_, tenant_infos))) { - LOG_WARN("failed to get tenant backup tasks", K(ret), K(clean_info)); - } else { - LOG_INFO("succeed get tenant backup task his info", K(tenant_infos)); - } - return ret; -} - int ObBackupDataClean::get_tenant_backup_task_info(const share::ObBackupCleanInfo &clean_info, common::ObISQLClient &trans, common::ObIArray &tenant_infos) { @@ -518,269 +468,6 @@ int ObBackupDataClean::get_tenant_backup_task_info(const share::ObBackupCleanInf return ret; } -int ObBackupDataClean::get_tenant_backup_backupset_task_his_info(const share::ObBackupCleanInfo &clean_info, - common::ObISQLClient &trans, common::ObIArray &tenant_infos) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (!clean_info.is_valid()) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("get tenant backup task his info get invalid argument", K(ret), K(clean_info)); - } else if (OB_FAIL(ObTenantBackupBackupsetHistoryOperator::get_full_task_items( - clean_info.tenant_id_, clean_info.copy_id_, tenant_infos, trans))) { - LOG_WARN("failed to get full backupset task items", KR(ret), K(clean_info)); - } - return ret; -} - -int ObBackupDataClean::convert_backup_backupset_task_to_backup_task( - const common::ObIArray &backup_backupset_tasks, - common::ObIArray &backup_tasks) -{ - int ret = OB_SUCCESS; - backup_tasks.reset(); - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < backup_backupset_tasks.count(); ++i) { - ObTenantBackupTaskInfo info; - const ObTenantBackupBackupsetTaskInfo &bb_info = backup_backupset_tasks.at(i); - if (OB_FAIL(bb_info.convert_to_backup_task_info(info))) { - LOG_WARN("failed to convert to backup task info", KR(ret), K(bb_info)); - } else if (OB_FAIL(backup_tasks.push_back(info))) { - LOG_WARN("failed to push back backup info", KR(ret), K(info)); - } - } - } - return ret; -} - -/*not use anymore*/ -int ObBackupDataClean::get_log_archive_info(const int64_t copy_id, const uint64_t tenant_id, - common::ObISQLClient &trans, common::ObIArray &log_archive_infos) -{ - int ret = OB_SUCCESS; - ObLogArchiveBackupInfoMgr mgr; - const bool for_update = false; - ObLogArchiveBackupInfo log_archive_info; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (OB_INVALID_ID == tenant_id || copy_id < 0) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("log archive info get invalid argument", K(ret), K(tenant_id), K(copy_id)); - } else if (copy_id > 0 && OB_FAIL(mgr.set_backup_backup())) { - LOG_WARN("failed to set copy id", K(ret), K(copy_id)); - } else if (OB_FAIL(mgr.get_log_archive_backup_info( - trans, for_update, tenant_id, inner_table_version_, log_archive_info))) { - LOG_WARN("failed to get log archive backup info", K(ret), K(tenant_id)); - } else if (ObLogArchiveStatus::DOING != log_archive_info.status_.status_ && - ObLogArchiveStatus::INTERRUPTED != log_archive_info.status_.status_) { - // do nothing - } else if (OB_FAIL(log_archive_infos.push_back(log_archive_info))) { - LOG_WARN("failed to push log archive info into array", K(ret), K(log_archive_info)); - } - return ret; -} - -/*not use anymore*/ -int ObBackupDataClean::get_log_archive_history_info(const int64_t copy_id, const uint64_t tenant_id, - common::ObISQLClient &trans, common::ObIArray &log_archive_infos) -{ - int ret = OB_SUCCESS; - ObLogArchiveBackupInfoMgr mgr; - const bool for_update = false; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (OB_INVALID_ID == tenant_id || copy_id < 0) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("log archive info get invalid argument", K(ret), K(copy_id), K(tenant_id)); - } else if (OB_FAIL(mgr.set_backup_backup())) { - LOG_WARN("failed to set copy id", K(ret), K(copy_id)); - } else if (OB_FAIL(mgr.get_log_archive_history_infos(trans, tenant_id, for_update, log_archive_infos))) { - LOG_WARN("failed to get log archive history infos", K(ret), K(tenant_id)); - } - return ret; -} - -/*not use anymore*/ -int ObBackupDataClean::get_extern_clean_tenants( - hash::ObHashMap &clean_tenants_map) -{ - int ret = OB_SUCCESS; - ObBackupCleanInfo sys_clean_info; - ObArray task_infos; - ObArray log_archive_infos; - hash::ObHashSet backup_dest_set; - ObSimpleBackupDataCleanTenant simple_clean_tenant; - simple_clean_tenant.tenant_id_ = OB_SYS_TENANT_ID; - simple_clean_tenant.is_deleted_ = false; - const bool for_update = false; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean not init", K(ret)); - } else if (OB_FAIL(backup_dest_set.create(MAX_BUCKET_NUM))) { - LOG_WARN("failed to create backup dest set", K(ret)); - } else { - sys_clean_info.tenant_id_ = OB_SYS_TENANT_ID; - if (OB_FAIL(get_backup_clean_info(OB_SYS_TENANT_ID, for_update, *sql_proxy_, sys_clean_info))) { - if (OB_BACKUP_CLEAN_INFO_NOT_EXIST == ret) { - ret = OB_SUCCESS; - } else { - LOG_WARN("failed to get backup clean info", K(ret)); - } - } else if (ObBackupCleanInfoStatus::STOP == sys_clean_info.status_) { - // do nothing - } else if (OB_FAIL(get_all_tenant_backup_infos( - sys_clean_info, simple_clean_tenant, *sql_proxy_, task_infos, log_archive_infos))) { - LOG_WARN("failed to get all tenant backup infos", K(ret), K(sys_clean_info)); - } - - // get tenant info from log archive info - for (int64_t i = 0; OB_SUCC(ret) && i < log_archive_infos.count(); ++i) { - const ObLogArchiveBackupInfo &info = log_archive_infos.at(i); - ObBackupDest backup_dest; - if (OB_FAIL(backup_dest.set(info.backup_dest_))) { - LOG_WARN("failed to set backup dest", K(ret), K(info)); - } else { - int hash_ret = backup_dest_set.exist_refactored(backup_dest); - if (OB_HASH_EXIST == hash_ret) { - // do nothing - } else if (OB_HASH_NOT_EXIST == hash_ret) { - if (OB_FAIL(get_archive_clean_tenant(info, clean_tenants_map))) { - LOG_WARN("failed to get archive clean tenant", K(ret), K(info)); - } else if (OB_FAIL(backup_dest_set.set_refactored(backup_dest))) { - LOG_WARN("failed to set backup dest", K(ret), K(info)); - } - } else { - ret = OB_SUCCESS != hash_ret ? hash_ret : OB_ERR_UNEXPECTED; - LOG_WARN("failed to check exist from hash set", K(ret), K(backup_dest_set)); - } - } - } - - // get tenant info from backup tenant info - backup_dest_set.reuse(); - - for (int64_t i = 0; OB_SUCC(ret) && i < task_infos.count(); ++i) { - const ObTenantBackupTaskInfo &task_info = task_infos.at(i); - int hash_ret = backup_dest_set.exist_refactored(task_info.backup_dest_); - if (OB_HASH_EXIST == hash_ret) { - // do nothing - } else if (OB_HASH_NOT_EXIST == hash_ret) { - if (OB_FAIL(get_backup_clean_tenant(task_info, clean_tenants_map))) { - LOG_WARN("failed to get extern clean tenant", K(ret), K(task_info)); - } else if (OB_FAIL(backup_dest_set.set_refactored(task_info.backup_dest_))) { - LOG_WARN("failed to set backup dest", K(ret), K(task_info)); - } - } else { - ret = hash_ret != OB_SUCCESS ? hash_ret : OB_ERR_UNEXPECTED; - LOG_WARN("can not check exist from hash set", K(ret)); - } - } - } - return ret; -} - -int ObBackupDataClean::get_archive_clean_tenant(const share::ObLogArchiveBackupInfo &log_archive_info, - hash::ObHashMap &clean_tenants_map) -{ - int ret = OB_SUCCESS; - ObTenantNameSimpleMgr tenant_name_mgr; - hash::ObHashSet tenant_id_set; - ObClusterBackupDest dest; - // TODO() cluster dest - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean not init", K(ret)); - } else if (!log_archive_info.is_valid()) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("get archive clean tenant get invalid argument", K(ret), K(log_archive_info)); - } else if (OB_FAIL(tenant_id_set.create(MAX_BUCKET_NUM))) { - LOG_WARN("failed to create tenant id set", K(ret), K(log_archive_info)); - } else if (OB_FAIL(dest.set(log_archive_info.backup_dest_, - GCONF.cluster, - GCONF.cluster_id, - log_archive_info.status_.incarnation_))) { - LOG_WARN("failed to set backup dest", K(ret), K(log_archive_info)); - } else if (OB_FAIL(tenant_name_mgr.init())) { - LOG_WARN("faiuiled to init tenant_name mgr", K(ret)); - } else if (OB_FAIL(tenant_name_mgr.read_backup_file(dest))) { - LOG_WARN("failed to read backup tenant name mgr", K(ret), K(dest)); - } else if (OB_FAIL(tenant_name_mgr.get_tenant_ids(tenant_id_set))) { - if (OB_BACKUP_FILE_NOT_EXIST != ret) { - LOG_WARN("failed to get tenant ids", K(ret), K(log_archive_info)); - } - } else { - for (hash::ObHashSet::iterator iter = tenant_id_set.begin(); OB_SUCC(ret) && iter != tenant_id_set.end(); - ++iter) { - ObSimpleBackupDataCleanTenant simple_clean_tenant; - simple_clean_tenant.tenant_id_ = iter->first; - simple_clean_tenant.is_deleted_ = true; - int hash_ret = clean_tenants_map.set_refactored(simple_clean_tenant.tenant_id_, simple_clean_tenant); - if (OB_SUCCESS == hash_ret) { - // do nothing - } else if (OB_HASH_EXIST == hash_ret) { - ret = OB_SUCCESS; - } else { - ret = hash_ret; - LOG_WARN("failed to set simple clean tenant info set", K(ret), K(simple_clean_tenant), K(log_archive_info)); - } - } - } - - return ret; -} - -int ObBackupDataClean::get_backup_clean_tenant(const share::ObTenantBackupTaskInfo &task_info, - hash::ObHashMap &clean_tenants_map) -{ - int ret = OB_SUCCESS; - ObExternTenantInfoMgr tenant_info_mgr; - ObClusterBackupDest backup_dest; - char backup_dest_str[share::OB_MAX_BACKUP_DEST_LENGTH] = ""; - ObArray extern_tenant_infos; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean not init", K(ret)); - } else if (!task_info.is_valid()) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("get extern clean tenant get invalid argument", K(ret), K(task_info)); - } else if (OB_FAIL(task_info.backup_dest_.get_backup_dest_str(backup_dest_str, OB_MAX_BACKUP_DEST_LENGTH))) { - LOG_WARN("failed to get backup dest str", K(ret), K(task_info)); - } else if (OB_FAIL(backup_dest.set(backup_dest_str, GCONF.cluster, task_info.cluster_id_, task_info.incarnation_))) { - LOG_WARN("failed to set backup dest", K(ret), K(task_info)); - } else if (OB_FAIL(tenant_info_mgr.init(backup_dest, *backup_lease_service_))) { - LOG_WARN("failed to init tenant info mgr", K(ret), K(backup_dest)); - } else if (OB_FAIL(tenant_info_mgr.get_extern_tenant_infos(extern_tenant_infos))) { - LOG_WARN("failed to get extern tenant infos", K(ret), K(backup_dest)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < extern_tenant_infos.count(); ++i) { - ObSimpleBackupDataCleanTenant simple_clean_tenant; - simple_clean_tenant.tenant_id_ = extern_tenant_infos.at(i).tenant_id_; - simple_clean_tenant.is_deleted_ = true; - int hash_ret = clean_tenants_map.set_refactored(simple_clean_tenant.tenant_id_, simple_clean_tenant); - if (OB_SUCCESS == hash_ret) { - // do nothing - } else if (OB_HASH_EXIST == hash_ret) { - ret = OB_SUCCESS; - } else { - ret = hash_ret; - LOG_WARN("failed to set simple clean tenant info set", K(ret), K(simple_clean_tenant), K(task_info)); - } - } - } - return ret; -} - int ObBackupDataClean::do_clean_scheduler(ObIArray &clean_tenants) { LOG_INFO("start do clean scheduler", K(clean_tenants)); @@ -2033,526 +1720,153 @@ int ObBackupDataClean::add_delete_backup_round(const share::ObBackupCleanInfo &c } else { if (clean_tenant.simple_clean_tenant_.is_deleted_) { LOG_INFO("tenant is deleted, can delete backup round directly", K(log_archive_info)); - } else { - ret = OB_BACKUP_DELETE_BACKUP_PIECE_NOT_ALLOWED; - LOG_WARN("round is not allowed to be deleted, because no valid backup_set is found", K(ret), K(log_archive_info)); - } - } - } - } - } - return ret; -} - -int ObBackupDataClean::do_tenant_backup_clean( - const share::ObBackupCleanInfo &clean_info, ObBackupDataCleanTenant &clean_tenant) -{ - LOG_INFO("start do tenant backup clean", K(clean_info)); - int ret = OB_SUCCESS; - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (!clean_tenant.is_valid() || !clean_info.is_valid()) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("get backup clean elements get invalid argument", K(ret), K(clean_tenant), K(clean_info)); - } - - DEBUG_SYNC(BACKUP_DATA_CLEAN_STATUS_DOING); - if (OB_FAIL(ret)) { - } else if (OB_SYS_TENANT_ID == clean_info.tenant_id_) { - // do nothing - } else if (OB_FAIL(do_normal_tenant_backup_clean(clean_info, clean_tenant))) { - LOG_WARN("failed to do sys tenant backup clean", K(ret), K(clean_info), K(clean_tenant)); - } - - return ret; -} - -int ObBackupDataClean::do_normal_tenant_backup_clean( - const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanTenant &clean_tenant) -{ - LOG_INFO("do normal tenant backup clean", K(clean_info), K(clean_tenant)); - int ret = OB_SUCCESS; - int tmp_ret = OB_SUCCESS; - const int64_t start_ts = ObTimeUtil::current_time(); - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (!clean_tenant.is_valid() || !clean_info.is_valid() || - OB_SYS_TENANT_ID == clean_tenant.simple_clean_tenant_.tenant_id_) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("get backup clean elements get invalid argument", K(ret), K(clean_tenant), K(clean_info)); - } else if (OB_FAIL(mark_backup_meta_data_deleting(clean_info, clean_tenant))) { - LOG_WARN("failed to mark backup data deleted", K(ret), K(clean_tenant), K(clean_info)); - } else if (OB_FAIL(delete_backup_data(clean_info, clean_tenant))) { - LOG_WARN("failed to delete backup data", K(ret), K(clean_info), K(clean_tenant)); - } else if (OB_FAIL(delete_tenant_backup_meta_data(clean_info, clean_tenant))) { - LOG_WARN("failed to delete backup meta data", K(ret), K(clean_tenant)); - } else if (OB_FAIL(try_clean_tenant_backup_dir(clean_tenant))) { - LOG_WARN("failed to try clean tenant backup dir", K(ret), K(clean_info)); - } - - if (is_result_need_retry(ret)) { - // do nothing - } else if (OB_SUCCESS != (tmp_ret = update_normal_tenant_clean_result(clean_info, clean_tenant, ret))) { - LOG_WARN("failed to update nomal tenant clean result", K(ret), K(clean_info), K(clean_tenant)); - } - - if (OB_SUCC(ret)) { - ret = tmp_ret; - } - - if (OB_SUCC(ret)) { - wakeup(); - } - - LOG_INFO("finish do normal tenant backup clean", - "cost_ts", - ObTimeUtil::current_time() - start_ts, - K(clean_tenant), - K(ret)); - - return ret; -} - -int ObBackupDataClean::update_normal_tenant_clean_result( - const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanTenant &clean_tenant, const int32_t clean_result) -{ - int ret = OB_SUCCESS; - ObMySQLTransaction trans; - ObBackupCleanInfo dest_clean_info; - ObTimeoutCtx timeout_ctx; - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (!clean_tenant.is_valid() || !clean_info.is_valid() || - OB_SYS_TENANT_ID == clean_tenant.simple_clean_tenant_.tenant_id_) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("get backup clean elements get invalid argument", K(ret), K(clean_tenant), K(clean_info)); - } else if (OB_FAIL(start_trans(timeout_ctx, trans))) { - LOG_WARN("failed to start trans", K(ret)); - } else { - dest_clean_info = clean_info; - dest_clean_info.result_ = clean_result; - dest_clean_info.status_ = ObBackupCleanInfoStatus::STOP; - dest_clean_info.end_time_ = ObTimeUtil::current_time(); - const uint64_t tenant_id = clean_tenant.simple_clean_tenant_.is_deleted_ ? OB_SYS_TENANT_ID : clean_info.tenant_id_; - if (OB_FAIL(set_comment(dest_clean_info.comment_))) { - LOG_WARN("failed to set comment", K(ret), K(dest_clean_info)); - } else if (OB_FAIL(set_error_msg(clean_result, dest_clean_info.error_msg_))) { - LOG_WARN("failed to set error msg", K(ret), K(dest_clean_info)); - } - - DEBUG_SYNC(BACKUP_DATA_NORMAL_TENANT_CLEAN_STATUS_DOING); - - if (OB_FAIL(ret)) { - } else if (OB_SUCCESS == clean_result && OB_FAIL(delete_inner_table_his_data(clean_info, clean_tenant, trans))) { - LOG_WARN("failed to delete inner table his data", K(ret), K(clean_info)); - } else if (OB_FAIL(update_clean_info(tenant_id, clean_info, dest_clean_info))) { - LOG_WARN("failed to update clean info", K(ret), K(clean_info), K(dest_clean_info)); - } - - if (OB_SUCC(ret)) { - if (OB_FAIL(commit_trans(trans))) { - LOG_WARN("failed to commit trans", K(ret)); - } - } else { - int tmp_ret = trans.end(false /*commit*/); - if (OB_SUCCESS != tmp_ret) { - LOG_WARN("end transaction failed", K(tmp_ret), K(ret)); - ret = OB_SUCCESS == ret ? tmp_ret : ret; - } - } - } - return ret; -} - -int ObBackupDataClean::mark_backup_meta_data_deleting( - const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanTenant &clean_tenant) -{ - int ret = OB_SUCCESS; - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (OB_FAIL(mark_backup_set_infos_deleting(clean_info, clean_tenant))) { - LOG_WARN("failed to mark backup set infos deleted", K(ret), K(clean_info)); - } else if (OB_FAIL(mark_log_archive_infos_deleting(clean_info, clean_tenant))) { - LOG_WARN("failed to mark log archive inifos deleted", K(ret), K(clean_info)); - } - return ret; -} - -int ObBackupDataClean::mark_extern_backup_info_deleted( - const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanElement &clean_element) -{ - int ret = OB_SUCCESS; - ObExternBackupInfoMgr extern_backup_info_mgr; - ObExternBackupSetFileInfoMgr extern_backup_set_file_info_mgr; - ObClusterBackupDest cluster_backup_dest; - ObArray backup_set_id_pairs; - const bool is_backup_backup = clean_info.copy_id_ > 0 || clean_info.is_delete_obsolete_backup_backup(); - ObBackupSetIdPair backup_set_id_pair; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (OB_FAIL(cluster_backup_dest.set(clean_element.backup_dest_, clean_element.incarnation_))) { - LOG_WARN("failed to set backup dest", K(ret), K(clean_element)); - } else if (OB_FAIL(extern_backup_info_mgr.init(clean_info.tenant_id_, cluster_backup_dest, *backup_lease_service_))) { - LOG_WARN("failed to init extern backup info mgr", K(ret), K(cluster_backup_dest), K(clean_info)); - } else if (OB_FAIL(extern_backup_set_file_info_mgr.init( - clean_info.tenant_id_, cluster_backup_dest, is_backup_backup, *backup_lease_service_))) { - LOG_WARN("failed to init extern backup set file info mgr", K(ret), K(clean_info), K(cluster_backup_dest)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < clean_element.backup_set_id_array_.count(); ++i) { - const ObBackupSetId &backup_set_id = clean_element.backup_set_id_array_.at(i); - backup_set_id_pair.reset(); - if (!backup_set_id.is_valid()) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("backup set id is invalid ", K(ret), K(backup_set_id)); - } else if (ObBackupDataCleanMode::TOUCH == backup_set_id.clean_mode_) { - // do nothing - } else { - backup_set_id_pair.backup_set_id_ = backup_set_id.backup_set_id_; - backup_set_id_pair.copy_id_ = backup_set_id.copy_id_; - if (OB_FAIL(backup_set_id_pairs.push_back(backup_set_id_pair))) { - LOG_WARN("failed to push backup set id into array", K(ret), K(backup_set_id_pair)); - } - } - } - - if (OB_SUCC(ret)) { - if (OB_FAIL(extern_backup_info_mgr.mark_backup_info_deleted(backup_set_id_pairs))) { - LOG_WARN("failed to mark backup info deleted", K(ret), K(backup_set_id_pairs)); - } else if (OB_FAIL(extern_backup_set_file_info_mgr.mark_backup_set_file_deleting(backup_set_id_pairs))) { - LOG_WARN("failed to mark backup set file info deleting", K(ret)); - } - } - } - return ret; -} - -int ObBackupDataClean::mark_inner_table_his_data_deleted( - const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanTenant &clean_tenant) -{ - int ret = OB_SUCCESS; - ObMySQLTransaction trans; - const int64_t clog_gc_snapshot = clean_info.clog_gc_snapshot_; - ObTimeoutCtx timeout_ctx; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (OB_FAIL(start_trans(timeout_ctx, trans))) { - LOG_WARN("failed to start trans", K(ret)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < clean_tenant.backup_element_array_.count(); ++i) { - const ObBackupDataCleanElement &backup_clean_element = clean_tenant.backup_element_array_.at(i); - if (OB_FAIL(mark_backup_task_his_data_deleted(clean_info, backup_clean_element, trans))) { - LOG_WARN("failed to mark backup task his data deleted", K(ret), K(clean_info)); - } else if (OB_FAIL(mark_log_archive_stauts_his_data_deleted( - clean_info, backup_clean_element, clog_gc_snapshot, trans))) { - LOG_WARN("failed to mark log archive status his data deleted", K(ret), K(clean_info)); - } - } - - if (OB_SUCC(ret)) { - if (OB_FAIL(commit_trans(trans))) { - LOG_WARN("failed to commit trans", K(ret)); - } - } else { - int tmp_ret = trans.end(false /*commit*/); - if (OB_SUCCESS != tmp_ret) { - LOG_WARN("end transaction failed", K(tmp_ret), K(ret)); - ret = OB_SUCCESS == ret ? tmp_ret : ret; - } - } - } - return ret; -} - -int ObBackupDataClean::mark_backup_task_his_data_deleted(const share::ObBackupCleanInfo &clean_info, - const ObBackupDataCleanElement &clean_element, common::ObISQLClient &trans) -{ - int ret = OB_SUCCESS; - const uint64_t tenant_id = clean_info.tenant_id_; - const int64_t incarnation = clean_element.incarnation_; - const ObBackupDest &backup_dest = clean_element.backup_dest_; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < clean_element.backup_set_id_array_.count(); ++i) { - const ObBackupSetId &backup_set_id = clean_element.backup_set_id_array_.at(i); - if (ObBackupDataCleanMode::CLEAN != backup_set_id.clean_mode_) { - // do nothing - } else { - if (0 == backup_set_id.copy_id_) { - if (OB_FAIL(inner_mark_backup_task_his_data_deleted( - tenant_id, incarnation, backup_set_id.backup_set_id_, backup_dest, trans))) { - LOG_WARN("failed to do inner mark backup task his data deleted", K(ret), K(backup_set_id), K(clean_info)); - } - } else { - if (OB_FAIL(inner_mark_backup_backup_task_his_data_deleted( - tenant_id, incarnation, backup_set_id.backup_set_id_, backup_set_id.copy_id_, backup_dest, trans))) { - LOG_WARN("failed to do inner mark backup backupset task his data deleted", - K(ret), - K(backup_set_id), - K(clean_info)); - } - } - - if (OB_FAIL(ret)) { - } else if (OB_FAIL(inner_mark_backup_set_file_data_deleted( - tenant_id, incarnation, backup_set_id.backup_set_id_, backup_set_id.copy_id_, trans))) { - LOG_WARN("failed to inner mark backup set file data deleted", K(ret), K(backup_set_id), K(clean_info)); - } - } - } - } - return ret; -} - -int ObBackupDataClean::inner_mark_backup_task_his_data_deleted(const uint64_t tenant_id, const int64_t incarnation, - const int64_t backup_set_id, const ObBackupDest &backup_dest, common::ObISQLClient &trans) -{ - int ret = OB_SUCCESS; - ObBackupTaskHistoryUpdater updater; - ObArray backup_tasks; - const bool for_update = true; - - if (OB_FAIL(updater.init(trans))) { - LOG_WARN("failed to init backup task history updater", K(ret)); - } else if (OB_FAIL(updater.get_need_mark_deleted_backup_tasks( - tenant_id, backup_set_id, incarnation, backup_dest, for_update, backup_tasks))) { - LOG_WARN("failed to get need mark deleted backup tasks", K(ret), K(tenant_id), K(backup_set_id), K(backup_dest)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < backup_tasks.count(); ++i) { - const ObTenantBackupTaskInfo &backup_task_info = backup_tasks.at(i); - if (OB_FAIL(updater.mark_backup_task_deleted( - backup_task_info.tenant_id_, backup_task_info.incarnation_, backup_task_info.backup_set_id_))) { - LOG_WARN("failed to mark backup task deleted", K(ret), K(backup_task_info)); - } - } - } - return ret; -} - -int ObBackupDataClean::inner_mark_backup_backup_task_his_data_deleted(const uint64_t tenant_id, - const int64_t incarnation, const int64_t backup_set_id, const int64_t copy_id, - const share::ObBackupDest &backup_dest, common::ObISQLClient &trans) -{ - int ret = OB_SUCCESS; - ObArray backup_backupset_tasks; - UNUSED(incarnation); - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (OB_FAIL(ObTenantBackupBackupsetHistoryOperator::get_need_mark_deleted_tasks_items( - tenant_id, copy_id, backup_set_id, backup_dest, backup_backupset_tasks, trans))) { - LOG_WARN("failed to get need mark deleted task items", KR(ret), K(tenant_id)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < backup_backupset_tasks.count(); ++i) { - const ObTenantBackupBackupsetTaskInfo &info = backup_backupset_tasks.at(i); - if (OB_FAIL(ObTenantBackupBackupsetHistoryOperator::mark_task_item_deleted( - info.tenant_id_, info.incarnation_, info.copy_id_, info.backup_set_id_, trans))) { - LOG_WARN("failed to mark task item deleted", KR(ret), K(tenant_id), K(copy_id)); - } - } - } - - return ret; -} - -int ObBackupDataClean::inner_mark_backup_set_file_data_deleting(const uint64_t tenant_id, const int64_t incarnation, - const int64_t backup_set_id, const int64_t copy_id, common::ObISQLClient &trans) -{ - int ret = OB_SUCCESS; - ObArray backup_set_file_infos; - const bool for_update = true; - ObBackupSetFileInfo dest_backup_set_file; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (OB_FAIL(ObBackupSetFilesOperator::get_tenant_backup_set_file_infos( - tenant_id, incarnation, backup_set_id, copy_id, for_update, trans, backup_set_file_infos))) { - LOG_WARN("failed to get tenant backup set file infos", K(ret), K(tenant_id), K(incarnation), K(backup_set_id)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < backup_set_file_infos.count(); ++i) { - const ObBackupSetFileInfo &src_backup_set_file = backup_set_file_infos.at(i); - dest_backup_set_file = src_backup_set_file; - if (ObBackupSetFileInfo::DOING == src_backup_set_file.status_) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("backup set file status is unexpected, can not clean", K(ret), K(src_backup_set_file)); - } else if (ObBackupFileStatus::BACKUP_FILE_DELETING == src_backup_set_file.file_status_) { - // do nothing - } else if (FALSE_IT(dest_backup_set_file.file_status_ = ObBackupFileStatus::BACKUP_FILE_DELETING)) { - } else if (OB_FAIL(ObBackupSetFilesOperator::update_tenant_backup_set_file( - src_backup_set_file, dest_backup_set_file, trans))) { - LOG_WARN("failed to update tenant backup set file", K(ret), K(src_backup_set_file), K(dest_backup_set_file)); + } else { + ret = OB_BACKUP_DELETE_BACKUP_PIECE_NOT_ALLOWED; + LOG_WARN("round is not allowed to be deleted, because no valid backup_set is found", + K(ret), + K(log_archive_info)); + } + } } } } return ret; } -int ObBackupDataClean::inner_mark_backup_set_file_data_deleted(const uint64_t tenant_id, const int64_t incarnation, - const int64_t backup_set_id, const int64_t copy_id, common::ObISQLClient &trans) +int ObBackupDataClean::do_tenant_backup_clean( + const share::ObBackupCleanInfo &clean_info, ObBackupDataCleanTenant &clean_tenant) { + LOG_INFO("start do tenant backup clean", K(clean_info)); int ret = OB_SUCCESS; - ObArray backup_set_file_infos; - const bool for_update = true; - ObBackupSetFileInfo dest_backup_set_file; - if (!is_inited_) { ret = OB_NOT_INIT; LOG_WARN("backup data clean do not init", K(ret)); - } else if (OB_FAIL(ObBackupSetFilesOperator::get_tenant_backup_set_file_infos( - tenant_id, incarnation, backup_set_id, copy_id, for_update, trans, backup_set_file_infos))) { - LOG_WARN("failed to get tenant backup set file infos", K(ret), K(tenant_id), K(incarnation), K(backup_set_id)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < backup_set_file_infos.count(); ++i) { - const ObBackupSetFileInfo &src_backup_set_file = backup_set_file_infos.at(i); - dest_backup_set_file = src_backup_set_file; - if (ObBackupSetFileInfo::DOING == src_backup_set_file.status_) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("backup set file status is unexpected, can not clean", K(ret), K(src_backup_set_file)); - } else if (ObBackupFileStatus::BACKUP_FILE_DELETED == src_backup_set_file.file_status_) { - // do nothing - } else if (FALSE_IT(dest_backup_set_file.file_status_ = ObBackupFileStatus::BACKUP_FILE_DELETED)) { - } else if (OB_FAIL(ObBackupSetFilesOperator::update_tenant_backup_set_file( - src_backup_set_file, dest_backup_set_file, trans))) { - LOG_WARN("failed to update tenant backup set file", K(ret), K(src_backup_set_file), K(dest_backup_set_file)); - } - } + } else if (!clean_tenant.is_valid() || !clean_info.is_valid()) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("get backup clean elements get invalid argument", K(ret), K(clean_tenant), K(clean_info)); + } + + DEBUG_SYNC(BACKUP_DATA_CLEAN_STATUS_DOING); + if (OB_FAIL(ret)) { + } else if (OB_SYS_TENANT_ID == clean_info.tenant_id_) { + // do nothing + } else if (OB_FAIL(do_normal_tenant_backup_clean(clean_info, clean_tenant))) { + LOG_WARN("failed to do sys tenant backup clean", K(ret), K(clean_info), K(clean_tenant)); } + return ret; } -int ObBackupDataClean::mark_log_archive_stauts_his_data_deleted(const share::ObBackupCleanInfo &clean_info, - const ObBackupDataCleanElement &clean_element, const int64_t clog_gc_snapshot, common::ObISQLClient &trans) +int ObBackupDataClean::do_normal_tenant_backup_clean( + const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanTenant &clean_tenant) { + LOG_INFO("do normal tenant backup clean", K(clean_info), K(clean_tenant)); int ret = OB_SUCCESS; - + int tmp_ret = OB_SUCCESS; + const int64_t start_ts = ObTimeUtil::current_time(); if (!is_inited_) { ret = OB_NOT_INIT; LOG_WARN("backup data clean do not init", K(ret)); - } else if (clean_info.is_delete_backup_piece()) { - const bool for_update = true; - ObLogArchiveBackupInfoMgr log_archive_backup_info_mgr; - ObBackupPieceInfo backup_piece_info; - if (OB_FAIL(log_archive_backup_info_mgr.get_backup_piece(trans, - for_update, - clean_info.tenant_id_, - clean_info.backup_piece_id_, - clean_info.copy_id_, - backup_piece_info))) { - LOG_WARN("failed to get backup piece info", K(ret), K(clean_info)); - } else if (OB_FAIL(mark_log_archive_piece_data_deleting(clean_info, backup_piece_info, clog_gc_snapshot, trans))) { - LOG_WARN("failed to mark log archive piece data deleted", K(clean_info), K(backup_piece_info)); - } - } else if (clean_info.is_delete_backup_round()) { - const int64_t start_piece_id = 0; - if (OB_FAIL(mark_log_archive_round_data_deleted( - clean_info, clean_info.backup_round_id_, clean_info.copy_id_, start_piece_id, clog_gc_snapshot, trans))) { - LOG_WARN("failed to mark delete log archive round data deleted", K(ret), K(clean_info)); - } - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < clean_element.log_archive_round_array_.count(); ++i) { - const ObLogArchiveRound &log_archive_round = clean_element.log_archive_round_array_.at(i); - if (OB_FAIL(mark_log_archive_round_data_deleted(clean_info, - log_archive_round.log_archive_round_, - log_archive_round.copy_id_, - log_archive_round.start_piece_id_, - clog_gc_snapshot, - trans))) { - LOG_WARN("failed to mark log archive round data deleted", K(ret), K(clean_info), K(log_archive_round)); - } - } + } else if (!clean_tenant.is_valid() || !clean_info.is_valid() || + OB_SYS_TENANT_ID == clean_tenant.simple_clean_tenant_.tenant_id_) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("get backup clean elements get invalid argument", K(ret), K(clean_tenant), K(clean_info)); + } else if (OB_FAIL(mark_backup_meta_data_deleting(clean_info, clean_tenant))) { + LOG_WARN("failed to mark backup data deleted", K(ret), K(clean_tenant), K(clean_info)); + } else if (OB_FAIL(delete_backup_data(clean_info, clean_tenant))) { + LOG_WARN("failed to delete backup data", K(ret), K(clean_info), K(clean_tenant)); + } else if (OB_FAIL(delete_tenant_backup_meta_data(clean_info, clean_tenant))) { + LOG_WARN("failed to delete backup meta data", K(ret), K(clean_tenant)); + } else if (OB_FAIL(try_clean_tenant_backup_dir(clean_tenant))) { + LOG_WARN("failed to try clean tenant backup dir", K(ret), K(clean_info)); + } + + if (is_result_need_retry(ret)) { + // do nothing + } else if (OB_SUCCESS != (tmp_ret = update_normal_tenant_clean_result(clean_info, clean_tenant, ret))) { + LOG_WARN("failed to update nomal tenant clean result", K(ret), K(clean_info), K(clean_tenant)); + } + + if (OB_SUCC(ret)) { + ret = tmp_ret; + } + + if (OB_SUCC(ret)) { + wakeup(); } + + LOG_INFO("finish do normal tenant backup clean", + "cost_ts", + ObTimeUtil::current_time() - start_ts, + K(clean_tenant), + K(ret)); + return ret; } -int ObBackupDataClean::mark_log_archive_round_data_deleted(const share::ObBackupCleanInfo &clean_info, - const int64_t log_archive_round, const int64_t copy_id, const int64_t start_piece_id, - const int64_t clog_gc_snapshot, common::ObISQLClient &trans) +int ObBackupDataClean::update_normal_tenant_clean_result( + const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanTenant &clean_tenant, const int32_t clean_result) { int ret = OB_SUCCESS; - const bool is_backup_backup = copy_id > 0; - ObLogArchiveBackupInfo log_archive_backup_info; - ObLogArchiveBackupInfoMgr log_archive_backup_info_mgr; - ObArray backup_piece_infos; - const bool for_update = true; - + ObMySQLTransaction trans; + ObBackupCleanInfo dest_clean_info; + ObTimeoutCtx timeout_ctx; if (!is_inited_) { ret = OB_NOT_INIT; LOG_WARN("backup data clean do not init", K(ret)); - } else if (is_backup_backup && OB_FAIL(log_archive_backup_info_mgr.set_backup_backup())) { - LOG_WARN("failed to set copy id", K(ret), K(clean_info)); - } else if (OB_FAIL(log_archive_backup_info_mgr.get_log_archive_history_info( - trans, clean_info.tenant_id_, log_archive_round, copy_id, for_update, log_archive_backup_info))) { - if (OB_ENTRY_NOT_EXIST == ret && is_backup_backup && start_piece_id > 0) { - ret = OB_SUCCESS; - } else { - LOG_WARN("failed to get log archive history info", K(ret), K(clean_info)); + } else if (!clean_tenant.is_valid() || !clean_info.is_valid() || + OB_SYS_TENANT_ID == clean_tenant.simple_clean_tenant_.tenant_id_) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("get backup clean elements get invalid argument", K(ret), K(clean_tenant), K(clean_info)); + } else if (OB_FAIL(start_trans(timeout_ctx, trans))) { + LOG_WARN("failed to start trans", K(ret)); + } else { + dest_clean_info = clean_info; + dest_clean_info.result_ = clean_result; + dest_clean_info.status_ = ObBackupCleanInfoStatus::STOP; + dest_clean_info.end_time_ = ObTimeUtil::current_time(); + const uint64_t tenant_id = clean_tenant.simple_clean_tenant_.is_deleted_ ? OB_SYS_TENANT_ID : clean_info.tenant_id_; + if (OB_FAIL(set_comment(dest_clean_info.comment_))) { + LOG_WARN("failed to set comment", K(ret), K(dest_clean_info)); + } else if (OB_FAIL(set_error_msg(clean_result, dest_clean_info.error_msg_))) { + LOG_WARN("failed to set error msg", K(ret), K(dest_clean_info)); } - } else if (ObLogArchiveStatus::STOP != log_archive_backup_info.status_.status_ || - log_archive_backup_info.status_.checkpoint_ts_ < clog_gc_snapshot) { - // do nothing - } else if (OB_FAIL( - log_archive_backup_info_mgr.mark_log_archive_history_info_deleted(log_archive_backup_info, trans))) { - LOG_WARN("failed to mark log archive history info deleted", K(ret), K(clean_info), K(log_archive_backup_info)); - } - if (OB_FAIL(ret)) { - } else if (OB_FAIL(log_archive_backup_info_mgr.get_round_backup_piece_infos(trans, - for_update, - clean_info.tenant_id_, - log_archive_backup_info.status_.incarnation_, - clean_info.backup_round_id_, - is_backup_backup, - backup_piece_infos))) { - LOG_WARN("failed to get round backup piece infos", K(ret), K(clean_info), K(log_archive_backup_info)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < backup_piece_infos.count(); ++i) { - ObBackupPieceInfo backup_piece_info = backup_piece_infos.at(i); - if (OB_FAIL(mark_log_archive_piece_data_deleting(clean_info, backup_piece_info, clog_gc_snapshot, trans))) { - LOG_WARN("failed to mark log archive piece data deleted", K(ret), K(clean_info)); + DEBUG_SYNC(BACKUP_DATA_NORMAL_TENANT_CLEAN_STATUS_DOING); + + if (OB_FAIL(ret)) { + } else if (OB_SUCCESS == clean_result && OB_FAIL(delete_inner_table_his_data(clean_info, clean_tenant, trans))) { + LOG_WARN("failed to delete inner table his data", K(ret), K(clean_info)); + } else if (OB_FAIL(update_clean_info(tenant_id, clean_info, dest_clean_info))) { + LOG_WARN("failed to update clean info", K(ret), K(clean_info), K(dest_clean_info)); + } + + if (OB_SUCC(ret)) { + if (OB_FAIL(commit_trans(trans))) { + LOG_WARN("failed to commit trans", K(ret)); + } + } else { + int tmp_ret = trans.end(false /*commit*/); + if (OB_SUCCESS != tmp_ret) { + LOG_WARN("end transaction failed", K(tmp_ret), K(ret)); + ret = OB_SUCCESS == ret ? tmp_ret : ret; } } } return ret; } -int ObBackupDataClean::mark_log_archive_piece_data_deleting(const share::ObBackupCleanInfo &clean_info, - const ObBackupPieceInfo &backup_piece_info, const int64_t clog_gc_snapshot, common::ObISQLClient &trans) +int ObBackupDataClean::mark_backup_meta_data_deleting( + const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanTenant &clean_tenant) { int ret = OB_SUCCESS; - ObLogArchiveBackupInfoMgr log_archive_backup_info_mgr; - if (!is_inited_) { ret = OB_NOT_INIT; LOG_WARN("backup data clean do not init", K(ret)); - } else { - if (!ObBackupUtils::can_backup_pieces_be_deleted(backup_piece_info.status_) || - backup_piece_info.max_ts_ > clog_gc_snapshot) { - if (clean_info.is_delete_backup_piece() || clean_info.is_delete_backup_round()) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("backup piece info status is unexpected, can not delete", K(ret), K(backup_piece_info)); - } else { - // do nothing - } - } else if (ObBackupFileStatus::BACKUP_FILE_DELETING == backup_piece_info.file_status_) { - // do nothing - } else { - ObBackupPieceInfo dest_backup_piece_info = backup_piece_info; - dest_backup_piece_info.file_status_ = ObBackupFileStatus::BACKUP_FILE_DELETING; - if (OB_FAIL(log_archive_backup_info_mgr.update_backup_piece(trans, dest_backup_piece_info))) { - LOG_WARN("failed to update backup piece", K(ret), K(dest_backup_piece_info), K(backup_piece_info)); - } - } + } else if (OB_FAIL(mark_backup_set_infos_deleting(clean_info, clean_tenant))) { + LOG_WARN("failed to mark backup set infos deleted", K(ret), K(clean_info)); + } else if (OB_FAIL(mark_log_archive_infos_deleting(clean_info, clean_tenant))) { + LOG_WARN("failed to mark log archive inifos deleted", K(ret), K(clean_info)); } return ret; } @@ -3120,7 +2434,6 @@ int ObBackupDataClean::get_sys_tenant_prepare_clog_round_and_piece(const share:: } } } - if (OB_FAIL(ret)) { } else if (ObLogArchiveStatus::STOP != log_archive_round.log_archive_status_) { // do nothing @@ -3694,31 +3007,6 @@ int ObBackupDataClean::delete_marked_backup_task_his_data(const share::ObBackupC return ret; } -int ObBackupDataClean::inner_delete_marked_backup_backup_task_his_data(const uint64_t tenant_id, const int64_t job_id, - const int64_t copy_id, const int64_t backup_set_id, common::ObISQLClient &trans) -{ - int ret = OB_SUCCESS; - ObTenantBackupTaskInfo tenant_backup_task; - ObTenantBackupBackupsetTaskInfo backup_backupset_task; - ObArray task_list; - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (OB_FAIL(ObTenantBackupBackupsetHistoryOperator::get_task_item( - tenant_id, job_id, backup_set_id, copy_id, task_list, trans))) { - LOG_WARN("failed to get task item", K(ret), K(backup_set_id), K(copy_id)); - } else if (FALSE_IT(backup_backupset_task = task_list.at(0))) { - // TODO(muwei.ym): deal with array list - } else if (OB_FAIL(backup_backupset_task.convert_to_backup_task_info(tenant_backup_task))) { - LOG_WARN("failed to convert to backup task info", K(ret), K(backup_backupset_task)); - } else if (OB_FAIL(ObBackupTaskCleanHistoryOpertor::insert_task_info(job_id, copy_id, tenant_backup_task, trans))) { - LOG_WARN("failed to insert task into clean history", K(ret), K(tenant_backup_task)); - } else if (OB_FAIL(ObTenantBackupBackupsetHistoryOperator::delete_task_item(backup_backupset_task, trans))) { - LOG_WARN("failed to delete task item", KR(ret), K(tenant_id), K(job_id)); - } - return ret; -} - int ObBackupDataClean::delete_marked_log_archive_status_his_data(const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanElement &clean_element, common::ObISQLClient &trans) { @@ -5304,80 +4592,6 @@ int ObBackupDataClean::do_normal_tenant_cancel_delete_backup( return ret; } -/*not use anymore*/ -int ObBackupDataClean::get_sys_tenant_backup_dest(hash::ObHashSet &cluster_backup_dest_set) -{ - int ret = OB_SUCCESS; - ObArray task_infos; - ObArray log_archive_infos; - ObMySQLTransaction trans; - ObTimeoutCtx timeout_ctx; - const uint64_t tenant_id = OB_SYS_TENANT_ID; - ObBackupCleanInfo sys_clean_info; - sys_clean_info.tenant_id_ = tenant_id; - const bool for_update = false; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (OB_FAIL(start_trans(timeout_ctx, trans))) { - LOG_WARN("failed to start trans", K(ret)); - } else { - if (OB_FAIL(get_backup_clean_info(tenant_id, for_update, trans, sys_clean_info))) { - LOG_WARN("failed to get backup clean info", K(ret), K(sys_clean_info)); - } else if (ObBackupCleanInfoStatus::STOP == sys_clean_info.status_ || - ObBackupCleanInfoStatus::PREPARE == sys_clean_info.status_) { - // do nothing - } else if (OB_FAIL(get_tenant_backup_task_his_info(sys_clean_info, trans, task_infos))) { - LOG_WARN("failed to get backup task his info", K(ret), K(sys_clean_info)); - } else if (OB_FAIL(get_tenant_backup_task_info(sys_clean_info, trans, task_infos))) { - LOG_WARN("failed to get archive info", K(ret), K(sys_clean_info)); - } else if (OB_FAIL(get_log_archive_history_info(sys_clean_info.copy_id_, tenant_id, trans, log_archive_infos))) { - LOG_WARN("failed to get log archive history info", K(ret), K(sys_clean_info)); - } else if (OB_FAIL(get_log_archive_info(sys_clean_info.copy_id_, tenant_id, trans, log_archive_infos))) { - LOG_WARN("failed to get archive info", K(ret), K(sys_clean_info)); - } - - if (OB_SUCC(ret)) { - if (OB_FAIL(commit_trans(trans))) { - LOG_WARN("failed to commit trans", K(ret)); - } - } else { - int tmp_ret = trans.end(false /*commit*/); - if (OB_SUCCESS != tmp_ret) { - LOG_WARN("end transaction failed", K(tmp_ret), K(ret)); - ret = OB_SUCCESS == ret ? tmp_ret : ret; - } - } - - if (OB_SUCC(ret)) { - // add task info backup dest - ObClusterBackupDest cluster_backup_dest; - for (int64_t i = 0; OB_SUCC(ret) && i < task_infos.count(); ++i) { - cluster_backup_dest.reset(); - const ObTenantBackupTaskInfo &task_info = task_infos.at(i); - if (OB_FAIL(cluster_backup_dest.set(task_info.backup_dest_, task_info.incarnation_))) { - LOG_WARN("failed to set cluster backup dest", K(ret), K(task_info)); - } else if (OB_FAIL(cluster_backup_dest_set.set_refactored(cluster_backup_dest))) { - LOG_WARN("failed to set cluster backup dest", K(ret), K(cluster_backup_dest)); - } - } - - // add log archive dest - for (int64_t i = 0; OB_SUCC(ret) && i < log_archive_infos.count(); ++i) { - cluster_backup_dest.reset(); - const ObLogArchiveBackupInfo &archive_info = log_archive_infos.at(i); - if (OB_FAIL(cluster_backup_dest.set(archive_info.backup_dest_, archive_info.status_.incarnation_))) { - LOG_WARN("failed to set cluster backup dest", K(ret), K(archive_info)); - } else if (OB_FAIL(cluster_backup_dest_set.set_refactored(cluster_backup_dest))) { - LOG_WARN("failed to set cluster backup dest", K(ret), K(cluster_backup_dest)); - } - } - } - } - return ret; -} - int ObBackupDataClean::do_scheduler_normal_tenant(share::ObBackupCleanInfo &clean_info, ObBackupDataCleanTenant &clean_tenant, common::ObIArray &task_infos, common::ObIArray &log_archive_infos) @@ -5411,109 +4625,6 @@ int ObBackupDataClean::do_scheduler_normal_tenant(share::ObBackupCleanInfo &clea return ret; } -int ObBackupDataClean::do_scheduler_deleted_tenant(share::ObBackupCleanInfo &clean_info, - ObBackupDataCleanTenant &clean_tenant, common::ObIArray &task_infos, - common::ObIArray &log_archive_infos) -{ - int ret = OB_SUCCESS; - clean_tenant.backup_element_array_.reset(); - ObBackupCleanInfo sys_clean_info; - clean_info.reset(); - ObSimpleBackupDataCleanTenant &simple_clean_tenant = clean_tenant.simple_clean_tenant_; - const bool for_update = false; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (!clean_tenant.is_valid() || !clean_tenant.simple_clean_tenant_.is_deleted_) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("do tenant clean scheduler get invalid argument", K(ret), K(clean_tenant)); - } else { - const uint64_t tenant_id = OB_SYS_TENANT_ID; - clean_info.tenant_id_ = simple_clean_tenant.tenant_id_; - if (OB_FAIL(get_backup_clean_info(tenant_id, for_update, *sql_proxy_, clean_info))) { - LOG_WARN("failed to get backup clean info", K(ret), K(clean_tenant)); - } else if (ObBackupCleanInfoStatus::STOP == clean_info.status_ || - ObBackupCleanInfoStatus::PREPARE == clean_info.status_) { - // do nothing - } else if (OB_FAIL(get_all_tenant_backup_infos( - clean_info, clean_tenant.simple_clean_tenant_, *sql_proxy_, task_infos, log_archive_infos))) { - LOG_WARN("failed to get all tenant backup infos", K(ret), K(clean_info)); - } - } - return ret; -} - -int ObBackupDataClean::do_inner_scheduler_delete_tenant(const ObClusterBackupDest &cluster_backup_dest, - ObBackupDataCleanTenant &clean_tenant, common::ObIArray &task_infos, - common::ObIArray &log_archive_infos) -{ - int ret = OB_SUCCESS; - ObExternBackupInfoMgr extern_backup_info_mgr; - ObLogArchiveBackupInfoMgr log_archive_info_mgr; - ObArray extern_backup_infos; - ObExternLogArchiveBackupInfo archive_backup_info; - ObArray status_array; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean do not init", K(ret)); - } else if (!cluster_backup_dest.is_valid()) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("do inner scheduler delete tenant get invalid argument", K(ret), K(cluster_backup_dest)); - } else if (OB_FAIL(extern_backup_info_mgr.init( - clean_tenant.simple_clean_tenant_.tenant_id_, cluster_backup_dest, *backup_lease_service_))) { - LOG_WARN("failed to init extern backup info mgr", K(ret), K(cluster_backup_dest), K(clean_tenant)); - } else if (OB_FAIL(extern_backup_info_mgr.get_extern_full_backup_infos(extern_backup_infos))) { - LOG_WARN("failed to get extern full backup infos", K(ret), K(clean_tenant)); - } else if (OB_FAIL(log_archive_info_mgr.read_extern_log_archive_backup_info( - cluster_backup_dest, clean_tenant.simple_clean_tenant_.tenant_id_, archive_backup_info))) { - LOG_WARN("failed to read extern log archive backup info", K(ret), K(cluster_backup_dest)); - } else if (OB_FAIL(archive_backup_info.get_log_archive_status(status_array))) { - LOG_WARN("failed to get log archive status", K(ret), K(clean_tenant)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < extern_backup_infos.count(); ++i) { - const ObExternBackupInfo &extern_backup_info = extern_backup_infos.at(i); - ObTenantBackupTaskInfo task_info; - task_info.cluster_id_ = cluster_backup_dest.cluster_id_; - task_info.tenant_id_ = clean_tenant.simple_clean_tenant_.tenant_id_; - task_info.backup_set_id_ = extern_backup_info.full_backup_set_id_; - task_info.incarnation_ = cluster_backup_dest.incarnation_; - task_info.snapshot_version_ = extern_backup_info.backup_snapshot_version_; - task_info.prev_full_backup_set_id_ = extern_backup_info.prev_full_backup_set_id_; - task_info.prev_inc_backup_set_id_ = extern_backup_info.prev_inc_backup_set_id_; - task_info.backup_type_.type_ = extern_backup_info.backup_type_; - task_info.status_ = ObTenantBackupTaskInfo::FINISH; - task_info.device_type_ = cluster_backup_dest.dest_.device_type_; - task_info.backup_dest_ = cluster_backup_dest.dest_; - task_info.encryption_mode_ = extern_backup_info.encryption_mode_; - task_info.date_ = extern_backup_info.date_; - if (OB_FAIL(task_infos.push_back(task_info))) { - LOG_WARN("failed to push task info into array", K(ret), K(task_info)); - } - } - - for (int64_t i = 0; OB_SUCC(ret) && i < status_array.count(); ++i) { - ObTenantLogArchiveStatus &status = status_array.at(i); - // set delete tenant archive status stop - status.status_ = ObLogArchiveStatus::STOP; - ObLogArchiveBackupInfo archive_info; - archive_info.status_ = status; - if (OB_FAIL( - cluster_backup_dest.dest_.get_backup_dest_str(archive_info.backup_dest_, OB_MAX_BACKUP_DEST_LENGTH))) { - LOG_WARN("failed to get backup dest str", K(ret), K(cluster_backup_dest)); - } else if (OB_FAIL(log_archive_infos.push_back(archive_info))) { - LOG_WARN("failed to push archive info into array", K(ret), K(archive_info)); - } - } - - if (OB_SUCC(ret)) { - LOG_INFO("succeed get task info and log archive info", K(task_infos), K(log_archive_infos)); - } - } - return ret; -} - int ObBackupDataClean::check_backup_dest_lifecycle(const ObBackupDataCleanTenant &clean_tenant) { int ret = OB_SUCCESS; diff --git a/src/rootserver/ob_backup_data_clean.h b/src/rootserver/ob_backup_data_clean.h index 47c6bf6187..3d5924ed45 100644 --- a/src/rootserver/ob_backup_data_clean.h +++ b/src/rootserver/ob_backup_data_clean.h @@ -105,30 +105,10 @@ public: private: int get_need_clean_tenants(common::ObIArray &clean_tenants); int get_server_clean_tenants(common::ObIArray &clean_tenants); - int get_extern_clean_tenants(hash::ObHashMap &clean_tenants_map); int get_server_need_clean_info(const uint64_t tenant_id, bool &need_add); int get_all_tenant_ids(common::ObIArray &tenant_ids); - int get_tenant_backup_task_his_info(const share::ObBackupCleanInfo &clean_info, common::ObISQLClient &trans, - common::ObIArray &tenant_infos); int get_tenant_backup_task_info(const share::ObBackupCleanInfo &clean_info, common::ObISQLClient &trans, common::ObIArray &tenant_infos); - int inner_get_tenant_backup_task_his_info(const share::ObBackupCleanInfo &clean_info, common::ObISQLClient &trans, - common::ObIArray &tenant_infos); - int get_tenant_backup_backupset_task_his_info(const share::ObBackupCleanInfo &clean_info, common::ObISQLClient &trans, - common::ObIArray &tenant_infos); - int convert_backup_backupset_task_to_backup_task( - const common::ObIArray &backup_backupset_tasks, - common::ObIArray &backup_tasks); - int get_log_archive_info(const int64_t copy_id, const uint64_t tenant_id, common::ObISQLClient &trans, - common::ObIArray &log_archive_infos); - int get_log_archive_history_info(const int64_t copy_id, const uint64_t tenant_id, common::ObISQLClient &trans, - common::ObIArray &log_archive_infos); - - int get_backup_clean_tenant(const share::ObTenantBackupTaskInfo &task_info, - hash::ObHashMap &clean_tenants_map); - int get_archive_clean_tenant(const share::ObLogArchiveBackupInfo &log_archive_info, - hash::ObHashMap &clean_tenants_map); - int get_backup_clean_elements(const share::ObBackupCleanInfo &clean_info, const common::ObIArray &task_infos, const common::ObArray &log_archive_infos, ObBackupDataCleanTenant &clean_tenant); @@ -155,30 +135,6 @@ private: const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanTenant &clean_tenant); int mark_backup_meta_data_deleting( const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanTenant &clean_tenant); - int mark_inner_table_his_data_deleted( - const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanTenant &clean_tenant); - - int mark_backup_task_his_data_deleted(const share::ObBackupCleanInfo &clean_info, - const ObBackupDataCleanElement &clean_element, common::ObISQLClient &trans); - int inner_mark_backup_task_his_data_deleted(const uint64_t tenant_id, const int64_t incarnation, - const int64_t backup_set_id, const share::ObBackupDest &backup_dest, common::ObISQLClient &trans); - int inner_mark_backup_backup_task_his_data_deleted(const uint64_t tenant_id, const int64_t incarnation, - const int64_t backup_set_id, const int64_t copy_id, const share::ObBackupDest &backup_dest, - common::ObISQLClient &trans); - int inner_mark_backup_set_file_data_deleting(const uint64_t tenant_id, const int64_t incarnation, - const int64_t backup_set_id, const int64_t copy_id, common::ObISQLClient &trans); - int inner_mark_backup_set_file_data_deleted(const uint64_t tenant_id, const int64_t incarnation, - const int64_t backup_set_id, const int64_t copy_id, common::ObISQLClient &trans); - - int mark_log_archive_stauts_his_data_deleted(const share::ObBackupCleanInfo &clean_info, - const ObBackupDataCleanElement &clean_element, const int64_t clog_gc_snapshot, common::ObISQLClient &trans); - int mark_log_archive_round_data_deleted(const share::ObBackupCleanInfo &clean_info, const int64_t log_archive_round, - const int64_t copy_id, const int64_t start_piece_id, const int64_t clog_gc_snapshot, common::ObISQLClient &trans); - int mark_log_archive_piece_data_deleting(const share::ObBackupCleanInfo &clean_info, - const ObBackupPieceInfo &backup_piece_info, const int64_t clog_gc_snapshot, common::ObISQLClient &trans); - - int mark_extern_backup_info_deleted( - const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanElement &clean_element); // for new interface int mark_backup_set_infos_deleting( @@ -189,7 +145,6 @@ private: const ObBackupDataCleanElement &clean_element, const common::ObIArray &backup_set_ids); int mark_extern_backup_set_info_deleting(const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanElement &clean_element, const common::ObIArray &backup_set_ids); - int mark_log_archive_infos_deleting( const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanTenant &clean_tenant); int mark_log_archive_info_deleting( @@ -232,21 +187,14 @@ private: const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanTenant &clean_tenant); int delete_inner_table_his_data(const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanTenant &clean_tenant, common::ObISQLClient &trans); - int delete_backup_extern_info( - const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanElement &clean_element); - int delete_extern_backup_info_deleted(const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanElement &clean_element, const common::ObIArray &backup_set_ids); int delete_extern_clog_info_deleted(const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanElement &clean_element, const common::ObIArray &log_archive_rounds); - int delete_marked_backup_task_his_data(const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanElement &clean_element, common::ObISQLClient &trans); - int inner_delete_marked_backup_backup_task_his_data(const uint64_t tenant_id, const int64_t job_id, - const int64_t copy_id, const int64_t backup_set_id, common::ObISQLClient &trans); int delete_marked_log_archive_status_his_data(const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanElement &clean_element, common::ObISQLClient &trans); - // new interface int delete_extern_tmp_files( const share::ObBackupCleanInfo &clean_info, const ObBackupDataCleanElement &clean_element); @@ -260,11 +208,9 @@ private: int update_clean_info(const uint64_t tenant_id, const share::ObBackupCleanInfo &src_clean_info, const share::ObBackupCleanInfo &dest_clean_info, common::ObISQLClient &trans); int do_with_status(const share::ObBackupCleanInfo &clean_info, ObBackupDataCleanTenant &clean_tenant); - int do_clean_scheduler(common::ObIArray &clean_tenants); int do_schedule_clean_tenants(common::ObIArray &clean_tenants); int do_check_clean_tenants_finished(const common::ObIArray &clean_tenants); - int do_tenant_clean_scheduler(share::ObBackupCleanInfo &clean_info, ObBackupDataCleanTenant &clean_tenant); int get_backup_clean_info(const uint64_t tenant_id, const bool for_update, common::ObISQLClient &sql_proxy, share::ObBackupCleanInfo &clean_info); @@ -304,7 +250,6 @@ private: int set_sys_clean_info_stop(const share::ObBackupCleanInfo &backup_clean_info, ObISQLClient &trans); int try_clean_tenant_backup_dir(const ObBackupDataCleanTenant &clean_tenant); int clean_tenant_backup_dir(const uint64_t tenant_id, const ObBackupDataCleanElement &clean_element); - int clean_backup_tenant_info(const ObBackupDataCleanTenant &sys_clean_tenant, const common::ObIArray &normal_clean_tenants); int inner_clean_backup_tenant_info(const ObBackupDataCleanElement &clean_element, @@ -372,16 +317,9 @@ private: int set_tenant_clean_info_cancel(const share::ObBackupCleanInfo &clean_info); int set_normal_tenant_cancel(const uint64_t tenant_id, common::ObISQLClient &sys_tenant_trans); int set_deleted_tenant_cancel(const ObBackupCleanInfo &clean_info, common::ObISQLClient &sys_tenant_trans); - int get_sys_tenant_backup_dest(common::hash::ObHashSet &cluster_backup_dest_set); int do_scheduler_normal_tenant(share::ObBackupCleanInfo &clean_info, ObBackupDataCleanTenant &clean_tenant, common::ObIArray &task_infos, common::ObIArray &log_archive_infos); - int do_scheduler_deleted_tenant(share::ObBackupCleanInfo &clean_info, ObBackupDataCleanTenant &clean_tenant, - common::ObIArray &task_infos, - common::ObIArray &log_archive_infos); - int do_inner_scheduler_delete_tenant(const ObClusterBackupDest &cluster_backup_dest, - ObBackupDataCleanTenant &clean_tenant, common::ObIArray &task_infos, - common::ObIArray &log_archive_infos); int get_all_tenant_backup_infos(const share::ObBackupCleanInfo &clean_info, const ObSimpleBackupDataCleanTenant &simple_clean_tenant, common::ObISQLClient &trans, common::ObIArray &tenant_backup_infos, @@ -398,11 +336,6 @@ private: const ObSimpleBackupDataCleanTenant &simple_clean_tenant, common::ObISQLClient &trans, common::ObIArray &tenant_backup_infos, common::ObIArray &tenant_backup_log_infos); - int get_delete_backup_piece_infos(const share::ObBackupCleanInfo &clean_info, - const ObSimpleBackupDataCleanTenant &simple_clean_tenant, common::ObISQLClient &trans, - common::ObIArray &tenant_backup_infos, - common::ObIArray &tenant_backup_log_infos); - int get_tenant_backup_task_infos(const share::ObBackupCleanInfo &clean_info, const ObSimpleBackupDataCleanTenant &simple_clean_tenant, common::ObISQLClient &trans, common::ObIArray &tenant_infos); diff --git a/src/rootserver/ob_backup_data_clean_scheduler.cpp b/src/rootserver/ob_backup_data_clean_scheduler.cpp index 8f03c4f76a..2746d89c8e 100644 --- a/src/rootserver/ob_backup_data_clean_scheduler.cpp +++ b/src/rootserver/ob_backup_data_clean_scheduler.cpp @@ -479,206 +479,5 @@ int ObBackupDataCleanScheduler::schedule_sys_tenant_backup_data_clean() return ret; } -int ObBackupDataCleanScheduler::schedule_tenants_backup_data_clean(const common::ObIArray& tenant_ids) -{ - int ret = OB_SUCCESS; - ObBackupCleanInfo sys_clean_info; - ObMySQLTransaction trans; - const bool for_update = true; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean scheduler do not init", K(ret)); - } else if (tenant_ids.empty()) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("schedule get tenants backup get invalid argument", K(ret), K(tenant_ids)); - } else if (OB_FAIL(trans.start(sql_proxy_))) { - LOG_WARN("fail to start trans", K(ret)); - } else { - if (OB_FAIL(get_backup_clean_info(OB_SYS_TENANT_ID, for_update, trans, sys_clean_info))) { - LOG_WARN("failed to get backup clean info", K(ret), K(sys_clean_info)); - } else if ((is_cluster_clean_ && ObBackupCleanInfoStatus::PREPARE != sys_clean_info.status_) || - (!is_cluster_clean_ && ObBackupCleanInfoStatus::STOP != sys_clean_info.status_)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("sys backup info status is unexpected", K(ret), K(sys_clean_info)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < tenant_ids.count(); ++i) { - const uint64_t tenant_id = tenant_ids.at(i); - if (OB_SYS_TENANT_ID == tenant_id) { - // do nothing - } else if (OB_FAIL(schedule_tenant_backup_data_clean(tenant_id, trans))) { - LOG_WARN("failed to schedule tenant backup", K(ret), K(tenant_id)); - } - } - } - - if (OB_SUCC(ret)) { - if (OB_FAIL(trans.end(true /*commit*/))) { - OB_LOG(WARN, "failed to commit", K(ret)); - } - } else { - int tmp_ret = OB_SUCCESS; - if (OB_SUCCESS != (tmp_ret = trans.end(false /* commit*/))) { - OB_LOG(WARN, "failed to rollback trans", K(tmp_ret)); - } - } - } - return ret; -} - -int ObBackupDataCleanScheduler::schedule_tenant_backup_data_clean( - const uint64_t tenant_id, ObISQLClient& sys_tenant_trans) -{ - int ret = OB_SUCCESS; - ObBackupCleanInfo clean_info; - ObBackupCleanInfo dest_clean_info; - ObMySQLTransaction trans; - const bool for_update = true; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup scheduler do not init", K(ret)); - } else if (OB_SYS_TENANT_ID == tenant_id) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("tenant id should be sys tenant id", K(ret), K(tenant_id)); - } else if (OB_FAIL(trans.start(sql_proxy_))) { - LOG_WARN("fail to start trans", K(ret)); - } else { - if (OB_FAIL(get_backup_clean_info(tenant_id, for_update, trans, clean_info))) { - LOG_WARN("failed to get backup clean info", K(ret), K(tenant_id)); - } else if (ObBackupCleanInfoStatus::STOP != clean_info.status_) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("clean info status is unexpected", K(ret), K(clean_info)); - } else { - dest_clean_info = clean_info; - dest_clean_info.status_ = ObBackupCleanInfoStatus::DOING; - dest_clean_info.incarnation_ = OB_START_INCARNATION; - dest_clean_info.job_id_ = max_job_id_; - if (OB_FAIL(rootserver::ObBackupUtil::check_sys_clean_info_trans_alive(sys_tenant_trans))) { - LOG_WARN("failed to check sys tenant trans alive", K(ret), K(clean_info)); - } else if (OB_FAIL(set_backup_clean_info(tenant_id, dest_clean_info))) { - LOG_WARN("failed to set backup clean info", K(ret), K(tenant_id), K(dest_clean_info)); - } else if (OB_FAIL(update_backup_clean_info(clean_info, dest_clean_info, trans))) { - LOG_WARN("failed to update backup clean info", K(ret), K(clean_info), K(dest_clean_info)); - } - } - - if (OB_SUCC(ret)) { - if (OB_FAIL(trans.end(true /*commit*/))) { - OB_LOG(WARN, "failed to commit", K(ret)); - } - } else { - int tmp_ret = OB_SUCCESS; - if (OB_SUCCESS != (tmp_ret = trans.end(false /* commit*/))) { - OB_LOG(WARN, "failed to rollback trans", K(tmp_ret)); - } - } - } - return ret; -} - -int ObBackupDataCleanScheduler::start_backup_clean() -{ - int ret = OB_SUCCESS; - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean scheduler do not init", K(ret)); - } else if (!is_cluster_clean_) { - // do nothing - } else { - ObBackupCleanInfo clean_info; - ObBackupCleanInfo dest_clean_info; - ObMySQLTransaction trans; - const uint64_t tenant_id = OB_SYS_TENANT_ID; - const bool for_update = true; - if (OB_FAIL(trans.start(sql_proxy_))) { - LOG_WARN("fail to start trans", K(ret)); - } else { - if (OB_FAIL(get_backup_clean_info(tenant_id, for_update, trans, clean_info))) { - LOG_WARN("failed to get backup clean info", K(ret), K(clean_info)); - } else if (ObBackupCleanInfoStatus::PREPARE != clean_info.status_) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("tenant backup clean info status is unexpected", K(ret), K(clean_info)); - } else { - dest_clean_info = clean_info; - dest_clean_info.status_ = ObBackupCleanInfoStatus::PREPARE; - if (OB_FAIL(update_backup_clean_info(clean_info, dest_clean_info, trans))) { - LOG_WARN("failed to update backup clean info", K(ret), K(clean_info), K(dest_clean_info)); - } - } - - if (OB_SUCC(ret)) { - if (OB_FAIL(trans.end(true /*commit*/))) { - OB_LOG(WARN, "failed to commit", K(ret)); - } - } else { - int tmp_ret = OB_SUCCESS; - if (OB_SUCCESS != (tmp_ret = trans.end(false /* commit*/))) { - OB_LOG(WARN, "failed to rollback trans", K(tmp_ret)); - } - } - } - } - return ret; -} - -int ObBackupDataCleanScheduler::rollback_backup_clean_infos(const common::ObIArray& tenant_ids) -{ - int ret = OB_SUCCESS; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup scheduler do not init", K(ret)); - } else { - for (int64_t i = tenant_ids.count() - 1; OB_SUCC(ret) && i >= 0; --i) { - const uint64_t tenant_id = tenant_ids.at(i); - if (OB_FAIL(rollback_backup_clean_info(tenant_id))) { - LOG_WARN("failed to rollback backup info", K(ret), K(tenant_id)); - } - } - } - return ret; -} - -int ObBackupDataCleanScheduler::rollback_backup_clean_info(const uint64_t tenant_id) -{ - int ret = OB_SUCCESS; - ObBackupCleanInfo clean_info; - ObBackupCleanInfo dest_clean_info; - ObMySQLTransaction trans; - const bool for_update = true; - - if (!is_inited_) { - ret = OB_NOT_INIT; - LOG_WARN("backup data clean scheduler do not init", K(ret)); - } else if (OB_FAIL(trans.start(sql_proxy_))) { - LOG_WARN("fail to start trans", K(ret)); - } else { - if (OB_FAIL(get_backup_clean_info(tenant_id, for_update, trans, clean_info))) { - LOG_WARN("failed to get backup clean info", K(ret), K(tenant_id)); - } else if (ObBackupCleanInfoStatus::STOP == clean_info.status_) { - // do nothing - } else { - dest_clean_info.tenant_id_ = tenant_id; - dest_clean_info.status_ = ObBackupCleanInfoStatus::STOP; - if (OB_FAIL(update_backup_clean_info(clean_info, dest_clean_info, trans))) { - LOG_WARN("failed to update backup clean info", K(ret), K(clean_info), K(dest_clean_info)); - } - } - - if (OB_SUCC(ret)) { - if (OB_FAIL(trans.end(true /*commit*/))) { - OB_LOG(WARN, "failed to commit", K(ret)); - } - } else { - int tmp_ret = OB_SUCCESS; - if (OB_SUCCESS != (tmp_ret = trans.end(false /* commit*/))) { - OB_LOG(WARN, "failed to rollback trans", K(tmp_ret)); - } - } - } - return ret; -} - } // namespace rootserver } // namespace oceanbase diff --git a/src/rootserver/ob_backup_data_clean_scheduler.h b/src/rootserver/ob_backup_data_clean_scheduler.h index f9d1409cad..c75d0b8344 100644 --- a/src/rootserver/ob_backup_data_clean_scheduler.h +++ b/src/rootserver/ob_backup_data_clean_scheduler.h @@ -42,14 +42,7 @@ private: int get_tenant_ids(common::ObIArray& tenant_ids); int schedule_backup_data_clean(const common::ObIArray& tenant_ids); int schedule_sys_tenant_backup_data_clean(); - int schedule_tenants_backup_data_clean(const common::ObIArray& tenant_ids); - int schedule_tenant_backup_data_clean(const uint64_t tenant_id, common::ObISQLClient& sys_tenant_trans); - int set_backup_clean_info(const uint64_t tenant_id, share::ObBackupCleanInfo& clean_info); - int start_backup_clean(); - int rollback_backup_clean_infos(const common::ObIArray& tenant_ids); - int rollback_backup_clean_info(const uint64_t tenant_id); - // delete backup set need to know incarnation - int get_backup_incarnation(const uint64_t tenant_id, const int64_t backup_set_id); + int set_backup_clean_info(const uint64_t tenant_id, share::ObBackupCleanInfo &clean_info); private: bool is_inited_; -- GitLab