diff --git a/src/rootserver/backup/ob_backup_data_scheduler.cpp b/src/rootserver/backup/ob_backup_data_scheduler.cpp index 6a54055e07..2f9ad7318d 100644 --- a/src/rootserver/backup/ob_backup_data_scheduler.cpp +++ b/src/rootserver/backup/ob_backup_data_scheduler.cpp @@ -584,7 +584,7 @@ int ObBackupDataScheduler::start_tenant_backup_data_(const ObBackupJobAttr &job_ LOG_WARN("[DATA_BACKUP]failed to get next job id", K(ret)); } else if (OB_FAIL(get_next_backup_set_id(trans, new_job_attr.tenant_id_, new_job_attr.backup_set_id_))) { LOG_WARN("[DATA_BACKUP]failed to get next backup set id", K(ret)); - } else if (OB_FAIL(update_backup_type_(trans, new_job_attr.tenant_id_, new_job_attr.backup_set_id_, + } else if (OB_FAIL(update_backup_type_if_need_(trans, new_job_attr.tenant_id_, new_job_attr.backup_set_id_, new_job_attr.backup_path_, new_job_attr.backup_type_))) { LOG_WARN("[DATA_BACKUP]failed to update backup type", K(ret), K(new_job_attr)); } else if (OB_FAIL(new_job_attr.executor_tenant_id_.push_back(new_job_attr.tenant_id_))) { @@ -763,7 +763,7 @@ int ObBackupDataScheduler::get_next_backup_set_id(common::ObISQLClient &trans, c return ret; } -int ObBackupDataScheduler::update_backup_type_(common::ObISQLClient &trans, const uint64_t tenant_id, +int ObBackupDataScheduler::update_backup_type_if_need_(common::ObISQLClient &trans, const uint64_t tenant_id, const int64_t backup_set_id, const share::ObBackupPathString &backup_path, share::ObBackupType &backup_type) { // if backup type is inc backup but no prev backup set id. @@ -771,6 +771,8 @@ int ObBackupDataScheduler::update_backup_type_(common::ObISQLClient &trans, cons int ret = OB_SUCCESS; int64_t prev_full_backup_set_id = -1; int64_t pre_inc_backup_set_id = -1; + ObBackupSetFileDesc pre_backup_set_desc; + uint64_t data_version = 0; if (OB_FAIL(ObBackupSetFileOperator::get_prev_backup_set_id( trans, tenant_id, backup_set_id, backup_type, backup_path, prev_full_backup_set_id, pre_inc_backup_set_id))) { if (OB_ENTRY_NOT_EXIST == ret && backup_type.is_inc_backup()) { @@ -779,6 +781,32 @@ int ObBackupDataScheduler::update_backup_type_(common::ObISQLClient &trans, cons } else { LOG_WARN("fail to get prev backup set id", K(ret), K(tenant_id), K(backup_set_id)); } + } else if (backup_type.is_full_backup()) {// full backup no need to check prev backup set's compatible + } else if (OB_FAIL(ObBackupSetFileOperator::get_one_backup_set_file(trans, false, pre_inc_backup_set_id, 1, tenant_id, pre_backup_set_desc))) { + LOG_WARN("failed to get one backup set file", K(ret), K(pre_inc_backup_set_id), K(tenant_id)); + } else if (OB_FAIL(ObShareUtil::fetch_current_data_version(trans, tenant_id, data_version))) { + LOG_WARN("failed to get data version", K(ret), K(tenant_id)); + } else if (data_version != pre_backup_set_desc.tenant_compatible_) { + ret = OB_BACKUP_CAN_NOT_START; + int tmp_ret = OB_SUCCESS; + const int64_t USER_ERROR_MSG_LEN = 128; + char pre_compatible_buf[OB_INNER_TABLE_BACKUP_TASK_CLUSTER_FORMAT_LENGTH] = ""; + char cur_compatible_buf[OB_INNER_TABLE_BACKUP_TASK_CLUSTER_FORMAT_LENGTH] = ""; + char user_error_msg_buf[USER_ERROR_MSG_LEN] = ""; + int64_t pos = ObClusterVersion::get_instance().print_version_str( + pre_compatible_buf, OB_INNER_TABLE_BACKUP_TASK_CLUSTER_FORMAT_LENGTH, pre_backup_set_desc.tenant_compatible_); + pos = ObClusterVersion::get_instance().print_version_str( + cur_compatible_buf, OB_INNER_TABLE_BACKUP_TASK_CLUSTER_FORMAT_LENGTH, data_version); + if (OB_TMP_FAIL(databuff_printf(user_error_msg_buf, USER_ERROR_MSG_LEN, + "cross compatible incremental backup is not supported, " + "previous backup set compatible is %.*s, current compatible is %.*s", + static_cast(OB_INNER_TABLE_BACKUP_TASK_CLUSTER_FORMAT_LENGTH), pre_compatible_buf, + static_cast(OB_INNER_TABLE_BACKUP_TASK_CLUSTER_FORMAT_LENGTH), cur_compatible_buf))) { + LOG_WARN("failed to databuff printf", K(ret), K(tmp_ret)); + } + LOG_USER_ERROR(OB_BACKUP_CAN_NOT_START, user_error_msg_buf); + LOG_WARN("pre backup set's tenant compatible does not match, backup can't start", + K(ret), K(tenant_id), K(data_version), K(pre_backup_set_desc)); } return ret; } diff --git a/src/rootserver/backup/ob_backup_data_scheduler.h b/src/rootserver/backup/ob_backup_data_scheduler.h index ca475e10fe..76b01edd9b 100644 --- a/src/rootserver/backup/ob_backup_data_scheduler.h +++ b/src/rootserver/backup/ob_backup_data_scheduler.h @@ -77,7 +77,7 @@ private: int get_all_tenants_(const bool with_backup_dest, ObIArray &tenants); int start_tenant_backup_data_(const share::ObBackupJobAttr &job_attr); - int update_backup_type_(common::ObISQLClient &trans, const uint64_t tenant_id, const int64_t next_backup_set_id, + int update_backup_type_if_need_(common::ObISQLClient &trans, const uint64_t tenant_id, const int64_t next_backup_set_id, const share::ObBackupPathString &backup_path, share::ObBackupType &backup_type); int get_need_cancel_tenants_(const uint64_t tenant_id, const common::ObIArray &backup_tenant_ids, common::ObIArray &need_cancel_backup_tenants); diff --git a/src/rootserver/restore/ob_restore_scheduler.cpp b/src/rootserver/restore/ob_restore_scheduler.cpp index 023c5e961d..8cca013782 100644 --- a/src/rootserver/restore/ob_restore_scheduler.cpp +++ b/src/rootserver/restore/ob_restore_scheduler.cpp @@ -486,34 +486,27 @@ int ObRestoreService::fill_restore_statistics(const share::ObPhysicalRestoreJob restore_progress_info.key_.tenant_id_ = job_info.get_tenant_id(); restore_progress_info.restore_scn_ = job_info.get_restore_scn(); int64_t idx = job_info.get_multi_restore_path_list().get_backup_set_path_list().count() - 1; - const int64_t turn_id = 1;// first turn; - share::ObBackupDataType type; - type.set_minor_data_backup(); + ObBackupDataLSAttrDesc ls_info; if (idx < 0) { ret = OB_ERR_UNEXPECTED; LOG_WARN("invalid job info", K(ret), K(idx), K(job_info)); } else { storage::ObBackupDataStore store; storage::ObExternBackupSetInfoDesc backup_set_info; - storage::ObBackupDataTabletToLSDesc tablet_to_ls_info; const share::ObBackupSetPath &backup_set_path = job_info.get_multi_restore_path_list().get_backup_set_path_list().at(idx); if (OB_FAIL(store.init(backup_set_path.ptr()))) { LOG_WARN("fail to init backup data store", K(backup_set_path)); } else if (OB_FAIL(store.read_backup_set_info(backup_set_info))) { LOG_WARN("fail to read backup set info", K(ret)); - } else if (OB_FAIL(store.read_tablet_to_ls_info(turn_id, type, tablet_to_ls_info))) { - LOG_WARN("fail to read tablet to ls info", K(ret)); + } else if (OB_FAIL(store.read_ls_attr_info(backup_set_info.backup_set_file_.meta_turn_id_, ls_info))) { + LOG_WARN("fail to read ls attr info", K(ret)); } else { - restore_progress_info.ls_count_ = tablet_to_ls_info.tablet_to_ls_.count(); - ARRAY_FOREACH(tablet_to_ls_info.tablet_to_ls_, i) { - restore_progress_info.tablet_count_ += tablet_to_ls_info.tablet_to_ls_.at(i).tablet_id_list_.count(); - } + restore_progress_info.ls_count_ = ls_info.ls_attr_array_.count(); + restore_progress_info.tablet_count_ = backup_set_info.backup_set_file_.stats_.finish_tablet_count_; restore_progress_info.total_bytes_ = backup_set_info.backup_set_file_.stats_.output_bytes_; } } - - if (OB_FAIL(ret)) { - } else { + if (OB_SUCC(ret)) { share::ObRestorePersistHelper helper; if (OB_FAIL(helper.init(job_info.get_tenant_id()))) { LOG_WARN("fail to init heler", K(ret)); diff --git a/src/rootserver/restore/ob_restore_util.cpp b/src/rootserver/restore/ob_restore_util.cpp index 65198118d0..5994874d41 100644 --- a/src/rootserver/restore/ob_restore_util.cpp +++ b/src/rootserver/restore/ob_restore_util.cpp @@ -684,6 +684,7 @@ int ObRestoreUtil::do_fill_backup_info_( { int ret = OB_SUCCESS; storage::ObBackupDataStore store; + ObBackupDataLSAttrDesc ls_info; HEAP_VARS_2((ObExternBackupSetInfoDesc, backup_set_info), (ObExternTenantLocalityInfoDesc, locality_info)) { if (backup_set_path.is_empty()) { @@ -698,6 +699,8 @@ int ObRestoreUtil::do_fill_backup_info_( } else if (!backup_set_info.is_valid()) { ret = OB_ERR_UNEXPECTED; LOG_WARN("invalid backup set file", K(ret), K(backup_set_info)); + } else if (OB_FAIL(store.read_ls_attr_info(backup_set_info.backup_set_file_.meta_turn_id_, ls_info))) { + LOG_WARN("failed to read ls attr info", K(ret), K(backup_set_info)); } else if (OB_FAIL(check_backup_set_version_match_(backup_set_info.backup_set_file_))) { LOG_WARN("failed to check backup set version match", K(ret)); } else if (OB_FAIL(job.set_backup_tenant_name(locality_info.tenant_name_.ptr()))) { @@ -709,7 +712,13 @@ int ObRestoreUtil::do_fill_backup_info_( job.set_source_cluster_version(backup_set_info.backup_set_file_.cluster_version_); job.set_compat_mode(locality_info.compat_mode_); job.set_backup_tenant_id(backup_set_info.backup_set_file_.tenant_id_); - job.set_consistent_scn(backup_set_info.backup_set_file_.consistent_scn_); + // becuase of no consistent scn in 4.1.x backup set, using ls_info.backup_scn to set the restore consisitent scn + // ls_info.backup_scn is the default replayable scn when create restore tenant, + // so using it as the consistet scn can also make recovery service work normally + const SCN &scn = backup_set_info.backup_set_file_.tenant_compatible_ < DATA_VERSION_4_2_0_0 + ? ls_info.backup_scn_ + : backup_set_info.backup_set_file_.consistent_scn_; + job.set_consistent_scn(scn); } } return ret; diff --git a/src/share/backup/ob_backup_path.cpp b/src/share/backup/ob_backup_path.cpp index 24721d5530..ab810c2f6d 100755 --- a/src/share/backup/ob_backup_path.cpp +++ b/src/share/backup/ob_backup_path.cpp @@ -364,6 +364,20 @@ int ObBackupPath::join_data_info_turn(const share::ObBackupDataType &type, const return ret; } +int ObBackupPath::join_data_info_turn_v_4_1_x(const int64_t turn_id) +{ + int ret = OB_SUCCESS; + if (cur_pos_ <= 0) { + ret = OB_NOT_INIT; + LOG_WARN("not inited", K(ret), K(*this)); + } else if (OB_FAIL(databuff_printf(path_, sizeof(path_), cur_pos_, "/%s_%ld", OB_STR_DATA_INTO_TURN, turn_id))) { + LOG_WARN("failed to join macro block data file", K(ret), K(turn_id), K(*this)); + } else if (OB_FAIL(trim_right_backslash())) { + LOG_WARN("failed to trim right backslash", K(ret)); + } + return ret; +} + int ObBackupPath::join_meta_info_turn_and_retry(const int64_t turn_id, const int64_t retry_id) { int ret = OB_SUCCESS; @@ -1293,3 +1307,43 @@ int ObBackupPathUtil::construct_backup_complement_log_dest(const share::ObBackup } return ret; } + +// file:///obbackup/backup_set_1_full/infos/xxx_xxx_turn_1_retry_0/meta_index.obbak +int ObBackupPathUtilV_4_1::get_tenant_meta_index_backup_path(const share::ObBackupDest &backup_set_dest, + const ObBackupDataType &backup_data_type, const int64_t turn_id, const int64_t retry_id, + const bool is_sec_meta, ObBackupPath &path) +{ + int ret = OB_SUCCESS; + if (OB_FAIL(get_ls_info_data_info_dir_path(backup_set_dest, turn_id, path))) { + LOG_WARN("failed to get ls info dir path", K(ret), K(backup_set_dest)); + } else if (OB_FAIL(path.join_tenant_meta_index_file(backup_data_type, retry_id, is_sec_meta))) { + LOG_WARN("failed to join tenant macro range index file", K(ret), K(backup_data_type)); + } + return ret; +} +// file:///obbackup/backup_set_1_full/infos/data_info_turn_1/ +int ObBackupPathUtilV_4_1::get_ls_info_data_info_dir_path(const share::ObBackupDest &backup_set_dest, + const int64_t turn_id, share::ObBackupPath &backup_path) +{ + int ret = OB_SUCCESS; + if (OB_FAIL(ObBackupPathUtil::get_backup_set_dir_path(backup_set_dest, backup_path))) { + LOG_WARN("failed to get backup set dir path", K(ret), K(backup_set_dest)); + } else if (OB_FAIL(backup_path.join(ObString::make_string("infos"), ObBackupFileSuffix::NONE))) { + LOG_WARN("failed to join data", K(ret)); + } else if (OB_FAIL(backup_path.join_data_info_turn_v_4_1_x(turn_id))) { + LOG_WARN("failed to join info turn", K(ret)); + } + return ret; +} +// file:///obbackup/backup_set_1_full/infos/data_info_turn_1/tablet_to_ls_info.obbak +int ObBackupPathUtilV_4_1::get_backup_data_tablet_ls_info_path(const share::ObBackupDest &backup_set_dest, + const uint64_t turn_id, ObBackupPath &path) +{ + int ret = OB_SUCCESS; + if (OB_FAIL(get_ls_info_data_info_dir_path(backup_set_dest, turn_id, path))) { + LOG_WARN("failed to get ls info data info dir path", K(ret)); + } else if (OB_FAIL(path.join(OB_STR_TABLET_LOG_STREAM_INFO, ObBackupFileSuffix::BACKUP))) { + LOG_WARN("failed to join tablet_log_stream_info", K(ret)); + } + return ret; +} \ No newline at end of file diff --git a/src/share/backup/ob_backup_path.h b/src/share/backup/ob_backup_path.h index 937086bf5b..84fc948faf 100755 --- a/src/share/backup/ob_backup_path.h +++ b/src/share/backup/ob_backup_path.h @@ -51,6 +51,7 @@ public: int join_macro_data_file(const int64_t file_id); int join_tablet_info_file(const int64_t file_id); int join_data_info_turn(const share::ObBackupDataType &type, const int64_t turn_id); + int join_data_info_turn_v_4_1_x(const int64_t turn_id); int join_meta_info_turn_and_retry(const int64_t turn_id, const int64_t retry_id); int join_tenant_macro_range_index_file(const share::ObBackupDataType &type, const int64_t retry_id); int join_tenant_meta_index_file(const share::ObBackupDataType &type, const int64_t retry_id, const bool is_sec_meta); @@ -279,6 +280,18 @@ private: share::ObBackupPath &path); }; +struct ObBackupPathUtilV_4_1 +{ +// 4.0 and 4.1 old format backup path + static int get_tenant_meta_index_backup_path(const share::ObBackupDest &backup_set_dest, + const share::ObBackupDataType &backup_data_type, const int64_t turn_id, const int64_t retry_id, + const bool is_sec_meta, share::ObBackupPath &backup_path); + static int get_ls_info_data_info_dir_path(const share::ObBackupDest &backup_set_dest, + const int64_t turn_id, share::ObBackupPath &backup_path); + static int get_backup_data_tablet_ls_info_path(const share::ObBackupDest &backup_set_dest, + const uint64_t turn_id, ObBackupPath &path); +}; + }//share }//oceanbase #endif /* SRC_SHARE_BACKUP_OB_BACKUP_INFO_H_ */ diff --git a/src/storage/backup/ob_backup_data_store.cpp b/src/storage/backup/ob_backup_data_store.cpp index 936436e32d..33ff04daf0 100755 --- a/src/storage/backup/ob_backup_data_store.cpp +++ b/src/storage/backup/ob_backup_data_store.cpp @@ -1069,3 +1069,80 @@ int ObBackupDataStore::read_base_tablet_list(const share::ObLSID &ls_id, ObIArra } return ret; } + +int ObBackupDataStore::read_tablet_to_ls_info_v_4_1_x( + const int64_t turn_id, const ObLSID &ls_id, ObIArray &tablet_ids) +{ + int ret = OB_SUCCESS; + share::ObBackupPath path; + ObBackupPathString full_path; + ObBackupDataTabletToLSDesc tablet_to_ls_info; + if (!is_init()) { + ret = OB_NOT_INIT; + LOG_WARN("ObBackupDataStore not init", K(ret)); + } else if (OB_FAIL(ObBackupPathUtilV_4_1::get_backup_data_tablet_ls_info_path(backup_set_dest_, turn_id, path))) { + LOG_WARN("fail to get tenant ls attr info path", K(ret)); + } else if (OB_FAIL(full_path.assign(path.get_obstr()))) { + LOG_WARN("fail to assign full path", K(ret)); + } else if (OB_FAIL(read_single_file(full_path, tablet_to_ls_info))) { + LOG_WARN("failed to read single file", K(ret), K(full_path)); + } else if (!tablet_to_ls_info.is_valid()) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("invalid tablet to ls info", K(ret), K(tablet_to_ls_info)); + } + for (int i = 0; OB_SUCC(ret) && i < tablet_to_ls_info.tablet_to_ls_.count(); ++i) { + const ObBackupDataTabletToLSInfo &info = tablet_to_ls_info.tablet_to_ls_.at(i); + if (!info.is_valid()) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("invalid info", K(ret), K(info)); + } else if (info.ls_id_ == ls_id) { + if (OB_FAIL(append(tablet_ids, info.tablet_id_list_))) { + LOG_WARN("failed to append tablet ids", K(ret), K(info)); + } else { + break; + } + } + } + if (OB_FAIL(ret)) { + } else if (tablet_ids.empty()) { + ret = OB_ENTRY_NOT_EXIST; + LOG_WARN("read no tablet", K(ret), K(turn_id), K(ls_id), K(full_path)); + } + return ret; +} + +int ObBackupDataStore::read_deleted_tablet_info_v_4_1_x( + const ObLSID &ls_id, ObIArray &deleted_tablet_ids) +{ + int ret = OB_SUCCESS; + deleted_tablet_ids.reset(); + share::ObBackupPath path; + ObBackupPathString full_path; + ObBackupDeletedTabletToLSDesc deleted_tablet_info; + if (!is_init()) { + ret = OB_NOT_INIT; + LOG_WARN("ObBackupDataStore not init", K(ret)); + } else if (OB_FAIL(ObBackupPathUtil::get_deleted_tablet_info_path(backup_set_dest_, path))) { + LOG_WARN("fail to get tenant ls attr info path", K(ret)); + } else if (OB_FAIL(full_path.assign(path.get_obstr()))) { + LOG_WARN("fail to assign full path", K(ret)); + } else if (OB_FAIL(read_single_file(full_path, deleted_tablet_info))) { + if (OB_BACKUP_FILE_NOT_EXIST == ret) { + ret = OB_SUCCESS; + LOG_INFO("backup deleted file not exist", K(ret)); + } else { + LOG_WARN("failed to read single file", K(ret), K(full_path)); + } + } else { + for (int64_t i = 0; OB_SUCC(ret) && i < deleted_tablet_info.deleted_tablet_to_ls_.count(); ++i) { + const ObBackupDataTabletToLSInfo &info = deleted_tablet_info.deleted_tablet_to_ls_.at(i); + if (info.ls_id_ == ls_id) { + if (OB_FAIL(deleted_tablet_ids.assign(info.tablet_id_list_))) { + LOG_WARN("failed to assign", K(ret), K(info)); + } + break; + } + } + } + return ret; +} diff --git a/src/storage/backup/ob_backup_data_store.h b/src/storage/backup/ob_backup_data_store.h index 9bd327ce06..3611e4c3a4 100755 --- a/src/storage/backup/ob_backup_data_store.h +++ b/src/storage/backup/ob_backup_data_store.h @@ -312,6 +312,10 @@ public: int read_root_key_info(const uint64_t tenant_id); int read_base_tablet_list(const share::ObLSID &ls_id, ObIArray &tablet_id_array); +// 4.1 interface to get tablet to ls + int read_tablet_to_ls_info_v_4_1_x(const int64_t turn_id, const ObLSID &ls_id, ObIArray &tablet_ids); + int read_deleted_tablet_info_v_4_1_x(const ObLSID &ls_id, ObIArray &deleted_tablet_ids); + TO_STRING_KV(K_(backup_desc)); public: diff --git a/src/storage/backup/ob_backup_index_store.cpp b/src/storage/backup/ob_backup_index_store.cpp index 628c7cb35f..e9da2cee5b 100644 --- a/src/storage/backup/ob_backup_index_store.cpp +++ b/src/storage/backup/ob_backup_index_store.cpp @@ -1036,7 +1036,7 @@ int ObBackupIndexStoreWrapper::get_idx_(const share::ObBackupDataType &backup_da int ObRestoreMetaIndexStore::init(const ObBackupRestoreMode &mode, const ObBackupIndexStoreParam ¶m, const share::ObBackupDest &backup_dest, const share::ObBackupSetDesc &backup_set_desc, const bool is_sec_meta, - ObBackupIndexKVCache &index_kv_cache) + const uint64_t data_version, ObBackupIndexKVCache &index_kv_cache) { int ret = OB_SUCCESS; share::ObBackupPath backup_path; @@ -1060,6 +1060,7 @@ int ObRestoreMetaIndexStore::init(const ObBackupRestoreMode &mode, const ObBacku backup_data_type_ = param.backup_data_type_; index_kv_cache_ = &index_kv_cache; is_sec_meta_ = is_sec_meta; + data_version_ = data_version; if (OB_FAIL(get_backup_file_path(backup_path))) { LOG_WARN("failed to get backup file path", K(ret)); } else if (OB_FAIL(read_file_trailer_(backup_path.get_obstr(), backup_dest_.get_storage_info()))) { @@ -1075,7 +1076,12 @@ int ObRestoreMetaIndexStore::get_backup_file_path(share::ObBackupPath &backup_pa { int ret = OB_SUCCESS; if (is_tenant_level_) { - if (OB_FAIL(share::ObBackupPathUtil::get_tenant_meta_index_backup_path( + if (DATA_VERSION_4_2_0_0 > data_version_) { + if (OB_FAIL(share::ObBackupPathUtilV_4_1::get_tenant_meta_index_backup_path( + backup_dest_, backup_data_type_, turn_id_, retry_id_, is_sec_meta_, backup_path))) { + LOG_WARN("failed to get tenant meta index file path", K(ret), K_(backup_dest), K_(backup_data_type), K_(turn_id)); + } + } else if (OB_FAIL(share::ObBackupPathUtil::get_tenant_meta_index_backup_path( backup_dest_, backup_data_type_, turn_id_, retry_id_, is_sec_meta_, backup_path))) { LOG_WARN("failed to get tenant meta index file path", K(ret), K_(backup_dest), K_(backup_data_type), K_(turn_id)); @@ -1121,24 +1127,50 @@ int ObBackupMetaIndexStoreWrapper::init(const ObBackupRestoreMode &mode, const O } else if (backup_data_type.is_sys_backup() && !init_sys_tablet_index_store) { continue; } + if (OB_FAIL(ret)) { + } else if (backup_set_info.tenant_compatible_ < DATA_VERSION_4_2_0_0) { + // In 4.1.x, sys tablet only has 1 backup turn. + // minor and major both use the data turn id. + if (backup_data_type.is_sys_backup() && OB_FALSE_IT(share_param.turn_id_ = 1)) { + } else if (!backup_data_type.is_sys_backup() && OB_FALSE_IT(share_param.turn_id_ = backup_set_info.data_turn_id_)) { + } } else if (backup_data_type.is_minor_backup() && OB_FALSE_IT(share_param.turn_id_ = backup_set_info.minor_turn_id_)) { } else if (backup_data_type.is_major_backup() && OB_FALSE_IT(share_param.turn_id_ = backup_set_info.major_turn_id_)) { + } + + if (OB_SUCC(ret) && !backup_data_type.is_sys_backup()) { + if (backup_set_info.tenant_compatible_ < DATA_VERSION_4_2_0_0) { + if (OB_FAIL(get_tenant_meta_index_retry_id_v_4_1_x_( + backup_dest, backup_data_type, share_param.turn_id_, is_sec_meta, retry_id))) { + LOG_WARN("failed to get tenant meta index retry id", K(ret)); + } + } else if (OB_FAIL(get_tenant_meta_index_retry_id_( + backup_dest, backup_data_type, share_param.turn_id_, is_sec_meta, retry_id))) { + LOG_WARN("failed to get tenant meta index retry id", K(ret)); + } + + if (OB_SUCC(ret)) { + share_param.retry_id_ = retry_id; + } + } + + if (OB_FAIL(ret)) { } else if (OB_FAIL(get_index_store_(backup_data_type, store))) { LOG_WARN("failed to get index store", K(ret), K(backup_data_type)); } else if (OB_ISNULL(store)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("failed to get index store", K(ret), K(backup_data_type)); - } else if (!backup_data_type.is_sys_backup() && OB_FAIL(get_tenant_meta_index_retry_id_( - backup_dest, backup_data_type, share_param.turn_id_, is_sec_meta, retry_id))) { - LOG_WARN("failed to get tenant meta index retry id", K(ret)); } else { share_param.backup_data_type_ = backup_data_type; share_param.is_tenant_level_ = backup_data_type.is_sys_backup() ? false : true; - if (!backup_data_type.is_sys_backup()) { - share_param.retry_id_ = retry_id; - } - if (OB_FAIL(store->init(mode, share_param, backup_dest, backup_set_desc, is_sec_meta, index_kv_cache))) { + if (OB_FAIL(store->init(mode, + share_param, + backup_dest, + backup_set_desc, + is_sec_meta, + backup_set_info.tenant_compatible_, + index_kv_cache))) { LOG_WARN("failed to init store", K(ret), K(i)); } } @@ -1208,6 +1240,26 @@ int ObBackupMetaIndexStoreWrapper::get_tenant_meta_index_retry_id_( return ret; } +int ObBackupMetaIndexStoreWrapper::get_tenant_meta_index_retry_id_v_4_1_x_( + const share::ObBackupDest &backup_dest, const share::ObBackupDataType &backup_data_type, + const int64_t turn_id, const int64_t is_sec_meta, int64_t &retry_id) +{ + int ret = OB_SUCCESS; + ObBackupTenantIndexRetryIDGetter retry_id_getter; + const bool is_restore = true; + const bool is_macro_index = false; + if (!backup_dest.is_valid() || !backup_data_type.is_valid() || turn_id <= 0) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("get invalid args", K(ret), K(backup_dest), K(backup_data_type), K(turn_id)); + } else if (OB_FAIL(retry_id_getter.init(backup_dest, backup_data_type, + turn_id, is_restore, is_macro_index, is_sec_meta))) { + LOG_WARN("failed to init retry id getter", K(ret), K(backup_dest), K(backup_data_type), K(turn_id)); + } else if (OB_FAIL(retry_id_getter.get_max_retry_id_v_4_1_x(retry_id))) { + LOG_WARN("failed to get max retry id", K(ret)); + } + return ret; +} + /* ObBackupMacroBlockIndexStoreWrapper */ ObBackupMacroBlockIndexStoreWrapper::ObBackupMacroBlockIndexStoreWrapper() @@ -1386,6 +1438,35 @@ int ObBackupTenantIndexRetryIDGetter::get_max_retry_id(int64_t &retry_id) return ret; } +int ObBackupTenantIndexRetryIDGetter::get_max_retry_id_v_4_1_x(int64_t &retry_id) +{ + int ret = OB_SUCCESS; + retry_id = 0; + ObArray id_list; + const char *file_name_prefix = NULL; + share::ObBackupPath backup_path; + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + LOG_WARN("retry id getter not init", K(ret)); + } else if (OB_FAIL(get_tenant_index_file_name_(file_name_prefix))) { + LOG_WARN("failed to get tenant index file name", K(ret)); + } else if (is_restore_ && + OB_FAIL(share::ObBackupPathUtilV_4_1::get_ls_info_data_info_dir_path(backup_dest_, + turn_id_, + backup_path))) { + LOG_WARN("failed to get ls info data info dir path", + K(ret), K_(backup_dest), K_(backup_data_type), K_(backup_set_desc), K_(turn_id)); + } else if (OB_FAIL(list_files_(backup_path, backup_dest_.get_storage_info(), file_name_prefix, id_list))) { + LOG_WARN("failed to list files", K(ret), K(backup_path), K(backup_dest_), K(file_name_prefix)); + } else if (OB_FAIL(find_largest_id_(id_list, retry_id))) { + LOG_WARN("failed to find largest id", K(ret), K(id_list)); + } else { + LOG_INFO("get max tenant index retry id", K_(backup_dest), K_(backup_data_type), + K_(turn_id), K_(is_restore), K_(is_macro_index), K_(is_sec_meta), K(retry_id)); + } + return ret; +} + int ObBackupTenantIndexRetryIDGetter::get_ls_info_data_info_dir_path_(ObBackupPath &backup_path) { int ret = OB_SUCCESS; diff --git a/src/storage/backup/ob_backup_index_store.h b/src/storage/backup/ob_backup_index_store.h index 388cf4d500..c1be21cba3 100644 --- a/src/storage/backup/ob_backup_index_store.h +++ b/src/storage/backup/ob_backup_index_store.h @@ -175,14 +175,14 @@ private: class ObRestoreMetaIndexStore final : public ObBackupMetaIndexStore { public: - ObRestoreMetaIndexStore() {} + ObRestoreMetaIndexStore(): ObBackupMetaIndexStore(), data_version_(0) {} virtual ~ObRestoreMetaIndexStore() {} int init(const ObBackupRestoreMode &mode, const ObBackupIndexStoreParam ¶m, const share::ObBackupDest &backup_dest, const share::ObBackupSetDesc &backup_set_desc, const bool is_sec_meta, - ObBackupIndexKVCache &index_kv_cache); - + const uint64_t data_version, ObBackupIndexKVCache &index_kv_cache); virtual int get_backup_file_path(share::ObBackupPath &backup_path) const override; private: + uint64_t data_version_; DISALLOW_COPY_AND_ASSIGN(ObRestoreMetaIndexStore); }; @@ -215,6 +215,8 @@ private: int get_index_store_(const share::ObBackupDataType &type, ObRestoreMetaIndexStore *&index_store); int get_tenant_meta_index_retry_id_(const share::ObBackupDest &backup_dest, const share::ObBackupDataType &backup_data_type, const int64_t turn_id, const int64_t is_sec_meta, int64_t &retry_id); + int get_tenant_meta_index_retry_id_v_4_1_x_(const share::ObBackupDest &backup_dest, const share::ObBackupDataType &backup_data_type, + const int64_t turn_id, const int64_t is_sec_meta, int64_t &retry_id); private: bool is_inited_; @@ -256,6 +258,7 @@ public: int init(const share::ObBackupDest &backup_dest, const share::ObBackupDataType &backup_data_type, const int64_t turn_id, const bool is_restore, const bool is_macro_index, const bool is_sec_meta); int get_max_retry_id(int64_t &retry_id); + int get_max_retry_id_v_4_1_x(int64_t &retry_id); private: int get_ls_info_data_info_dir_path_(share::ObBackupPath &backup_path); diff --git a/src/storage/high_availability/ob_ls_restore.cpp b/src/storage/high_availability/ob_ls_restore.cpp index c59b0c1029..8ffc398969 100644 --- a/src/storage/high_availability/ob_ls_restore.cpp +++ b/src/storage/high_availability/ob_ls_restore.cpp @@ -904,12 +904,23 @@ int ObStartLSRestoreTask::alloc_copy_ls_view_reader_(ObICopyLSViewInfoReader *&r if (ctx_->arg_.is_leader_) { ObCopyLSViewInfoRestoreReader *restore_reader = nullptr; - if (FALSE_IT(buf = mtl_malloc(sizeof(ObCopyLSViewInfoRestoreReader), "CpLSViewRestore"))) { + ObIDagNet *dag_net = nullptr; + ObLSRestoreDagNet *ls_restore_dag_net = nullptr; + + if (FALSE_IT(dag_net = this->get_dag()->get_dag_net())) { + } else if (OB_ISNULL(dag_net)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("dag net should not be NULL", K(ret), KP(dag_net)); + } else if (ObDagNetType::DAG_NET_TYPE_RESTORE != dag_net->get_type()) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("dag net type is unexpected", K(ret), KPC(dag_net)); + } else if (FALSE_IT(ls_restore_dag_net = static_cast(dag_net))) { + } else if (FALSE_IT(buf = mtl_malloc(sizeof(ObCopyLSViewInfoRestoreReader), "CpLSViewRestore"))) { } else if (OB_ISNULL(buf)) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("failed to alloc memory", K(ret)); } else if (FALSE_IT(restore_reader = new (buf) ObCopyLSViewInfoRestoreReader())) { - } else if (OB_FAIL(restore_reader->init(ctx_->arg_.ls_id_, ctx_->arg_.restore_base_info_))) { + } else if (OB_FAIL(restore_reader->init(ctx_->arg_.ls_id_, ctx_->arg_.restore_base_info_, ls_restore_dag_net->get_meta_index_store()))) { LOG_WARN("failed to init tablet restore reader", K(ret), KPC(ctx_)); } else { reader = restore_reader; diff --git a/src/storage/high_availability/ob_storage_ha_reader.cpp b/src/storage/high_availability/ob_storage_ha_reader.cpp index 36c976b116..4dd4867301 100644 --- a/src/storage/high_availability/ob_storage_ha_reader.cpp +++ b/src/storage/high_availability/ob_storage_ha_reader.cpp @@ -2652,7 +2652,8 @@ ObCopyLSViewInfoRestoreReader::ObCopyLSViewInfoRestoreReader() int ObCopyLSViewInfoRestoreReader::init( const share::ObLSID &ls_id, - const ObRestoreBaseInfo &restore_base_info) + const ObRestoreBaseInfo &restore_base_info, + backup::ObBackupMetaIndexStoreWrapper *meta_index_store) { int ret = OB_SUCCESS; if (IS_INIT) { @@ -2662,7 +2663,11 @@ int ObCopyLSViewInfoRestoreReader::init( || OB_UNLIKELY(!restore_base_info.is_valid())) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid argument", K(ret), K(ls_id), K(restore_base_info)); - } else if (OB_FAIL(reader_.init(restore_base_info.backup_dest_, ls_id))) { + } else if (restore_base_info.backup_data_version_ >= DATA_VERSION_4_2_0_0 + && OB_FAIL(reader_.init(restore_base_info.backup_dest_, ls_id))) { + LOG_WARN("fail to init reader", K(ret), K(restore_base_info), K(ls_id)); + } else if (restore_base_info.backup_data_version_ < DATA_VERSION_4_2_0_0 + && OB_FAIL(init_for_4_1_x_(ls_id, restore_base_info, *meta_index_store))) { LOG_WARN("fail to init reader", K(ret), K(restore_base_info), K(ls_id)); } else { ls_id_ = ls_id; @@ -2703,11 +2708,19 @@ int ObCopyLSViewInfoRestoreReader::get_next_tablet_info( if (IS_NOT_INIT) { ret = OB_NOT_INIT; LOG_WARN("ObCopyLSViewInfoRestoreReader not init", K(ret)); + } else if (restore_base_info_->backup_data_version_ < DATA_VERSION_4_2_0_0) { + if (OB_FAIL(reader_41x_.fetch_tablet_info(tablet_info))) { + if (OB_ITER_END != ret) { + LOG_WARN("failed to get next tablet meta", K(ret)); + } + } } else if (OB_FAIL(reader_.get_next(tablet_info.param_))) { if (OB_ITER_END != ret) { LOG_WARN("failed to get next tablet meta", K(ret)); } - } else { + } + + if (OB_SUCC(ret)) { tablet_info.data_size_ = 0; tablet_info.status_ = ObCopyTabletStatus::TABLET_EXIST; tablet_info.tablet_id_ = tablet_info.param_.tablet_id_; @@ -2716,5 +2729,30 @@ int ObCopyLSViewInfoRestoreReader::get_next_tablet_info( return ret; } + +int ObCopyLSViewInfoRestoreReader::init_for_4_1_x_( + const share::ObLSID &ls_id, + const ObRestoreBaseInfo &restore_base_info, + backup::ObBackupMetaIndexStoreWrapper &meta_index_store) +{ + int ret = OB_SUCCESS; + ObBackupDataStore store; + ObArray tablet_id_array; + ObArray deleted_tablet_id_array; + ObArray tablet_need_restore_array; + const int64_t base_turn_id = 1; // for restore, read all tablet from turn 1 + if (OB_FAIL(store.init(restore_base_info.backup_dest_))) { + LOG_WARN("failed to init backup data store", K(ret)); + } else if (OB_FAIL(store.read_tablet_to_ls_info_v_4_1_x(base_turn_id, ls_id, tablet_id_array))) { + LOG_WARN("failed to read tablet to ls info from 4_1_x backup set", K(ret), K(ls_id)); + } else if (OB_FAIL(store.read_deleted_tablet_info_v_4_1_x(ls_id, deleted_tablet_id_array))) { + LOG_WARN("failed to read deleted tablet info from 4_1_x backup set", K(ret), K(ls_id)); + } else if (OB_FAIL(get_difference(tablet_id_array, deleted_tablet_id_array, tablet_need_restore_array))) { + LOG_WARN("failed to get difference", K(ret), K(tablet_id_array), K(deleted_tablet_id_array)); + } else if (OB_FAIL(reader_41x_.init(restore_base_info, tablet_need_restore_array, meta_index_store))) { + LOG_WARN("failed to init copy tablet info restore reader", K(ret), K(restore_base_info)); + } + return ret; +} } } diff --git a/src/storage/high_availability/ob_storage_ha_reader.h b/src/storage/high_availability/ob_storage_ha_reader.h index 0120042c4d..7214ef7384 100644 --- a/src/storage/high_availability/ob_storage_ha_reader.h +++ b/src/storage/high_availability/ob_storage_ha_reader.h @@ -695,7 +695,8 @@ public: virtual ~ObCopyLSViewInfoRestoreReader() {} int init( const share::ObLSID &ls_id, - const ObRestoreBaseInfo &restore_base_info); + const ObRestoreBaseInfo &restore_base_info, + backup::ObBackupMetaIndexStoreWrapper *meta_index_store); Type get_type() const override { @@ -707,12 +708,17 @@ public: int get_next_tablet_info( obrpc::ObCopyTabletInfo &tablet_info) override; +private: + int init_for_4_1_x_(const share::ObLSID &ls_id, + const ObRestoreBaseInfo &restore_base_info, + backup::ObBackupMetaIndexStoreWrapper &meta_index_store); private: bool is_inited_; share::ObLSID ls_id_; const ObRestoreBaseInfo *restore_base_info_; backup::ObExternTabletMetaReader reader_; + ObCopyTabletInfoRestoreReader reader_41x_; // only used by 4.1 DISALLOW_COPY_AND_ASSIGN(ObCopyLSViewInfoRestoreReader); }; diff --git a/src/storage/high_availability/ob_storage_restore_struct.cpp b/src/storage/high_availability/ob_storage_restore_struct.cpp index 521d4401de..ce697843c8 100644 --- a/src/storage/high_availability/ob_storage_restore_struct.cpp +++ b/src/storage/high_availability/ob_storage_restore_struct.cpp @@ -23,6 +23,7 @@ namespace storage ObRestoreBaseInfo::ObRestoreBaseInfo() : restore_scn_(), backup_cluster_version_(0), + backup_data_version_(0), backup_dest_(), backup_set_list_() { @@ -32,6 +33,7 @@ void ObRestoreBaseInfo::reset() { restore_scn_.reset(); backup_cluster_version_ = 0; + backup_data_version_ = 0; backup_dest_.reset(); backup_set_list_.reset(); } @@ -40,6 +42,7 @@ bool ObRestoreBaseInfo::is_valid() const { return restore_scn_.is_valid() && backup_cluster_version_ > 0 + && backup_data_version_ > 0 && backup_dest_.is_valid() && !backup_set_list_.empty(); //backup piece list can be empty @@ -55,6 +58,7 @@ int ObRestoreBaseInfo::assign(const ObRestoreBaseInfo &restore_base_info) } else { restore_scn_ = restore_base_info.restore_scn_; backup_cluster_version_ = restore_base_info.backup_cluster_version_; + backup_data_version_ = restore_base_info.backup_data_version_; if (OB_FAIL(backup_dest_.deep_copy(restore_base_info.backup_dest_))) { LOG_WARN("failed to set backup dest", K(ret), K(restore_base_info)); } else if (OB_FAIL(backup_set_list_.assign(restore_base_info.backup_set_list_))) { @@ -75,6 +79,7 @@ int ObRestoreBaseInfo::copy_from(const ObTenantRestoreCtx &restore_arg) idx = restore_arg.get_backup_set_list().count() - 1; restore_scn_ = restore_arg.get_restore_scn(); backup_cluster_version_ = restore_arg.get_backup_cluster_version(); + backup_data_version_ = restore_arg.get_backup_data_version(); backup_dest_.reset(); backup_set_list_.reset(); if (OB_FAIL(backup_dest_.set(restore_arg.get_backup_set_list().at(idx).backup_set_path_))) { diff --git a/src/storage/high_availability/ob_storage_restore_struct.h b/src/storage/high_availability/ob_storage_restore_struct.h index d44b5506a5..7b0922f5c9 100644 --- a/src/storage/high_availability/ob_storage_restore_struct.h +++ b/src/storage/high_availability/ob_storage_restore_struct.h @@ -44,11 +44,13 @@ struct ObRestoreBaseInfo VIRTUAL_TO_STRING_KV( K_(restore_scn), K_(backup_cluster_version), + K_(backup_data_version), K_(backup_dest), K_(backup_set_list)); share::SCN restore_scn_; - int64_t backup_cluster_version_; + uint64_t backup_cluster_version_; + uint64_t backup_data_version_; share::ObBackupDest backup_dest_; common::ObArray backup_set_list_; }; diff --git a/src/storage/restore/ob_ls_restore_args.cpp b/src/storage/restore/ob_ls_restore_args.cpp index 4ee48f01fe..7749e86360 100644 --- a/src/storage/restore/ob_ls_restore_args.cpp +++ b/src/storage/restore/ob_ls_restore_args.cpp @@ -23,6 +23,7 @@ ObTenantRestoreCtx::ObTenantRestoreCtx() consistent_scn_(), tenant_id_(0), backup_cluster_version_(0), + backup_data_version_(0), backup_set_list_(), backup_piece_list_() { @@ -54,6 +55,7 @@ int ObTenantRestoreCtx::assign(const ObTenantRestoreCtx &args) consistent_scn_ = args.get_consistent_scn(); tenant_id_ = args.get_tenant_id(); backup_cluster_version_ = args.get_backup_cluster_version(); + backup_data_version_ = args.get_backup_data_version(); } return ret; } \ No newline at end of file diff --git a/src/storage/restore/ob_ls_restore_args.h b/src/storage/restore/ob_ls_restore_args.h index f1c864ca2f..3ea0508654 100644 --- a/src/storage/restore/ob_ls_restore_args.h +++ b/src/storage/restore/ob_ls_restore_args.h @@ -39,7 +39,8 @@ struct ObTenantRestoreCtx const share::SCN &get_restore_scn() const { return restore_scn_; } const share::SCN &get_consistent_scn() const { return consistent_scn_; } uint64_t get_tenant_id() const { return tenant_id_; } - int64_t get_backup_cluster_version() const { return backup_cluster_version_; } + uint64_t get_backup_cluster_version() const { return backup_cluster_version_; } + uint64_t get_backup_data_version() const { return backup_data_version_; } const common::ObArray &get_backup_set_list() const { return backup_set_list_; } const common::ObArray &get_backup_piece_list() const { return backup_piece_list_; } TO_STRING_KV( @@ -49,6 +50,7 @@ struct ObTenantRestoreCtx K_(consistent_scn), K_(tenant_id), K_(backup_cluster_version), + K_(backup_data_version), K_(backup_set_list), K_(backup_piece_list)); @@ -57,7 +59,8 @@ struct ObTenantRestoreCtx share::SCN restore_scn_; // restore end scn share::SCN consistent_scn_; uint64_t tenant_id_; - int64_t backup_cluster_version_; + uint64_t backup_cluster_version_; + uint64_t backup_data_version_; // every set path is integral. common::ObArray backup_set_list_; // every piece path is integral. diff --git a/src/storage/restore/ob_ls_restore_handler.cpp b/src/storage/restore/ob_ls_restore_handler.cpp index 75835fba99..5c56a706e5 100644 --- a/src/storage/restore/ob_ls_restore_handler.cpp +++ b/src/storage/restore/ob_ls_restore_handler.cpp @@ -1597,6 +1597,7 @@ int ObLSRestoreHandler::fill_restore_arg_() ls_restore_arg_.restore_scn_ = job_info.get_restore_scn(); ls_restore_arg_.consistent_scn_ = job_info.get_consistent_scn(); ls_restore_arg_.backup_cluster_version_ = job_info.get_source_cluster_version(); + ls_restore_arg_.backup_data_version_ = job_info.get_source_data_version(); ls_restore_arg_.backup_set_list_.reset(); ls_restore_arg_.backup_piece_list_.reset(); if (OB_FAIL(ls_restore_arg_.backup_piece_list_.assign(