From fe06884eaaa11010076d796e956ed3a14a31fb8e Mon Sep 17 00:00:00 2001 From: obdev Date: Mon, 18 Sep 2023 07:48:19 +0000 Subject: [PATCH] [CP] fix recover table when create tmp table failed --- src/rootserver/ob_root_service.cpp | 4 +++- .../restore/ob_recover_table_initiator.cpp | 1 + src/rootserver/restore/ob_restore_scheduler.cpp | 2 ++ src/share/ob_rpc_struct.cpp | 8 ++++++-- src/share/ob_rpc_struct.h | 3 ++- src/share/restore/ob_physical_restore_info.cpp | 5 ++++- src/share/restore/ob_physical_restore_info.h | 1 + .../restore/ob_physical_restore_table_operator.cpp | 13 +++++++++++++ 8 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/rootserver/ob_root_service.cpp b/src/rootserver/ob_root_service.cpp index e8908f206b..309e013421 100755 --- a/src/rootserver/ob_root_service.cpp +++ b/src/rootserver/ob_root_service.cpp @@ -2705,10 +2705,12 @@ int ObRootService::create_tenant(const ObCreateTenantArg &arg, UInt64 &tenant_id int ret = OB_SUCCESS; int tmp_ret = OB_SUCCESS; const ObString &tenant_name = arg.tenant_schema_.get_tenant_name_str(); + // when recovering table, it needs to create tmp tenant + const bool tmp_tenant = arg.is_tmp_tenant_for_recover_; if (!inited_) { ret = OB_NOT_INIT; LOG_WARN("not init", KR(ret)); - } else if (OB_FAIL(ObResolverUtils::check_not_supported_tenant_name(tenant_name))) { + } else if (!tmp_tenant && OB_FAIL(ObResolverUtils::check_not_supported_tenant_name(tenant_name))) { LOG_WARN("unsupported tenant name", KR(ret), K(tenant_name)); } else if (OB_FAIL(ddl_service_.create_tenant(arg, tenant_id))) { LOG_WARN("fail to create tenant", KR(ret), K(arg)); diff --git a/src/rootserver/restore/ob_recover_table_initiator.cpp b/src/rootserver/restore/ob_recover_table_initiator.cpp index 395526b551..fb0c3732f6 100644 --- a/src/rootserver/restore/ob_recover_table_initiator.cpp +++ b/src/rootserver/restore/ob_recover_table_initiator.cpp @@ -214,6 +214,7 @@ int ObRecoverTableInitiator::insert_sys_job_( } else if (OB_FALSE_IT(physical_restore_job.init_restore_key(OB_SYS_TENANT_ID, job_id))) { } else if (OB_FALSE_IT(physical_restore_job.set_initiator_job_id(job.get_job_id()))) { } else if (OB_FALSE_IT(physical_restore_job.set_initiator_tenant_id(OB_SYS_TENANT_ID))) { + } else if (OB_FALSE_IT(physical_restore_job.set_recover_table(true))) { } else if (OB_FAIL(ObRestoreUtil::record_physical_restore_job(trans, physical_restore_job))) { LOG_WARN("failed to record physical restore job", K(ret)); } diff --git a/src/rootserver/restore/ob_restore_scheduler.cpp b/src/rootserver/restore/ob_restore_scheduler.cpp index eda5e90a5c..f8810a2041 100644 --- a/src/rootserver/restore/ob_restore_scheduler.cpp +++ b/src/rootserver/restore/ob_restore_scheduler.cpp @@ -297,6 +297,8 @@ int ObRestoreScheduler::fill_create_tenant_arg( arg.tenant_schema_.set_compatibility_mode(mode); arg.if_not_exist_ = false; arg.is_restore_ = true; + // create tmp tenant for recover table + arg.is_tmp_tenant_for_recover_ = job.get_recover_table(); // Physical restore is devided into 2 stages. Recover to 'consistent_scn' which was recorded during // data backup first, then to user specified scn. arg.recovery_until_scn_ = job.get_consistent_scn(); diff --git a/src/share/ob_rpc_struct.cpp b/src/share/ob_rpc_struct.cpp index d1588a3184..232fe032bd 100755 --- a/src/share/ob_rpc_struct.cpp +++ b/src/share/ob_rpc_struct.cpp @@ -1123,6 +1123,7 @@ int ObCreateTenantArg::assign(const ObCreateTenantArg &other) compatible_version_ = other.compatible_version_; is_creating_standby_ = other.is_creating_standby_; log_restore_source_ = other.log_restore_source_; + is_tmp_tenant_for_recover_ = other.is_tmp_tenant_for_recover_; } return ret; } @@ -1140,6 +1141,7 @@ void ObCreateTenantArg::reset() compatible_version_ = 0; is_creating_standby_ = false; log_restore_source_.reset(); + is_tmp_tenant_for_recover_ = false; } int ObCreateTenantArg::init(const share::schema::ObTenantSchema &tenant_schema, @@ -1177,7 +1179,8 @@ DEF_TO_STRING(ObCreateTenantArg) K_(recovery_until_scn), K_(compatible_version), K_(is_creating_standby), - K_(log_restore_source)); + K_(log_restore_source), + K_(is_tmp_tenant_for_recover)); return pos; } @@ -1192,7 +1195,8 @@ OB_SERIALIZE_MEMBER((ObCreateTenantArg, ObDDLArg), compatible_version_, recovery_until_scn_, is_creating_standby_, - log_restore_source_); + log_restore_source_, + is_tmp_tenant_for_recover_); bool ObCreateTenantEndArg::is_valid() const { diff --git a/src/share/ob_rpc_struct.h b/src/share/ob_rpc_struct.h index a09203b368..b2fc91da92 100755 --- a/src/share/ob_rpc_struct.h +++ b/src/share/ob_rpc_struct.h @@ -510,7 +510,7 @@ public: : ObDDLArg(), tenant_schema_(), pool_list_(), if_not_exist_(false), sys_var_list_(), name_case_mode_(common::OB_NAME_CASE_INVALID), is_restore_(false), palf_base_info_(), compatible_version_(0), recovery_until_scn_(share::SCN::min_scn()), - is_creating_standby_(false), log_restore_source_() {} + is_creating_standby_(false), log_restore_source_(), is_tmp_tenant_for_recover_(false) {} virtual ~ObCreateTenantArg() {}; bool is_valid() const; int check_valid() const; @@ -538,6 +538,7 @@ public: share::SCN recovery_until_scn_; bool is_creating_standby_; common::ObString log_restore_source_; // for create standby tenant + bool is_tmp_tenant_for_recover_; //tmp tenant for recover table }; struct ObCreateTenantEndArg : public ObDDLArg diff --git a/src/share/restore/ob_physical_restore_info.cpp b/src/share/restore/ob_physical_restore_info.cpp index f4c77c300e..99d0b420b2 100644 --- a/src/share/restore/ob_physical_restore_info.cpp +++ b/src/share/restore/ob_physical_restore_info.cpp @@ -260,7 +260,8 @@ DEF_TO_STRING(ObPhysicalRestoreJob) K_(concurrency), K_(passwd_array), K_(multi_restore_path_list), - K_(white_list) + K_(white_list), + K_(recover_table) ); J_OBJ_END(); return pos; @@ -288,6 +289,7 @@ int ObPhysicalRestoreJob::assign(const ObPhysicalRestoreJob &other) compatible_ = other.compatible_; kms_encrypt_ = other.kms_encrypt_; concurrency_ = other.concurrency_; + recover_table_ = other.recover_table_; if (FAILEDx(deep_copy_ob_string(allocator_, other.comment_, comment_))) { LOG_WARN("failed to copy string", KR(ret), K(other)); @@ -362,6 +364,7 @@ void ObPhysicalRestoreJob::reset() kms_dest_.reset(); kms_encrypt_key_.reset(); concurrency_ = 0; + recover_table_ = false; passwd_array_.reset(); diff --git a/src/share/restore/ob_physical_restore_info.h b/src/share/restore/ob_physical_restore_info.h index bdfde3ac66..54d7959c29 100644 --- a/src/share/restore/ob_physical_restore_info.h +++ b/src/share/restore/ob_physical_restore_info.h @@ -186,6 +186,7 @@ public: Property_declare_ObString(kms_encrypt_key) Property_declare_ObString(passwd_array) Property_declare_int(int64_t, concurrency) + Property_declare_int(bool, recover_table) private: //job_id and tenant_id in __all_restore_job primary_key diff --git a/src/share/restore/ob_physical_restore_table_operator.cpp b/src/share/restore/ob_physical_restore_table_operator.cpp index 6e83804518..f9a5ee4a06 100644 --- a/src/share/restore/ob_physical_restore_table_operator.cpp +++ b/src/share/restore/ob_physical_restore_table_operator.cpp @@ -262,6 +262,7 @@ int ObPhysicalRestoreTableOperator::fill_dml_splicer( ADD_COLUMN_MACRO_IN_TABLE_OPERATOR(job_info, compatible); ADD_COLUMN_MACRO_IN_TABLE_OPERATOR(job_info, passwd_array); ADD_COLUMN_MACRO_IN_TABLE_OPERATOR(job_info, concurrency); + ADD_COLUMN_MACRO_IN_TABLE_OPERATOR(job_info, recover_table); // source_cluster_version if (OB_SUCC(ret)) { @@ -538,6 +539,18 @@ int ObPhysicalRestoreTableOperator::retrieve_restore_option( } } } + + if (OB_SUCC(ret)) { + if (name == "recover_table") { + int64_t recover_table = 0; + if (OB_FAIL(retrieve_int_value(result, recover_table))) { + LOG_WARN("fail to retrive int value", K(ret), "column_name", "recover_table"); + } else { + job.set_recover_table(recover_table != 0); + } + } + } + if (OB_SUCC(ret)) { if (name == "restore_type") { uint64_t restore_type = 0;