Fix infinite retry when table dropped to recyclebin
This commit is contained in:
		| @ -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. |   // 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 |   // https://work.aone.alibaba-inc.com/issue/38544828 | ||||||
|   const ObTableSchema *data_table_schema = nullptr; |   const ObTableSchema *data_table_schema = nullptr; | ||||||
|  |   const ObDatabaseSchema *data_database_schema = nullptr; | ||||||
|   const ObTableSchema *child_table_schema = nullptr; |   const ObTableSchema *child_table_schema = nullptr; | ||||||
|   const ObDatabaseSchema *child_database_schema = nullptr; |   const ObDatabaseSchema *child_database_schema = nullptr; | ||||||
|   const ObTableSchema *parent_table_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_)); |     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))) { |   } 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_)); |     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; |     ret = OB_TABLE_NOT_EXIST; | ||||||
|     LOG_WARN("table schema not exist", K(ret)); |     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))) { |   } else if (OB_FAIL(get_foreign_key_info(data_table_schema, fk_info))) { | ||||||
|     LOG_WARN("get foreign key info failed", K(ret)); |     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))) { |   } else if (OB_FAIL(schema_guard.get_table_schema(tenant_id_, fk_info.parent_table_id_, parent_table_schema))) { | ||||||
|  | |||||||
| @ -652,6 +652,8 @@ bool ObDDLTask::is_replica_build_need_retry( | |||||||
|     const ObTableSchema *table_schema = nullptr; |     const ObTableSchema *table_schema = nullptr; | ||||||
|     if (OB_FAIL(ObMultiVersionSchemaService::get_instance().get_tenant_schema_guard(tenant_id_, schema_guard))) { |     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)); |       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))) { |     } 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_)); |       LOG_WARN("get table schema failed", K(ret), K(tenant_id_), K(object_id_)); | ||||||
|     } else if (OB_ISNULL(table_schema)) { |     } 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_) { |           if (target_object_id_ != fk_infos.at(i).foreign_key_id_) { | ||||||
|           } else { |           } else { | ||||||
|             found = true; |             found = true; | ||||||
|             if (OB_FAIL(schema_guard.check_table_exist(tenant_id_, fk_infos.at(i).parent_table_id_, is_table_exist))) { |             if (OB_FAIL(ObDDLUtil::check_table_exist(tenant_id_, fk_infos.at(i).parent_table_id_, schema_guard))) { | ||||||
|               LOG_WARN("check schema exist failed", K(ret), K(tenant_id_), K(fk_infos.at(i))); |               LOG_WARN("failed to check table exist", K(ret)); | ||||||
|             } else if (!is_table_exist) { |             } else if (OB_FAIL(ObDDLUtil::check_table_exist(tenant_id_, fk_infos.at(i).child_table_id_, schema_guard))) { | ||||||
|               ret = OB_TABLE_NOT_EXIST; |               LOG_WARN("failed to check table exist", K(ret)); | ||||||
|               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))); |  | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
|       } else if (OB_FAIL(schema_guard.check_table_exist(tenant_id_, target_object_id_, is_table_exist))) { |       } else if (OB_FAIL(ObDDLUtil::check_table_exist(tenant_id_, target_object_id_, schema_guard))) { | ||||||
|         LOG_WARN("check table exist failed", K(ret), K(tenant_id_), K(target_object_id_)); |         LOG_WARN("failed to check table exist", K(ret)); | ||||||
|       } else if (!is_table_exist) { |  | ||||||
|         ret = OB_TABLE_NOT_EXIST; |  | ||||||
|         LOG_WARN("not exist", K(ret), K(tenant_id_), K(target_object_id_)); |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } else { |   } else { | ||||||
|  | |||||||
| @ -875,6 +875,30 @@ int ObDDLUtil::get_sys_ls_leader_addr( | |||||||
|   return ret; |   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         *************/ | /******************           ObCheckTabletDataComplementOp         *************/ | ||||||
|  |  | ||||||
| int ObCheckTabletDataComplementOp::check_task_inner_sql_session_status( | int ObCheckTabletDataComplementOp::check_task_inner_sql_session_status( | ||||||
|  | |||||||
| @ -300,6 +300,11 @@ public: | |||||||
|     const common::ObTabletID &tablet_id, |     const common::ObTabletID &tablet_id, | ||||||
|     ObLSLocation &location); |     ObLSLocation &location); | ||||||
|  |  | ||||||
|  |   static int check_table_exist( | ||||||
|  |      const uint64_t tenant_id, | ||||||
|  |      const uint64_t table_id, | ||||||
|  |      share::schema::ObSchemaGetterGuard &schema_guard); | ||||||
|  |  | ||||||
| private: | private: | ||||||
|   static int generate_column_name_str( |   static int generate_column_name_str( | ||||||
|     const common::ObIArray<ObColumnNameInfo> &column_names, |     const common::ObIArray<ObColumnNameInfo> &column_names, | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Hongqin-Li
					Hongqin-Li