From 47044f346e373850c8352e4a573f57943dc81eb8 Mon Sep 17 00:00:00 2001 From: godyangfight Date: Thu, 3 Mar 2022 14:46:14 +0800 Subject: [PATCH] Fix 2277 backup 320 restore backup snapshot failed bug --- .../restore/ob_restore_scheduler.cpp | 4 ++ src/share/backup/ob_backup_info_mgr.cpp | 49 ++++++++++++++----- src/share/backup/ob_backup_info_mgr.h | 5 +- .../backup/ob_multi_backup_dest_util.cpp | 31 +++++------- src/share/backup/ob_multi_backup_dest_util.h | 2 - 5 files changed, 55 insertions(+), 36 deletions(-) diff --git a/src/rootserver/restore/ob_restore_scheduler.cpp b/src/rootserver/restore/ob_restore_scheduler.cpp index 784299429..c1794e320 100644 --- a/src/rootserver/restore/ob_restore_scheduler.cpp +++ b/src/rootserver/restore/ob_restore_scheduler.cpp @@ -469,6 +469,10 @@ int ObRestoreScheduler::fill_backup_info(ObPhysicalRestoreJob &job, ObCreateTena // fill restore_pkeys/restore_log_pkeys if (OB_FAIL(arg.restore_pkeys_.assign(backup_info.sys_pg_key_list_))) { LOG_WARN("fail to assign pkeys", KR(ret), K(job)); + } else if (backup_info.snapshot_version_ == param.restore_timestamp_ && + backup_info.physical_restore_info_.cluster_version_ > CLUSTER_VERSION_3000) { + LOG_INFO("backup snapshot equal to restore timestamp, no need get pkeys from log", + K(backup_info), K(param.restore_timestamp_)); } else if (OB_FAIL(fill_pkeys_for_physical_restore_log(job, arg))) { LOG_WARN("fail to fill pkeys for physical restore log", KR(ret), K(arg)); } diff --git a/src/share/backup/ob_backup_info_mgr.cpp b/src/share/backup/ob_backup_info_mgr.cpp index 26668175b..fdb7923b3 100644 --- a/src/share/backup/ob_backup_info_mgr.cpp +++ b/src/share/backup/ob_backup_info_mgr.cpp @@ -1046,6 +1046,7 @@ int ObRestoreBackupInfoUtil::get_restore_backup_info_v1_( const int64_t restore_timestamp = param.restore_timestamp_; const char *passwd_array = param.passwd_array_; ObFakeBackupLeaseService fake_backup_lease; + bool is_snapshot_restore = false; if (OB_ISNULL(backup_dest) || OB_ISNULL(backup_cluster_name) || cluster_id <= 0 || incarnation < 0 || OB_ISNULL(backup_tenant_name) || restore_timestamp <= 0 || OB_ISNULL(passwd_array)) { @@ -1079,6 +1080,13 @@ int ObRestoreBackupInfoUtil::get_restore_backup_info_v1_( LOG_WARN("failed to init backup info mgr", K(ret), K(dest), K(tenant_info)); } else if (OB_FAIL(backup_info_mgr.find_backup_info(restore_timestamp, passwd_array, backup_info))) { LOG_WARN("failed to find backup info", K(ret), K(restore_timestamp), K(tenant_info)); + } else if (OB_FAIL(check_is_snapshot_restore(backup_info.backup_snapshot_version_, + restore_timestamp, + backup_info.cluster_version_, + is_snapshot_restore))) { + LOG_WARN("failed to check is snapshot restore", K(ret), K(backup_info), K(restore_timestamp)); + } else if (is_snapshot_restore) { + LOG_INFO("backup info backup snapshot version equal to restore timestamp", K(backup_info), K(restore_timestamp)); } else if (OB_FAIL(log_archive_backup_info_mgr.read_extern_log_archive_backup_info( dest, tenant_info.tenant_id_, log_archive_backup_info))) { LOG_WARN("failed to read extern log archive backup info", K(ret), K(dest), K(tenant_info)); @@ -1154,7 +1162,10 @@ int ObRestoreBackupInfoUtil::get_restore_backup_info_v2_( if (OB_FAIL( inner_get_restore_backup_set_info_(param, backup_set_info, tenant_locality_info, info.sys_pg_key_list_))) { LOG_WARN("failed to inner get restore backup set info", K(ret)); - } else if (OB_FAIL(check_is_snapshot_restore_(param, backup_set_info, is_snapshot_restore))) { + } else if (OB_FAIL(check_is_snapshot_restore(backup_set_info.snapshot_version_, + param.restore_timestamp_, + backup_set_info.cluster_version_, + is_snapshot_restore))) { LOG_WARN("failed to check is snapshot backup", K(ret), K(backup_set_info)); } else if (!is_snapshot_restore && OB_FAIL(inner_get_restore_backup_piece_info_(param, piece_info))) { LOG_WARN("failed to inner get restore backup piece info", K(ret)); @@ -1190,18 +1201,6 @@ int ObRestoreBackupInfoUtil::get_restore_backup_info_v2_( return ret; } -int ObRestoreBackupInfoUtil::check_is_snapshot_restore_( - const GetRestoreBackupInfoParam ¶m, const ObBackupSetFileInfo &backup_set_info, bool &is_snapshot_restore) -{ - int ret = OB_SUCCESS; - is_snapshot_restore = false; - if (param.backup_piece_path_list_.empty() && !param.backup_set_path_list_.empty()) { - is_snapshot_restore = backup_set_info.snapshot_version_ == param.restore_timestamp_; - LOG_INFO("check is snapshot backup", K(backup_set_info.snapshot_version_), K(param.restore_timestamp_)); - } - return ret; -} - int ObRestoreBackupInfoUtil::inner_get_restore_backup_set_info_(const GetRestoreBackupInfoParam ¶m, ObBackupSetFileInfo &backup_set_info, ObExternTenantLocalityInfo &tenant_locality_info, common::ObIArray &sys_pg_key_list) @@ -1266,6 +1265,30 @@ int ObRestoreBackupInfoUtil::get_restore_sys_table_ids( return OB_SUCCESS; } +int ObRestoreBackupInfoUtil::check_is_snapshot_restore(const int64_t backup_snapshot, const int64_t restore_timestamp, + const uint64_t cluster_version, bool &is_snapshot_restore) +{ + int ret = OB_SUCCESS; + is_snapshot_restore = false; + + if (backup_snapshot <= 0 || restore_timestamp <= 0 || 0 == cluster_version) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("check is restore snapshot restore get invalid argument", + K(ret), + K(backup_snapshot), + K(restore_timestamp), + K(cluster_version)); + } else { + is_snapshot_restore = backup_snapshot == restore_timestamp && cluster_version > CLUSTER_VERSION_3000; + } + LOG_INFO("check is snapshot restore", + K(is_snapshot_restore), + K(backup_snapshot), + K(restore_timestamp), + K(cluster_version)); + return ret; +} + ObRestoreFatalErrorReporter &ObRestoreFatalErrorReporter::get_instance() { static ObRestoreFatalErrorReporter reporter; diff --git a/src/share/backup/ob_backup_info_mgr.h b/src/share/backup/ob_backup_info_mgr.h index d87d13fb5..069297915 100644 --- a/src/share/backup/ob_backup_info_mgr.h +++ b/src/share/backup/ob_backup_info_mgr.h @@ -165,13 +165,14 @@ public: static int get_restore_sys_table_ids( const ObPhysicalRestoreInfo &info, common::ObIArray &pkey_list); + static int check_is_snapshot_restore(const int64_t backup_snapshot, const int64_t restore_timestamp, + const uint64_t cluster_version, bool &is_snapshot_restore); + private: // get info from cluster backup dest level static int get_restore_backup_info_v1_(const GetRestoreBackupInfoParam ¶m, ObRestoreBackupInfo &info); // get info from simple path level static int get_restore_backup_info_v2_(const GetRestoreBackupInfoParam ¶m, ObRestoreBackupInfo &info); - static int check_is_snapshot_restore_( - const GetRestoreBackupInfoParam ¶m, const ObBackupSetFileInfo &backup_set_info, bool &is_snapshot_restore); static int inner_get_restore_backup_set_info_(const GetRestoreBackupInfoParam ¶m, ObBackupSetFileInfo &backup_set_info, ObExternTenantLocalityInfo &tenant_locality_info, common::ObIArray &sys_pg_keys); diff --git a/src/share/backup/ob_multi_backup_dest_util.cpp b/src/share/backup/ob_multi_backup_dest_util.cpp index 48bb02ed5..653686b31 100644 --- a/src/share/backup/ob_multi_backup_dest_util.cpp +++ b/src/share/backup/ob_multi_backup_dest_util.cpp @@ -20,6 +20,7 @@ #include "share/backup/ob_extern_backup_info_mgr.h" #include "share/backup/ob_log_archive_backup_info_mgr.h" #include "lib/restore/ob_storage.h" +#include "share/backup/ob_backup_info_mgr.h" using namespace oceanbase::common; using namespace oceanbase::share; @@ -776,8 +777,9 @@ int ObMultiBackupDestUtil::do_get_backup_set_list(const bool is_preview, const c } else { LOG_WARN("failed to get extern backup set file infos", KR(ret), K(simple_path)); } - } else if (OB_FAIL(check_is_snapshot_restore(info, restore_timestamp, is_snapshot_restore))) { - LOG_WARN("failed to check is snapshot backup", K(ret), K(info)); + } else if (OB_FAIL(ObRestoreBackupInfoUtil::check_is_snapshot_restore( + info.snapshot_version_, restore_timestamp, info.cluster_version_, is_snapshot_restore))) { + LOG_WARN("failed to check is snapshot restore", K(ret), K(info), K(restore_timestamp)); } else { simple_path.backup_set_id_ = info.backup_set_id_; simple_path.copy_id_ = info.copy_id_; @@ -880,8 +882,11 @@ int ObMultiBackupDestUtil::do_get_backup_set_list_from_cluster_level(const bool ObClusterBackupDest cluster_backup_dest; ObBackupDest tmp_backup_dest; char tmp_simple_path_str[OB_MAX_BACKUP_DEST_LENGTH] = ""; - if (OB_FAIL(check_is_snapshot_restore(tmp_file_info, restore_timestamp, is_snapshot_restore))) { - LOG_WARN("failed to check is snaptshot backup", K(ret), K(tmp_file_info)); + if (OB_FAIL(ObRestoreBackupInfoUtil::check_is_snapshot_restore(tmp_file_info.snapshot_version_, + restore_timestamp, + tmp_file_info.cluster_version_, + is_snapshot_restore))) { + LOG_WARN("failed to check is snapshot restore", K(ret), K(tmp_file_info), K(restore_timestamp)); } else if (OB_FAIL(cluster_backup_dest.set( tmp_file_info.backup_dest_.ptr(), cluster_name, cluster_id, OB_START_INCARNATION))) { LOG_WARN("failed to set cluster backup dest"); @@ -953,8 +958,9 @@ int ObMultiBackupDestUtil::do_inner_get_backup_set_list(const char *cluster_name const ObBackupSetFileInfo &info = file_infos.at(i); if (OB_SUCCESS != info.result_) { // do nothing - } else if (OB_FAIL(check_is_snapshot_restore(info, restore_timestamp, is_snapshot_restore))) { - LOG_WARN("failed to check is snaptshot backup", K(ret), K(info), K(restore_timestamp)); + } else if (OB_FAIL(ObRestoreBackupInfoUtil::check_is_snapshot_restore( + info.snapshot_version_, restore_timestamp, info.cluster_version_, is_snapshot_restore))) { + LOG_WARN("failed to check is snapshot restore", K(ret), K(info), K(restore_timestamp)); } else if (!ObBackupFileStatus::can_show_in_preview(info.file_status_)) { LOG_INFO("backup set info cannot list in preview", K(info)); } else { @@ -1442,18 +1448,5 @@ int ObMultiBackupDestUtil::check_backup_path_is_backup_backup(const char *cluste return ret; } -int ObMultiBackupDestUtil::check_is_snapshot_restore( - const share::ObBackupSetFileInfo &backup_set_info, const int64_t restore_timestamp, bool &is_snapshot_restore) -{ - int ret = OB_SUCCESS; - if (!backup_set_info.is_valid() || restore_timestamp <= 0) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("get invalid args", K(ret), K(backup_set_info), K(restore_timestamp)); - } else { - is_snapshot_restore = backup_set_info.snapshot_version_ == restore_timestamp; - } - return ret; -} - } // end namespace share } // end namespace oceanbase diff --git a/src/share/backup/ob_multi_backup_dest_util.h b/src/share/backup/ob_multi_backup_dest_util.h index 7b30a6cff..02e5211a9 100644 --- a/src/share/backup/ob_multi_backup_dest_util.h +++ b/src/share/backup/ob_multi_backup_dest_util.h @@ -126,8 +126,6 @@ private: static int check_backup_path_is_backup_backup(const char *cluster_name, const int64_t cluster_id, const common::ObString &root_path, const common::ObString &storage_info, const uint64_t tenant_id, bool &is_backup_backup); - static int check_is_snapshot_restore( - const share::ObBackupSetFileInfo &backup_set_info, const int64_t restore_timestamp, bool &is_snapshot_restore); private: DISALLOW_COPY_AND_ASSIGN(ObMultiBackupDestUtil);