diff --git a/src/rootserver/ddl_task/ob_constraint_task.cpp b/src/rootserver/ddl_task/ob_constraint_task.cpp index 3c250b76dd87e4996c9c21178054fe9c8a4b8d41..bf0813ab036e8e77da6ae0c4bfdc9ab5da5bd9df 100644 --- a/src/rootserver/ddl_task/ob_constraint_task.cpp +++ b/src/rootserver/ddl_task/ob_constraint_task.cpp @@ -212,6 +212,7 @@ int ObForeignKeyConstraintValidationTask::check_fk_by_send_sql() const // for example: data_table_id will be parent_table_id when altering non-ref column type of parent table. // https://work.aone.alibaba-inc.com/issue/38544828 const ObTableSchema *data_table_schema = nullptr; + const ObDatabaseSchema *data_database_schema = nullptr; const ObTableSchema *child_table_schema = nullptr; const ObDatabaseSchema *child_database_schema = nullptr; const ObTableSchema *parent_table_schema = nullptr; @@ -221,9 +222,15 @@ int ObForeignKeyConstraintValidationTask::check_fk_by_send_sql() const LOG_WARN("get tenant schema guard failed", K(ret), K(tenant_id_)); } else if (OB_FAIL(schema_guard.get_table_schema(tenant_id_, data_table_id_, data_table_schema))) { LOG_WARN("get table schema failed", K(ret), K(tenant_id_), K(data_table_id_)); - } else if (OB_ISNULL(data_table_schema)) { + } else if (OB_ISNULL(data_table_schema) || data_table_schema->is_in_recyclebin()) { ret = OB_TABLE_NOT_EXIST; LOG_WARN("table schema not exist", K(ret)); + } else if (OB_FAIL(schema_guard.get_database_schema(tenant_id_, data_table_schema->get_database_id(), data_database_schema))) { + LOG_WARN("failed to get database schema", K(ret)); + } else if (OB_ISNULL(data_database_schema) || data_database_schema->is_in_recyclebin()) { + // ob drop database to recyclebin won't drop its tables to recyclebin, but will drop fk of its tables directly. + ret = OB_TABLE_NOT_EXIST; + LOG_WARN("database schema not exist", K(ret)); } else if (OB_FAIL(get_foreign_key_info(data_table_schema, fk_info))) { LOG_WARN("get foreign key info failed", K(ret)); } else if (OB_FAIL(schema_guard.get_table_schema(tenant_id_, fk_info.parent_table_id_, parent_table_schema))) { diff --git a/src/rootserver/ddl_task/ob_ddl_task.cpp b/src/rootserver/ddl_task/ob_ddl_task.cpp index 4757ca57fea72011f4153844e1fa02ff4c0fa05f..26a9a0fb9667c09e32ab9ae32e8f9103292e9a17 100644 --- a/src/rootserver/ddl_task/ob_ddl_task.cpp +++ b/src/rootserver/ddl_task/ob_ddl_task.cpp @@ -652,6 +652,8 @@ bool ObDDLTask::is_replica_build_need_retry( const ObTableSchema *table_schema = nullptr; if (OB_FAIL(ObMultiVersionSchemaService::get_instance().get_tenant_schema_guard(tenant_id_, schema_guard))) { LOG_WARN("get tenant schema guard failed", K(ret), K_(tenant_id)); + } else if (OB_FAIL(ObDDLUtil::check_table_exist(tenant_id_, object_id_, schema_guard))) { + LOG_WARN("failed to check table exist", K(ret)); } else if (OB_FAIL(schema_guard.get_table_schema(tenant_id_, object_id_, table_schema))) { LOG_WARN("get table schema failed", K(ret), K(tenant_id_), K(object_id_)); } else if (OB_ISNULL(table_schema)) { @@ -668,24 +670,15 @@ bool ObDDLTask::is_replica_build_need_retry( if (target_object_id_ != fk_infos.at(i).foreign_key_id_) { } else { found = true; - if (OB_FAIL(schema_guard.check_table_exist(tenant_id_, fk_infos.at(i).parent_table_id_, is_table_exist))) { - LOG_WARN("check schema exist failed", K(ret), K(tenant_id_), K(fk_infos.at(i))); - } else if (!is_table_exist) { - ret = OB_TABLE_NOT_EXIST; - LOG_INFO("table schema not exist", K(ret), K(tenant_id_), K(object_id_), K(fk_infos.at(i))); - } else if (OB_FAIL(schema_guard.check_table_exist(tenant_id_, fk_infos.at(i).child_table_id_, is_table_exist))) { - LOG_WARN("check schema exist failed", K(ret), K(tenant_id_), K(fk_infos.at(i))); - } else if (!is_table_exist) { - ret = OB_TABLE_NOT_EXIST; - LOG_INFO("table schema not exist", K(ret), K(tenant_id_), K(object_id_), K(fk_infos.at(i))); + if (OB_FAIL(ObDDLUtil::check_table_exist(tenant_id_, fk_infos.at(i).parent_table_id_, schema_guard))) { + LOG_WARN("failed to check table exist", K(ret)); + } else if (OB_FAIL(ObDDLUtil::check_table_exist(tenant_id_, fk_infos.at(i).child_table_id_, schema_guard))) { + LOG_WARN("failed to check table exist", K(ret)); } } } - } else if (OB_FAIL(schema_guard.check_table_exist(tenant_id_, target_object_id_, is_table_exist))) { - LOG_WARN("check table exist failed", K(ret), K(tenant_id_), K(target_object_id_)); - } else if (!is_table_exist) { - ret = OB_TABLE_NOT_EXIST; - LOG_WARN("not exist", K(ret), K(tenant_id_), K(target_object_id_)); + } else if (OB_FAIL(ObDDLUtil::check_table_exist(tenant_id_, target_object_id_, schema_guard))) { + LOG_WARN("failed to check table exist", K(ret)); } } } else { diff --git a/src/share/ob_ddl_common.cpp b/src/share/ob_ddl_common.cpp index d5bc23c5f5496a65ef0c2546a31d599747adc26a..a3e188bce8da0ffad8dcee5cb352fe0e72c3e76e 100644 --- a/src/share/ob_ddl_common.cpp +++ b/src/share/ob_ddl_common.cpp @@ -875,6 +875,30 @@ int ObDDLUtil::get_sys_ls_leader_addr( return ret; } +int ObDDLUtil::check_table_exist( + const uint64_t tenant_id, + const uint64_t table_id, + ObSchemaGetterGuard &schema_guard) +{ + int ret = OB_SUCCESS; + const ObTableSchema *table_schema = nullptr; + const ObDatabaseSchema *database_schema = nullptr; + uint64_t database_id = OB_INVALID_ID; + if (OB_FAIL(schema_guard.get_table_schema(tenant_id, table_id, table_schema))) { + LOG_WARN("failed to get table schema", K(ret)); + } else if (OB_ISNULL(table_schema) || table_schema->is_in_recyclebin()) { + ret = OB_TABLE_NOT_EXIST; + LOG_WARN("table not exist", K(ret), K(tenant_id), K(table_id), K(table_schema)); + } else if (OB_FALSE_IT(database_id = table_schema->get_database_id())) { + } else if (OB_FAIL(schema_guard.get_database_schema(tenant_id, database_id, database_schema))) { + LOG_WARN("failed to get database schema", K(ret), K(tenant_id), K(table_id), K(database_id)); + } else if (OB_ISNULL(database_schema) || database_schema->is_in_recyclebin()) { + ret = OB_TABLE_NOT_EXIST; + LOG_WARN("database not exist", K(ret), K(tenant_id), K(table_id), K(database_id), K(database_schema)); + } + return ret; +} + /****************** ObCheckTabletDataComplementOp *************/ int ObCheckTabletDataComplementOp::check_task_inner_sql_session_status( diff --git a/src/share/ob_ddl_common.h b/src/share/ob_ddl_common.h index ffd35d0b805c8eb6296c19a6e9eadcefed1d582e..98ee3cbdaa8fcbe0d5ddc616597ab6432ac765f4 100644 --- a/src/share/ob_ddl_common.h +++ b/src/share/ob_ddl_common.h @@ -300,6 +300,11 @@ public: const common::ObTabletID &tablet_id, ObLSLocation &location); + static int check_table_exist( + const uint64_t tenant_id, + const uint64_t table_id, + share::schema::ObSchemaGetterGuard &schema_guard); + private: static int generate_column_name_str( const common::ObIArray &column_names,