diff --git a/src/rootserver/ob_ddl_operator.cpp b/src/rootserver/ob_ddl_operator.cpp index 90f236f48b..df33a70c14 100644 --- a/src/rootserver/ob_ddl_operator.cpp +++ b/src/rootserver/ob_ddl_operator.cpp @@ -663,15 +663,13 @@ int ObDDLOperator::alter_database(ObDatabaseSchema &new_database_schema, int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, ObMySQLTransaction &trans, - ObSchemaGetterGuard &schema_guard, const ObString *ddl_stmt_str/*=NULL*/) { int ret = OB_SUCCESS; ObSchemaService *schema_service_impl = schema_service_.get_schema_service(); const uint64_t tenant_id = db_schema.get_tenant_id(); + const uint64_t database_id = db_schema.get_database_id(); int64_t new_schema_version = OB_INVALID_VERSION; - uint64_t database_id = db_schema.get_database_id(); - ObArenaAllocator allocator(ObModIds::OB_SCHEMA_OB_SCHEMA_ARENA); if (OB_ISNULL(schema_service_impl)) { ret = OB_ERR_SYS; @@ -680,7 +678,7 @@ int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, } //drop tables in recyclebin if (OB_SUCC(ret)) { - if (OB_FAIL(purge_table_of_database(db_schema, trans, schema_guard))) { + if (OB_FAIL(purge_table_of_database(db_schema, trans))) { LOG_WARN("purge_table_in_db failed", K(ret)); } } @@ -688,18 +686,26 @@ int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, //delete triggers in database, 只删除trigger_database != base_table_database 的trigger // trigger_database == base_table_database 的trigger会在下面删除表的时候删除 if (OB_SUCC(ret)) { - ObArray tgs; - if (OB_FAIL(schema_guard.get_trigger_infos_in_database(tenant_id, database_id, tgs))) { - LOG_WARN("get trigger infos in database failed", K(tenant_id), KT(database_id), K(ret)); + ObArray trigger_ids; + ObSchemaGetterGuard schema_guard; + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_trigger_ids_in_database(tenant_id, database_id, trigger_ids))) { + LOG_WARN("get trigger infos in database failed", KR(ret), K(tenant_id), K(database_id)); } else { - for (int64_t i = 0; OB_SUCC(ret) && i < tgs.count(); i++) { - const ObTriggerInfo *tg_info = tgs.at(i); - if (OB_ISNULL(tg_info)) { + for (int64_t i = 0; OB_SUCC(ret) && i < trigger_ids.count(); i++) { + const ObTriggerInfo *tg_info = NULL; + const uint64_t trigger_id = trigger_ids.at(i); + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_trigger_info(tenant_id, trigger_id, tg_info))) { + LOG_WARN("fail to get trigger info", KR(ret), K(tenant_id), K(trigger_id)); + } else if (OB_ISNULL(tg_info)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("trigger info is NULL", K(ret)); } else { - const ObTableSchema * tbl_schema = NULL; - OZ (schema_guard.get_table_schema(tenant_id, tg_info->get_base_object_id(), tbl_schema)); + const ObSimpleTableSchemaV2 * tbl_schema = NULL; + OZ (schema_guard.get_simple_table_schema(tenant_id, tg_info->get_base_object_id(), tbl_schema)); CK (OB_NOT_NULL(tbl_schema)); if (OB_SUCC(ret) && database_id != tbl_schema->get_database_id()) { OZ (drop_trigger(*tg_info, trans, NULL)); @@ -711,17 +717,23 @@ int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, // delete tables in database if (OB_SUCC(ret)) { - ObArray tables; - if (OB_FAIL(schema_guard.get_table_schemas_in_database(tenant_id, database_id, tables))) { + ObArray table_ids; + ObSchemaGetterGuard schema_guard; + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_table_ids_in_database(tenant_id, database_id, table_ids))) { LOG_WARN("get tables in database failed", K(tenant_id), KT(database_id), K(ret)); } else { // drop index tables first - common::ObSqlString public_sql_string; - ObArray audits; for (int64_t cycle = 0; OB_SUCC(ret) && cycle < 2; ++cycle) { - for (int64_t i = 0; OB_SUCC(ret) && i < tables.count(); ++i) { - const ObTableSchema *table = tables.at(i); - if (OB_ISNULL(table)) { + for (int64_t i = 0; OB_SUCC(ret) && i < table_ids.count(); ++i) { + const ObTableSchema *table = NULL; + const uint64_t table_id = table_ids.at(i); + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_table_schema(tenant_id, table_id, table))) { + LOG_WARN("fail to get table schema", KR(ret), K(tenant_id), K(table_id)); + } else if (OB_ISNULL(table)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("table is NULL", K(ret)); } else if (table->is_in_recyclebin()) { @@ -744,40 +756,50 @@ int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, // delete outlines in database if (OB_SUCC(ret)) { - ObArray outlines; - if (OB_FAIL(schema_guard.get_outline_infos_in_database(tenant_id, database_id, outlines))) { + ObArray outline_schemas; + ObSchemaGetterGuard schema_guard; + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_simple_outline_schemas_in_database(tenant_id, database_id, outline_schemas))) { LOG_WARN("get outlines in database failed", K(tenant_id), KT(database_id), K(ret)); } else { - for (int64_t i = 0; OB_SUCC(ret) && i < outlines.count(); ++i) { - const ObOutlineInfo *outline_info = outlines.at(i); - if (OB_ISNULL(outline_info)) { + for (int64_t i = 0; OB_SUCC(ret) && i < outline_schemas.count(); ++i) { + const ObSimpleOutlineSchema *outline_schema = outline_schemas.at(i); + if (OB_ISNULL(outline_schema)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("outline info is NULL", K(ret)); } else if (OB_FAIL(schema_service_.gen_new_schema_version(tenant_id, new_schema_version))) { LOG_WARN("fail to gen new schema_version", K(ret), K(tenant_id)); - } else if (OB_FAIL(schema_service_impl->get_outline_sql_service().drop_outline( - *outline_info, new_schema_version, trans))) { - LOG_WARN("drop outline failed", "outline_id", outline_info->get_outline_id(), K(ret)); + } else if (OB_FAIL(schema_service_impl->get_outline_sql_service().delete_outline(tenant_id, + database_id, + outline_schema->get_outline_id(), + new_schema_version, trans))) { + LOG_WARN("drop outline failed", KR(ret), "outline_id", outline_schema->get_outline_id()); } } } } // delete synonyms in database if (OB_SUCC(ret)) { - ObArray synonyms; - if (OB_FAIL(schema_guard.get_synonym_infos_in_database(tenant_id, database_id, synonyms))) { + ObSchemaGetterGuard schema_guard; + ObArray synonym_schemas; + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_simple_synonym_schemas_in_database(tenant_id, database_id, synonym_schemas))) { LOG_WARN("get synonyms in database failed", K(tenant_id), KT(database_id), K(ret)); } else { - for (int64_t i = 0; OB_SUCC(ret) && i < synonyms.count(); ++i) { - const ObSynonymInfo *synonym_info = synonyms.at(i); - if (OB_ISNULL(synonym_info)) { + for (int64_t i = 0; OB_SUCC(ret) && i < synonym_schemas.count(); ++i) { + const ObSimpleSynonymSchema *synonym_schema = synonym_schemas.at(i); + if (OB_ISNULL(synonym_schema)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("synonym info is NULL", K(ret)); } else if (OB_FAIL(schema_service_.gen_new_schema_version(tenant_id, new_schema_version))) { LOG_WARN("fail to gen new schema_version", K(ret), K(tenant_id)); - } else if (OB_FAIL(schema_service_impl->get_synonym_sql_service().drop_synonym( - *synonym_info, new_schema_version, &trans))) { - LOG_WARN("drop synonym failed", "synonym_id", synonym_info->get_synonym_id(), K(ret)); + } else if (OB_FAIL(schema_service_impl->get_synonym_sql_service().delete_synonym(tenant_id, + database_id, + synonym_schema->get_synonym_id(), + new_schema_version, &trans))) { + LOG_WARN("drop synonym failed", KR(ret), "synonym_id", synonym_schema->get_synonym_id()); } } } @@ -785,29 +807,35 @@ int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, // delete packages in database if (OB_SUCC(ret)) { - ObArray packages; - if (OB_FAIL(schema_guard.get_package_infos_in_database(tenant_id, database_id, packages))) { + ObSchemaGetterGuard schema_guard; + ObArray package_schemas; + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_simple_package_schemas_in_database(tenant_id, database_id, package_schemas))) { LOG_WARN("get packages in database failed", K(tenant_id), KT(database_id), K(ret)); } else { ObArray audits; common::ObSqlString public_sql_string; - for (int64_t i = 0; OB_SUCC(ret) && i < packages.count(); ++i) { - const ObPackageInfo *package_info = packages.at(i); - if (OB_ISNULL(package_info)) { + for (int64_t i = 0; OB_SUCC(ret) && i < package_schemas.count(); ++i) { + const ObSimplePackageSchema *package_schema = package_schemas.at(i); + if (OB_ISNULL(package_schema)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("package info is NULL", K(ret)); } else if (OB_FAIL(schema_service_.gen_new_schema_version(tenant_id, new_schema_version))) { LOG_WARN("fail to gen new schema_version", K(ret), K(tenant_id)); } else if (OB_FAIL(schema_service_impl->get_routine_sql_service().drop_package( - *package_info, new_schema_version, trans))) { - LOG_WARN("drop package failed", "package_id", package_info->get_package_id(), K(ret)); + package_schema->get_tenant_id(), + package_schema->get_database_id(), + package_schema->get_package_id(), + new_schema_version, trans))) { + LOG_WARN("drop package failed", KR(ret), "package_id", package_schema->get_package_id()); } else { // delete audit in package audits.reuse(); public_sql_string.reuse(); if (OB_FAIL(schema_guard.get_audit_schema_in_owner(tenant_id, AUDIT_PACKAGE, - package_info->get_package_id(), + package_schema->get_package_id(), audits))) { LOG_WARN("get get_audit_schema_in_owner failed", K(tenant_id), K(ret)); } else if (!audits.empty()) { @@ -832,7 +860,7 @@ int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, } } } else { - LOG_DEBUG("no need to delete audit_schema from drop package", K(audits), KPC(package_info)); + LOG_DEBUG("no need to delete audit_schema from drop package", K(audits), KPC(package_schema)); } } } @@ -841,30 +869,38 @@ int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, // delete routines in database if (OB_SUCC(ret)) { - ObArray routines; - if (OB_FAIL(schema_guard.get_routine_infos_in_database(tenant_id, database_id, routines))) { + ObArray routine_ids; + ObSchemaGetterGuard schema_guard; + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_routine_ids_in_database(tenant_id, database_id, routine_ids))) { LOG_WARN("get routines in database failed", K(tenant_id), KT(database_id), K(ret)); } else { ObArray audits; common::ObSqlString public_sql_string; - for (int64_t i = 0; OB_SUCC(ret) && i < routines.count(); ++i) { - const ObRoutineInfo *routine_info = routines.at(i); + for (int64_t i = 0; OB_SUCC(ret) && i < routine_ids.count(); ++i) { + const ObRoutineInfo *routine_info = NULL; + const uint64_t routine_id = routine_ids.at(i); int64_t new_schema_version = OB_INVALID_VERSION; - if (OB_ISNULL(routine_info)) { + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_routine_info(tenant_id, routine_id, routine_info))) { + LOG_WARN("fail to get routine with id", KR(ret), K(tenant_id), K(routine_id)); + } else if (OB_ISNULL(routine_info)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("routine info is NULL", K(ret)); } else if (OB_FAIL(schema_service_.gen_new_schema_version(tenant_id, new_schema_version))) { LOG_WARN("fail to gen new schema_version", K(ret), K(tenant_id)); } else if (OB_FAIL(schema_service_impl->get_routine_sql_service().drop_routine( *routine_info, new_schema_version, trans))) { - LOG_WARN("drop routine failed", "routine_id", routine_info->get_routine_id(), K(ret)); + LOG_WARN("drop routine failed", KR(ret), "routine_id", routine_id); } else { // delete audit in routine audits.reuse(); public_sql_string.reuse(); if (OB_FAIL(schema_guard.get_audit_schema_in_owner(tenant_id, AUDIT_PROCEDURE, - routine_info->get_routine_id(), + routine_id, audits))) { LOG_WARN("get get_audit_schema_in_owner failed", K(tenant_id), K(ret)); } else if (!audits.empty()) { @@ -898,14 +934,22 @@ int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, // delete udts in database if (OB_SUCC(ret)) { - ObArray udts; - if (OB_FAIL(schema_guard.get_udt_infos_in_database(tenant_id, database_id, udts))) { + ObArray udt_ids; + ObSchemaGetterGuard schema_guard; + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_udt_ids_in_database(tenant_id, database_id, udt_ids))) { LOG_WARN("get udts in database failed", K(tenant_id), KT(database_id), K(ret)); } else { - for (int64_t i = 0; OB_SUCC(ret) && i < udts.count(); ++i) { - const ObUDTTypeInfo *udt_info = udts.at(i); + for (int64_t i = 0; OB_SUCC(ret) && i < udt_ids.count(); ++i) { + const ObUDTTypeInfo *udt_info = NULL; + const uint64_t udt_id = udt_ids.at(i); int64_t new_schema_version = OB_INVALID_VERSION; - if (OB_ISNULL(udt_info)) { + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_udt_info(tenant_id, udt_id, udt_info))) { + LOG_WARN("fail to get routine with id", KR(ret), K(tenant_id), K(udt_id)); + } else if (OB_ISNULL(udt_info)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("routine info is NULL", K(ret)); } else if (OB_FAIL(schema_service_.gen_new_schema_version(tenant_id, new_schema_version))) { @@ -920,36 +964,39 @@ int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, // delete sequences in database if (OB_SUCC(ret)) { - ObArray sequences; - if (OB_FAIL(schema_guard.get_sequence_infos_in_database(tenant_id, - database_id, - sequences))) { + ObSchemaGetterGuard schema_guard; + ObArray sequence_schemas; + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_sequence_schemas_in_database(tenant_id, + database_id, + sequence_schemas))) { LOG_WARN("get sequences in database failed", K(tenant_id), KT(database_id), K(ret)); } else { ObArray audits; common::ObSqlString public_sql_string; - for (int64_t i = 0; OB_SUCC(ret) && i < sequences.count(); ++i) { - const ObSequenceSchema *sequence_info = sequences.at(i); - if (OB_ISNULL(sequence_info)) { + for (int64_t i = 0; OB_SUCC(ret) && i < sequence_schemas.count(); ++i) { + const ObSequenceSchema *sequence_schema = sequence_schemas.at(i); + if (OB_ISNULL(sequence_schema)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("sequence info is NULL", K(ret)); - } else if (sequence_info->get_is_system_generated()) { + } else if (sequence_schema->get_is_system_generated()) { continue; } else if (OB_FAIL(schema_service_.gen_new_schema_version(tenant_id, new_schema_version))) { LOG_WARN("fail to gen new schema_version", K(ret), K(tenant_id)); } else if (OB_FAIL(schema_service_impl ->get_sequence_sql_service() - .drop_sequence(*sequence_info, new_schema_version, &trans))) { + .drop_sequence(*sequence_schema, new_schema_version, &trans))) { LOG_WARN("drop sequence failed", - K(*sequence_info), K(ret)); + KR(ret), K(*sequence_schema)); } else { // delete audit in table audits.reuse(); public_sql_string.reuse(); if (OB_FAIL(schema_guard.get_audit_schema_in_owner(tenant_id, AUDIT_SEQUENCE, - sequence_info->get_sequence_id(), + sequence_schema->get_sequence_id(), audits))) { LOG_WARN("get get_audit_schema_in_owner failed", K(tenant_id), K(ret)); } else if (!audits.empty()) { @@ -975,7 +1022,7 @@ int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, } } } else { - LOG_DEBUG("no need to delete audit_schema from drop sequence", K(audits), KPC(sequence_info)); + LOG_DEBUG("no need to delete audit_schema from drop sequence", K(audits), KPC(sequence_schema)); } } } @@ -984,8 +1031,11 @@ int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, // delete mock_fk_parent_tables in database if (OB_SUCC(ret)) { - ObArray mock_fk_parent_table_schemas; - if (OB_FAIL(schema_guard.get_mock_fk_parent_table_schemas_in_database(tenant_id, database_id, mock_fk_parent_table_schemas))) { + ObSchemaGetterGuard schema_guard; + ObArray mock_fk_parent_table_ids; + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_mock_fk_parent_table_ids_in_database(tenant_id, database_id, mock_fk_parent_table_ids))) { LOG_WARN("fail to get mock_fk_parent_table_schemas in database", K(ret), K(tenant_id), K(database_id)); } else { ObArray mock_fk_parent_table_schema_array; @@ -993,10 +1043,19 @@ int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, if (OB_FAIL(schema_service_.gen_new_schema_version(tenant_id, new_schema_version))) { LOG_WARN("fail to gen new schema_version", K(ret), K(tenant_id)); } - for (int64_t i = 0; OB_SUCC(ret) && i < mock_fk_parent_table_schemas.count(); ++i) { + for (int64_t i = 0; OB_SUCC(ret) && i < mock_fk_parent_table_ids.count(); ++i) { ObMockFKParentTableSchema tmp_mock_fk_parent_table_schema; - if (OB_FAIL(tmp_mock_fk_parent_table_schema.assign(*mock_fk_parent_table_schemas.at(i)))) { - LOG_WARN("fail to assign mock_fk_parent_table_schema", K(ret), K(tenant_id), K(database_id), KPC(mock_fk_parent_table_schemas.at(i))); + const uint64_t mock_fk_parent_table_id = mock_fk_parent_table_ids.at(i); + const ObMockFKParentTableSchema *mock_fk_parent_table_schema = NULL; + if (OB_FAIL(schema_guard.get_mock_fk_parent_table_schema_with_id(tenant_id, + mock_fk_parent_table_id, + mock_fk_parent_table_schema))) { + LOG_WARN("fail to get mock fk parent table schema", KR(ret), K(tenant_id), K(mock_fk_parent_table_id)); + } else if (OB_ISNULL(mock_fk_parent_table_schema)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("mock fk parent table schema is NULL", KR(ret), K(tenant_id), K(mock_fk_parent_table_id)); + } else if (OB_FAIL(tmp_mock_fk_parent_table_schema.assign(*mock_fk_parent_table_schema))) { + LOG_WARN("fail to assign mock_fk_parent_table_schema", K(ret), K(tenant_id), K(database_id), KPC(mock_fk_parent_table_schema)); } else if (FALSE_IT(tmp_mock_fk_parent_table_schema.set_schema_version(new_schema_version))) { } else if (FALSE_IT(tmp_mock_fk_parent_table_schema.set_operation_type(ObMockFKParentTableOperationType::MOCK_FK_PARENT_TABLE_OP_DROP_TABLE))) { } else if (OB_FAIL(mock_fk_parent_table_schema_array.push_back(tmp_mock_fk_parent_table_schema))) { @@ -1028,25 +1087,33 @@ int ObDDLOperator::drop_database(const ObDatabaseSchema &db_schema, // of each table, in case of hitting plan cache. // The key of plan cache is current database name, table_id and schema version. int ObDDLOperator::update_table_version_of_db(const ObDatabaseSchema &database_schema, - ObMySQLTransaction &trans, - ObSchemaGetterGuard &schema_guard) + ObMySQLTransaction &trans) { int ret = OB_SUCCESS; const uint64_t tenant_id = database_schema.get_tenant_id(); + const uint64_t database_id = database_schema.get_database_id(); int64_t new_schema_version = OB_INVALID_VERSION; - ObArray table_schemas; + ObArray table_ids; + ObSchemaGetterGuard schema_guard; ObSchemaService *schema_service = schema_service_.get_schema_service(); if (OB_ISNULL(schema_service)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("schema service should not be null", K(ret)); - } else if (OB_FAIL(schema_guard.get_table_schemas_in_database(tenant_id, - database_schema.get_database_id(), - table_schemas))) { + } else if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_table_ids_in_database(tenant_id, + database_id, + table_ids))) { LOG_WARN("get_table_schemas_in_database failed", K(ret), K(tenant_id)); } - for (int64_t idx = 0; OB_SUCC(ret) && idx < table_schemas.count(); ++idx) { - const ObTableSchema *table = table_schemas.at(idx); - if (OB_ISNULL(table)) { + const int64_t table_count = table_ids.count(); + for (int64_t idx = 0; OB_SUCC(ret) && idx < table_count; ++idx) { + const ObTableSchema *table = NULL; + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_table_schema(tenant_id, table_ids.at(idx), table))) { + LOG_WARN("fail to get table schema", KR(ret), K(tenant_id), K(table_ids.at(idx))); + } else if (OB_ISNULL(table)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("table schema should not be null", K(ret)); } else if (table->is_index_table()) { @@ -1056,32 +1123,36 @@ int ObDDLOperator::update_table_version_of_db(const ObDatabaseSchema &database_s if (OB_FAIL(table->get_simple_index_infos(simple_index_infos))) { LOG_WARN("get_index_tid_array failed", K(ret)); } + ObSchemaGetterGuard tmp_schema_guard; for (int64_t i = 0; OB_SUCC(ret) && i < simple_index_infos.count(); ++i) { const ObTableSchema *index_table_schema = NULL; - if (OB_FAIL(schema_guard.get_table_schema(tenant_id, - simple_index_infos.at(i).table_id_, index_table_schema))) { - LOG_WARN("get_table_schema failed", - "table id", simple_index_infos.at(i).table_id_, K(ret)); + const uint64_t table_id = simple_index_infos.at(i).table_id_; + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, tmp_schema_guard))) { + LOG_WARN("failed to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(tmp_schema_guard.get_table_schema(tenant_id, + table_id, + index_table_schema))) { + LOG_WARN("get_table_schema failed", KR(ret), "table id", table_id); } else if (OB_ISNULL(index_table_schema)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("table schema should not be null", K(ret)); } else if (OB_FAIL(schema_service_.gen_new_schema_version(tenant_id, new_schema_version))) { LOG_WARN("fail to gen new schema_version", K(ret), K(tenant_id)); } else { - ObTableSchema new_index_schema; - if (OB_FAIL(new_index_schema.assign(*index_table_schema))) { - LOG_WARN("fail to assign schema", K(ret)); - } else { - new_index_schema.set_schema_version(new_schema_version); - } - if (OB_FAIL(ret)) { - } else if (OB_FAIL(schema_service->get_table_sql_service().update_table_options( - trans, - *index_table_schema, - new_index_schema, - OB_DDL_DROP_TABLE_TO_RECYCLEBIN, - NULL))) { - LOG_WARN("update_table_option failed", K(ret)); + HEAP_VAR(ObTableSchema, new_index_schema) { + if (OB_FAIL(new_index_schema.assign(*index_table_schema))) { + LOG_WARN("fail to assign schema", KR(ret), K(tenant_id), K(table_id)); + } else { + new_index_schema.set_schema_version(new_schema_version); + } + if (FAILEDx(schema_service->get_table_sql_service().update_table_options( + trans, + *index_table_schema, + new_index_schema, + OB_DDL_DROP_TABLE_TO_RECYCLEBIN, + NULL))) { + LOG_WARN("update_table_option failed", KR(ret), K(tenant_id), K(table_id)); + } } } } @@ -1112,11 +1183,11 @@ int ObDDLOperator::update_table_version_of_db(const ObDatabaseSchema &database_s int ObDDLOperator::drop_database_to_recyclebin(const ObDatabaseSchema &database_schema, ObMySQLTransaction &trans, - ObSchemaGetterGuard &guard, const ObString *ddl_stmt_str) { int ret = OB_SUCCESS; const uint64_t tenant_id = database_schema.get_tenant_id(); + const uint64_t database_id = database_schema.get_database_id(); int64_t new_schema_version = OB_INVALID_VERSION; ObSchemaService *schema_service_impl = schema_service_.get_schema_service(); if (OB_ISNULL(schema_service_impl)) { @@ -1126,23 +1197,23 @@ int ObDDLOperator::drop_database_to_recyclebin(const ObDatabaseSchema &database_ ret = OB_INVALID_ARGUMENT; LOG_WARN("tenant_id is invalid", K(ret), K(tenant_id)); } else { - ObArray tables; - ObDatabaseSchema new_database_schema = database_schema; ObSqlString new_db_name; ObRecycleObject recycle_object; - recycle_object.set_original_name(database_schema.get_database_name_str()); + ObDatabaseSchema new_database_schema; + ObSchemaService *schema_service = schema_service_.get_schema_service(); recycle_object.set_type(ObRecycleObject::DATABASE); recycle_object.set_database_id(database_schema.get_database_id()); recycle_object.set_table_id(OB_INVALID_ID); recycle_object.set_tablegroup_id(database_schema.get_default_tablegroup_id()); - new_database_schema.set_in_recyclebin(true); - new_database_schema.set_default_tablegroup_id(OB_INVALID_ID); - // It ensure that db schema version of insert recyclebin and alter database - // is equal that updating table version and inserting recyclebin. - ObSchemaService *schema_service = schema_service_.get_schema_service(); - if (OB_FAIL(update_table_version_of_db(database_schema, - trans, - guard))) { + if (OB_FAIL(recycle_object.set_original_name(database_schema.get_database_name_str()))) { + LOG_WARN("fail to set original name for recycleb object", KR(ret), K(tenant_id), K(database_id)); + } else if (OB_FAIL(new_database_schema.assign(database_schema))) { + LOG_WARN("fail to assign new database schema", KR(ret), K(tenant_id), K(database_id)); + } else if (FALSE_IT(new_database_schema.set_in_recyclebin(true))) { + } else if (FALSE_IT(new_database_schema.set_default_tablegroup_id(OB_INVALID_ID))) { + // It ensure that db schema version of insert recyclebin and alter database + // is equal that updating table version and inserting recyclebin. + } else if (OB_FAIL(update_table_version_of_db(database_schema, trans))) { LOG_WARN("update table version of db failed", K(ret), K(database_schema)); } else if (OB_ISNULL(schema_service)) { ret = OB_ERR_SYS; @@ -1155,7 +1226,7 @@ int ObDDLOperator::drop_database_to_recyclebin(const ObDatabaseSchema &database_ } else if (OB_FAIL(new_database_schema.set_database_name(new_db_name.string()))) { LOG_WARN("set database name failed", K(ret)); } else if (FALSE_IT(recycle_object.set_object_name(new_db_name.string()))) { - } else if (FALSE_IT(recycle_object.set_tenant_id(database_schema.get_tenant_id()))) { + } else if (FALSE_IT(recycle_object.set_tenant_id(tenant_id))) { } else if (OB_FAIL(schema_service_impl->insert_recyclebin_object(recycle_object, trans))) { LOG_WARN("insert recycle object failed", K(ret)); @@ -1164,14 +1235,18 @@ int ObDDLOperator::drop_database_to_recyclebin(const ObDatabaseSchema &database_ ddl_stmt_str, false /*no need_new_schema_version*/))) { LOG_WARN("alter_database failed,", K(ret)); - } else if (OB_FAIL(guard.get_table_schemas_in_database(tenant_id, - database_schema.get_database_id(), - tables))) { - LOG_WARN("get tables in database failed", K(tenant_id), - KT(database_schema.get_database_id()), K(ret)); } else { + ObSchemaGetterGuard schema_guard; + ObArray tables; + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("fail to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_table_schemas_in_database(tenant_id, + database_id, + tables))) { + LOG_WARN("get tables in database failed", KR(ret), K(tenant_id), K(database_id)); + } for (int64_t i = 0; OB_SUCC(ret) && i < tables.count(); ++i) { - const ObTableSchema *table_schema = tables.at(i); + const ObSimpleTableSchemaV2 *table_schema = tables.at(i); if (OB_ISNULL(table_schema)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("table is NULL", K(ret)); @@ -5166,18 +5241,20 @@ int ObDDLOperator::flashback_database_from_recyclebin(const ObDatabaseSchema &da } int ObDDLOperator::purge_table_of_database(const ObDatabaseSchema &db_schema, - ObMySQLTransaction &trans, - ObSchemaGetterGuard &guard) + ObMySQLTransaction &trans) { int ret = OB_SUCCESS; + ObSchemaGetterGuard schema_guard; + const uint64_t tenant_id = db_schema.get_tenant_id(); + const uint64_t database_id = db_schema.get_database_id(); ObSchemaService *schema_service = schema_service_.get_schema_service(); if (OB_ISNULL(schema_service)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("schema_service should not be null", K(ret)); } else { ObArray recycle_objs; - if (OB_FAIL(schema_service->fetch_recycle_objects_of_db(db_schema.get_tenant_id(), - db_schema.get_database_id(), + if (OB_FAIL(schema_service->fetch_recycle_objects_of_db(tenant_id, + database_id, trans, recycle_objs))) { LOG_WARN("fetch recycle objects of db failed", K(ret)); @@ -5185,16 +5262,19 @@ int ObDDLOperator::purge_table_of_database(const ObDatabaseSchema &db_schema, for (int i = 0; OB_SUCC(ret) && i < recycle_objs.count(); ++i) { const ObRecycleObject &recycle_obj = recycle_objs.at(i); const ObTableSchema* table_schema = NULL; - if (OB_FAIL(guard.get_table_schema(recycle_obj.get_tenant_id(), - recycle_obj.get_table_id(), table_schema))) { - LOG_WARN("get table schema failed", K(ret), K(recycle_obj)); + if (OB_FAIL(schema_service_.get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("failed to get schema guard", K(ret)); + } else if (OB_FAIL(schema_guard.get_table_schema(recycle_obj.get_tenant_id(), + recycle_obj.get_table_id(), + table_schema))) { + LOG_WARN("fail to get table_schema", KR(ret), K(recycle_obj)); } else if (OB_ISNULL(table_schema)) { ret = OB_TABLE_NOT_EXIST; LOG_WARN("table is not exist", K(ret), K(recycle_obj)); LOG_USER_ERROR(OB_TABLE_NOT_EXIST, to_cstring(db_schema.get_database_name_str()), to_cstring(recycle_obj.get_object_name())); } else if (OB_FAIL(purge_table_with_aux_table(*table_schema, - guard, + schema_guard, trans, NULL /*ddl_stmt_str */))) { LOG_WARN("purge table with index failed", K(ret), K(recycle_obj)); @@ -5207,7 +5287,6 @@ int ObDDLOperator::purge_table_of_database(const ObDatabaseSchema &db_schema, int ObDDLOperator::purge_database_in_recyclebin(const ObDatabaseSchema &database_schema, ObMySQLTransaction &trans, - ObSchemaGetterGuard &guard, const ObString *ddl_stmt_str) { int ret = OB_SUCCESS; @@ -5232,7 +5311,6 @@ int ObDDLOperator::purge_database_in_recyclebin(const ObDatabaseSchema &database LOG_WARN("unexpected recycle object num", K(ret)); } else if (OB_FAIL(drop_database(database_schema, trans, - guard, ddl_stmt_str))) { LOG_WARN("drop_table failed", K(ret)); } else if (OB_FAIL(schema_service->delete_recycle_object( @@ -8646,7 +8724,10 @@ int ObDDLOperator::drop_package(const ObPackageInfo &package_info, } else if (OB_FAIL(schema_service_.gen_new_schema_version(tenant_id, new_schema_version))) { LOG_WARN("fail to gen new schema_version", K(ret), K(tenant_id)); } else if (NULL != package_body_info) { - if (OB_FAIL(schema_service_impl->get_routine_sql_service().drop_package(*package_body_info, new_schema_version, trans))) { + if (OB_FAIL(schema_service_impl->get_routine_sql_service().drop_package(package_body_info->get_tenant_id(), + package_body_info->get_database_id(), + package_body_info->get_package_id(), + new_schema_version, trans))) { LOG_WARN("drop package body info failed", K(package_body_info), K(ret)); } } else { @@ -8667,7 +8748,10 @@ int ObDDLOperator::drop_package(const ObPackageInfo &package_info, if (OB_SUCC(ret)) { if (OB_FAIL(schema_service_.gen_new_schema_version(tenant_id, new_schema_version))) { LOG_WARN("fail to gen new schema_version", K(ret), K(tenant_id)); - } else if (OB_FAIL(schema_service_impl->get_routine_sql_service().drop_package(package_info, new_schema_version, trans, ddl_stmt_str))) { + } else if (OB_FAIL(schema_service_impl->get_routine_sql_service().drop_package(package_info.get_tenant_id(), + package_info.get_database_id(), + package_info.get_package_id(), + new_schema_version, trans, ddl_stmt_str))) { LOG_WARN("drop package info failed", K(package_info), K(ret)); } } diff --git a/src/rootserver/ob_ddl_operator.h b/src/rootserver/ob_ddl_operator.h index 3a53da4e6f..2a5665c269 100644 --- a/src/rootserver/ob_ddl_operator.h +++ b/src/rootserver/ob_ddl_operator.h @@ -183,7 +183,6 @@ public: const bool need_update_schema_version = true); virtual int drop_database(const share::schema::ObDatabaseSchema &db_schema, common::ObMySQLTransaction &trans, - share::schema::ObSchemaGetterGuard &guard, const common::ObString *ddl_stmt_str = NULL); virtual int create_tablegroup(share::schema::ObTablegroupSchema &tablegroup_schema, common::ObMySQLTransaction &trans, @@ -477,7 +476,6 @@ public: virtual int drop_database_to_recyclebin(const share::schema::ObDatabaseSchema &database_schema, common::ObMySQLTransaction &trans, - share::schema::ObSchemaGetterGuard &guard, const common::ObString *ddl_stmt_str); virtual int flashback_database_from_recyclebin(const share::schema::ObDatabaseSchema &database_schema, common::ObMySQLTransaction &trans, @@ -485,11 +483,9 @@ public: share::schema::ObSchemaGetterGuard &schema_guard, const common::ObString &ddl_stmt_str); virtual int purge_table_of_database(const share::schema::ObDatabaseSchema &db_schema, - common::ObMySQLTransaction &trans, - share::schema::ObSchemaGetterGuard &guard); + common::ObMySQLTransaction &trans); virtual int purge_database_in_recyclebin(const share::schema::ObDatabaseSchema &database_schema, common::ObMySQLTransaction &trans, - share::schema::ObSchemaGetterGuard &guard, const common::ObString *ddl_stmt_str); virtual int purge_table_with_aux_table( const share::schema::ObTableSchema &table_schema, @@ -1078,8 +1074,7 @@ private: common::ObMySQLTransaction &trans, share::schema::ObSchemaGetterGuard &schema_guard); int update_table_version_of_db(const share::schema::ObDatabaseSchema &database_schema, - common::ObMySQLTransaction &trans, - share::schema::ObSchemaGetterGuard &schema_guard); + common::ObMySQLTransaction &trans); int drop_trigger_cascade(const share::schema::ObTableSchema &table_schema, common::ObMySQLTransaction &trans); template diff --git a/src/rootserver/ob_ddl_service.cpp b/src/rootserver/ob_ddl_service.cpp index a3a6ee3997..33e4fe1e49 100755 --- a/src/rootserver/ob_ddl_service.cpp +++ b/src/rootserver/ob_ddl_service.cpp @@ -6098,7 +6098,7 @@ int ObDDLService::lock_tablets(ObMySQLTransaction &trans, } int ObDDLService::lock_table(ObMySQLTransaction &trans, - const ObTableSchema &table_schema) + const ObSimpleTableSchemaV2 &table_schema) { int ret = OB_SUCCESS; @@ -6131,23 +6131,27 @@ int ObDDLService::lock_table(ObMySQLTransaction &trans, } int ObDDLService::lock_tables_of_database(const ObDatabaseSchema &database_schema, - ObSchemaGetterGuard &schema_guard, ObMySQLTransaction &trans) { int ret = OB_SUCCESS; + ObSchemaGetterGuard schema_guard; const uint64_t tenant_id = database_schema.get_tenant_id(); const uint64_t database_id = database_schema.get_database_id(); - ObArray table_ids; - if (OB_FAIL(schema_guard.get_table_ids_in_database(tenant_id, - database_id, - table_ids))) { + ObArray table_schemas; + if (OB_ISNULL(schema_service_)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("schema_service is null", KR(ret)); + } else if (OB_FAIL(schema_service_->get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("fail to get schema guard", KR(ret), K(tenant_id)); + } else if (OB_FAIL(schema_guard.get_table_schemas_in_database(tenant_id, + database_id, + table_schemas))) { LOG_WARN("fail to get table ids in database", K(tenant_id), K(database_id), K(ret)); } else { - const ObTableSchema *table_schema = NULL; - for (int64_t i = 0; OB_SUCC(ret) && i < table_ids.count(); i++) { - if (OB_FAIL(schema_guard.get_table_schema(tenant_id, table_ids.at(i), table_schema))) { - LOG_WARN("fail to get table schema", K(ret), "table_id", table_ids.at(i)); - } else if (OB_ISNULL(table_schema)) { + const ObSimpleTableSchemaV2 *table_schema = NULL; + for (int64_t i = 0; OB_SUCC(ret) && i < table_schemas.count(); i++) { + table_schema = table_schemas.at(i); + if (OB_ISNULL(table_schema)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("table schema should not be null", K(ret)); } else if (!table_schema->check_can_do_ddl()) { @@ -6163,28 +6167,32 @@ int ObDDLService::lock_tables_of_database(const ObDatabaseSchema &database_schem } int ObDDLService::lock_tables_in_recyclebin(const ObDatabaseSchema &database_schema, - ObSchemaGetterGuard &schema_guard, ObMySQLTransaction &trans) { int ret = OB_SUCCESS; + ObSchemaGetterGuard schema_guard; ObArray recycle_objs; ObSchemaService *schema_service = nullptr; + const uint64_t tenant_id = database_schema.get_tenant_id(); + const uint64_t database_id = database_schema.get_database_id(); if (OB_ISNULL(schema_service_)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("schema_service is null", K(ret)); } else if (OB_ISNULL(schema_service = schema_service_->get_schema_service())) { ret = OB_ERR_UNEXPECTED; LOG_WARN("schema service is null", K(ret)); - } else if (OB_FAIL(schema_service->fetch_recycle_objects_of_db(database_schema.get_tenant_id(), - database_schema.get_database_id(), + } else if (OB_FAIL(schema_service->fetch_recycle_objects_of_db(tenant_id, + database_id, trans, recycle_objs))) { LOG_WARN("fetch recycle objects of db failed", K(ret)); + } else if (OB_FAIL(schema_service_->get_tenant_schema_guard(tenant_id, schema_guard))) { + LOG_WARN("fail to get schema guard", KR(ret), K(tenant_id)); } else { for (int64_t i = 0; OB_SUCC(ret) && i < recycle_objs.count(); ++i) { const ObRecycleObject &recycle_obj = recycle_objs.at(i); - const ObTableSchema* table_schema = NULL; - if (OB_FAIL(schema_guard.get_table_schema(recycle_obj.get_tenant_id(), + const ObSimpleTableSchemaV2* table_schema = NULL; + if (OB_FAIL(schema_guard.get_simple_table_schema(recycle_obj.get_tenant_id(), recycle_obj.get_table_id(), table_schema))) { LOG_WARN("get table schema failed", K(ret), K(recycle_obj)); } else if (OB_ISNULL(table_schema)) { @@ -22299,13 +22307,12 @@ int ObDDLService::purge_database( } else if (OB_ISNULL(pr_trans) && OB_FAIL(trans.start(sql_proxy_, tenant_id, refreshed_schema_version))) { LOG_WARN("start transaction failed", KR(ret), K(tenant_id), K(refreshed_schema_version)); - } else if (OB_FAIL(lock_tables_of_database(*database_schema, schema_guard, OB_ISNULL(pr_trans) ? trans : *pr_trans))) { + } else if (OB_FAIL(lock_tables_of_database(*database_schema, OB_ISNULL(pr_trans) ? trans : *pr_trans))) { LOG_WARN("failed to lock tables of database", K(ret)); - } else if (OB_FAIL(lock_tables_in_recyclebin(*database_schema, schema_guard, OB_ISNULL(pr_trans) ? trans : *pr_trans))) { + } else if (OB_FAIL(lock_tables_in_recyclebin(*database_schema, OB_ISNULL(pr_trans) ? trans : *pr_trans))) { LOG_WARN("failed to lock tables in recyclebin", K(ret)); } else if (OB_FAIL(ddl_operator.purge_database_in_recyclebin(*database_schema, OB_ISNULL(pr_trans) ? trans : *pr_trans, - schema_guard, &arg.ddl_stmt_str_))) { LOG_WARN("purge database failed", K(ret)); } @@ -28234,24 +28241,25 @@ int ObDDLService::drop_database(const ObDropDatabaseArg &arg, LOG_WARN("start transaction failed", KR(ret), K(tenant_id), K(refreshed_schema_version)); } else { ObDDLSQLTransaction &actual_trans = OB_ISNULL(ora_user_trans) ? trans : *ora_user_trans; - const ObTableSchema *schema = NULL; // lock table when drop data table - if (OB_FAIL(lock_tables_of_database(*db_schema, schema_guard, actual_trans))) { + if (OB_FAIL(lock_tables_of_database(*db_schema, actual_trans))) { LOG_WARN("lock tables of database", K(ret)); - } else if (!arg.to_recyclebin_ && OB_FAIL(lock_tables_in_recyclebin(*db_schema, schema_guard, actual_trans))) { + } else if (!arg.to_recyclebin_ && OB_FAIL(lock_tables_in_recyclebin(*db_schema, actual_trans))) { LOG_WARN("failed to lock tables in recyclebin", K(ret)); } if (OB_SUCC(ret) && arg.to_recyclebin_ && !is_inner_db(db_schema->get_database_id())) { if (OB_FAIL(ddl_operator.drop_database_to_recyclebin(*db_schema, - actual_trans, schema_guard, &arg.ddl_stmt_str_))) { + actual_trans, + &arg.ddl_stmt_str_))) { LOG_WARN("drop database to recyclebin failed", K(arg), K(ret)); } } else { if (OB_FAIL(ret)) { // FAIL - } else if (OB_FAIL(ddl_operator.drop_database(*db_schema, actual_trans, - schema_guard, &arg.ddl_stmt_str_))) { + } else if (OB_FAIL(ddl_operator.drop_database(*db_schema, + actual_trans, + &arg.ddl_stmt_str_))) { LOG_WARN("ddl_operator drop_database failed", K(tenant_id), KT(database_id), K(ret)); } } diff --git a/src/rootserver/ob_ddl_service.h b/src/rootserver/ob_ddl_service.h index 98d5d6598b..d3d5a13a7c 100644 --- a/src/rootserver/ob_ddl_service.h +++ b/src/rootserver/ob_ddl_service.h @@ -1176,7 +1176,7 @@ int check_table_udt_id_is_exist(share::schema::ObSchemaGetterGuard &schema_guard const ObTabletIDArray &tablet_ids); // lock table, unlock when ddl trans end int lock_table(ObMySQLTransaction &trans, - const share::schema::ObTableSchema &table_schema); + const ObSimpleTableSchemaV2 &table_schema); int recompile_view(const ObTableSchema &view_schema, const bool reset_view_column_infos, ObDDLSQLTransaction &trans); int recompile_all_views_batch(const uint64_t tenant_id, const common::ObIArray &view_ids); int try_add_dep_info_for_all_synonyms_batch(const uint64_t tenant_id, const common::ObIArray &synonym_ids); @@ -2006,10 +2006,8 @@ private: common::ObMySQLTransaction &trans, bool &is_add_lob); int lock_tables_of_database(const share::schema::ObDatabaseSchema &database_schema, - share::schema::ObSchemaGetterGuard &schema_guard, ObMySQLTransaction &trans); int lock_tables_in_recyclebin(const share::schema::ObDatabaseSchema &database_schema, - share::schema::ObSchemaGetterGuard &schema_guard, ObMySQLTransaction &trans); public: diff --git a/src/share/schema/ob_multi_version_schema_service.cpp b/src/share/schema/ob_multi_version_schema_service.cpp index 990c595406..f3f2ff98fc 100644 --- a/src/share/schema/ob_multi_version_schema_service.cpp +++ b/src/share/schema/ob_multi_version_schema_service.cpp @@ -4946,13 +4946,13 @@ int ObMultiVersionSchemaService::cal_purge_database_timeout_( } // cal sequences if (OB_SUCC(ret)) { - ObArray sequences; + ObArray sequence_schemas; if (OB_FAIL(get_tenant_schema_guard(tenant_id, schema_guard))) { LOG_WARN("fail to get tenant schema guard", KR(ret), K(tenant_id)); - } else if (OB_FAIL(schema_guard.get_sequence_infos_in_database(tenant_id, database_id, sequences))) { + } else if (OB_FAIL(schema_guard.get_sequence_schemas_in_database(tenant_id, database_id, sequence_schemas))) { LOG_WARN("fail to get sequences in database failed", KR(ret), K(tenant_id), K(database_id)); } else { - cal_database_timeout += sequences.count() * GCONF.rpc_timeout; + cal_database_timeout += sequence_schemas.count() * GCONF.rpc_timeout; } } // cal mock_fk diff --git a/src/share/schema/ob_outline_sql_service.cpp b/src/share/schema/ob_outline_sql_service.cpp index 926cdd4203..a456b3fbba 100644 --- a/src/share/schema/ob_outline_sql_service.cpp +++ b/src/share/schema/ob_outline_sql_service.cpp @@ -275,30 +275,6 @@ int ObOutlineSqlService::delete_outline(const uint64_t tenant_id, return ret; } - -int ObOutlineSqlService::drop_outline(const ObOutlineInfo &outline_info, - const int64_t new_schema_version, - common::ObISQLClient &sql_client, - const common::ObString *ddl_stmt_str) -{ - int ret = OB_SUCCESS; - ObSqlString sql; - const uint64_t tenant_id = outline_info.get_tenant_id(); - const uint64_t database_id = outline_info.get_database_id(); - const uint64_t outline_id = outline_info.get_outline_id(); - if (OB_UNLIKELY(OB_INVALID_ID ==tenant_id - || OB_INVALID_ID == database_id - || OB_INVALID_ID == outline_id)) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid outline info in drop outline", K(outline_info), K(ret)); - } else if (OB_FAIL(delete_outline(tenant_id, database_id, outline_id, - new_schema_version, sql_client, ddl_stmt_str))) { - LOG_WARN("failed to delete outline", K(outline_info), K(ret)); - } else {/*do nothing*/} - return ret; -} - - int ObOutlineSqlService::add_outline(common::ObISQLClient &sql_client, const ObOutlineInfo &outline_info, const bool only_history) diff --git a/src/share/schema/ob_outline_sql_service.h b/src/share/schema/ob_outline_sql_service.h index c1c06f4998..bed9079901 100644 --- a/src/share/schema/ob_outline_sql_service.h +++ b/src/share/schema/ob_outline_sql_service.h @@ -50,11 +50,6 @@ public: const int64_t new_schema_version, common::ObISQLClient &sql_client, const common::ObString *ddl_stmt_str = NULL); - - virtual int drop_outline(const ObOutlineInfo &outline_info, - const int64_t new_schema_version, - common::ObISQLClient &sql_client, - const common::ObString *ddl_stmt_str = NULL); private: int add_outline(common::ObISQLClient &sql_client, const ObOutlineInfo &outline_info, const bool only_history = false); diff --git a/src/share/schema/ob_routine_sql_service.cpp b/src/share/schema/ob_routine_sql_service.cpp index 1b2faa152d..4ead36ab86 100644 --- a/src/share/schema/ob_routine_sql_service.cpp +++ b/src/share/schema/ob_routine_sql_service.cpp @@ -60,27 +60,26 @@ int ObRoutineSqlService::create_package(ObPackageInfo &package_info, return ret; } -int ObRoutineSqlService::drop_package(const ObPackageInfo &package_info, +int ObRoutineSqlService::drop_package(const uint64_t tenant_id, + const uint64_t database_id, + const uint64_t package_id, const int64_t new_schema_version, ObISQLClient &sql_client, const ObString *ddl_stmt_str) { int ret = OB_SUCCESS; - uint64_t tenant_id = package_info.get_tenant_id(); - uint64_t db_id = package_info.get_database_id(); - uint64_t package_id = package_info.get_package_id(); if (OB_UNLIKELY(OB_INVALID_ID == tenant_id) - || OB_UNLIKELY(OB_INVALID_ID == db_id) + || OB_UNLIKELY(OB_INVALID_ID == database_id) || OB_UNLIKELY(OB_INVALID_ID == package_id)) { ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid package info in drop procedure", K(tenant_id), K(db_id), K(package_id)); - } else if (OB_FAIL(del_package(sql_client, package_info, new_schema_version))) { + LOG_WARN("invalid package info in drop procedure", KR(ret), K(tenant_id), K(database_id), K(package_id)); + } else if (OB_FAIL(del_package(sql_client, tenant_id, package_id, new_schema_version))) { LOG_WARN("delete package failed", K(ret)); } else { ObSchemaOperation opt; - opt.tenant_id_ = package_info.get_tenant_id(); - opt.database_id_ = package_info.get_database_id(); - opt.table_id_ = package_info.get_package_id(); + opt.tenant_id_ = tenant_id; + opt.database_id_ = database_id; + opt.table_id_ = package_id; opt.op_type_ = OB_DDL_DROP_PACKAGE; opt.schema_version_ = new_schema_version; opt.ddl_stmt_str_ = (NULL != ddl_stmt_str) ? *ddl_stmt_str : ObString(); @@ -289,16 +288,15 @@ int ObRoutineSqlService::drop_routine(const ObRoutineInfo &routine_info, } int ObRoutineSqlService::del_package(ObISQLClient &sql_client, - const ObPackageInfo &package_info, + const uint64_t tenant_id, + const uint64_t package_id, int64_t new_schema_version) { int ret = OB_SUCCESS; int64_t affected_rows = 0; ObDMLSqlSplicer dml; ObSqlString sql; - uint64_t tenant_id = package_info.get_tenant_id(); const uint64_t exec_tenant_id = ObSchemaUtils::get_exec_tenant_id(tenant_id); - uint64_t package_id = package_info.get_package_id(); if (OB_FAIL(dml.add_pk_column("tenant_id", ObSchemaUtils::get_extract_tenant_id( exec_tenant_id, tenant_id))) diff --git a/src/share/schema/ob_routine_sql_service.h b/src/share/schema/ob_routine_sql_service.h index 16b8e6574c..283d0346c2 100644 --- a/src/share/schema/ob_routine_sql_service.h +++ b/src/share/schema/ob_routine_sql_service.h @@ -58,7 +58,9 @@ public: int alter_package(const ObPackageInfo &package_info, common::ObISQLClient *sql_client, const common::ObString *ddl_stmt_str); - int drop_package(const ObPackageInfo &package_info, + int drop_package(const uint64_t tenant_id, + const uint64_t database_id, + const uint64_t package_id, const int64_t new_schema_version, common::ObISQLClient &sql_client, const common::ObString *ddl_stmt_str = NULL); @@ -75,7 +77,8 @@ private: bool is_replace, bool only_history = false); int del_package(common::ObISQLClient &sql_client, - const ObPackageInfo &package_info, + const uint64_t tenant_id, + const uint64_t package_id, int64_t new_schema_version); int gen_routine_dml(const uint64_t exec_tenant_id, const ObRoutineInfo &routine_info, diff --git a/src/share/schema/ob_schema_getter_guard.cpp b/src/share/schema/ob_schema_getter_guard.cpp index 775f8c3939..438f649a34 100644 --- a/src/share/schema/ob_schema_getter_guard.cpp +++ b/src/share/schema/ob_schema_getter_guard.cpp @@ -574,60 +574,13 @@ int ObSchemaGetterGuard::get_user_id(uint64_t tenant_id, return ret; } -int ObSchemaGetterGuard::get_outline_infos_in_database( - const uint64_t tenant_id, - const uint64_t database_id, - ObIArray &outline_infos) +int ObSchemaGetterGuard::get_trigger_ids_in_database(const uint64_t tenant_id, + const uint64_t database_id, + ObIArray &trigger_ids) { int ret = OB_SUCCESS; const ObSchemaMgr *mgr = NULL; - outline_infos.reset(); - - ObArray schemas; - if (!check_inner_stat()) { - ret = OB_INNER_STAT_ERROR; - LOG_WARN("inner stat error", KR(ret)); - } else if (OB_INVALID_ID == tenant_id || OB_INVALID_ID == database_id) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid argument", KR(ret), K(tenant_id), K(database_id)); - } else if (OB_FAIL(check_tenant_schema_guard(tenant_id))) { - LOG_WARN("fail to check tenant schema guard", KR(ret), K(tenant_id), K_(tenant_id)); - } else if (OB_FAIL(check_lazy_guard(tenant_id, mgr))) { - LOG_WARN("fail to check lazy guard", KR(ret), K(tenant_id)); - } else if (OB_FAIL(mgr->outline_mgr_.get_outline_schemas_in_database(tenant_id, - database_id, schemas))) { - LOG_WARN("get outlne schemas in database failed", KR(ret), K(tenant_id), K(database_id)); - } else { - FOREACH_CNT_X(schema, schemas, OB_SUCC(ret)) { - const ObSimpleOutlineSchema *tmp_schema = *schema; - const ObOutlineInfo *outline_info = NULL; - if (OB_ISNULL(tmp_schema)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("NULL ptr", KR(ret), KP(tmp_schema)); - } else if (OB_FAIL(get_schema(OUTLINE_SCHEMA, - tmp_schema->get_tenant_id(), - tmp_schema->get_outline_id(), - outline_info, - tmp_schema->get_schema_version()))) { - LOG_WARN("get schema failed", KR(ret), K(tenant_id), - "outline_id", tmp_schema->get_outline_id(), - "schema_version", tmp_schema->get_schema_version()); - } else if (OB_FAIL(outline_infos.push_back(outline_info))) { - LOG_WARN("add outline schema failed", KR(ret)); - } - } - } - - return ret; -} - -int ObSchemaGetterGuard::get_trigger_infos_in_database(const uint64_t tenant_id, - const uint64_t database_id, - common::ObIArray &tg_infos) -{ - int ret = OB_SUCCESS; - const ObSchemaMgr *mgr = NULL; - tg_infos.reset(); + trigger_ids.reset(); ObArray tg_schemas; if (!check_inner_stat()) { @@ -642,21 +595,15 @@ int ObSchemaGetterGuard::get_trigger_infos_in_database(const uint64_t tenant_id, LOG_WARN("fail to check lazy guard", KR(ret), K(tenant_id)); } else if (OB_FAIL(mgr->trigger_mgr_.get_trigger_schemas_in_database(tenant_id, database_id, tg_schemas))) { LOG_WARN("get trigger schemas in database failed", KR(ret), K(tenant_id), K(database_id)); + } else if (OB_FAIL(trigger_ids.reserve(tg_schemas.count()))) { + LOG_WARN("fail to reserve trigger_ids", KR(ret), K(tenant_id), K(database_id)); } else { FOREACH_CNT_X(tg, tg_schemas, OB_SUCC(ret)) { const ObSimpleTriggerSchema *tmp_tg = *tg; - const ObTriggerInfo *tg_info = NULL; if (OB_ISNULL(tmp_tg)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("NULL ptr", KR(ret), KP(tmp_tg)); - } else if (OB_FAIL(get_schema(TRIGGER_SCHEMA, - tmp_tg->get_tenant_id(), - tmp_tg->get_trigger_id(), - tg_info, - tmp_tg->get_schema_version()))) { - LOG_WARN("get schema failed", KR(ret), K(tenant_id), - K(tmp_tg->get_trigger_id()), K(tmp_tg->get_schema_version())); - } else if (OB_FAIL(tg_infos.push_back(tg_info))) { + } else if (OB_FAIL(trigger_ids.push_back(tmp_tg->get_trigger_id()))) { LOG_WARN("add trigger infos failed", KR(ret)); } } @@ -664,112 +611,19 @@ int ObSchemaGetterGuard::get_trigger_infos_in_database(const uint64_t tenant_id, return ret; } -int ObSchemaGetterGuard::get_synonym_infos_in_database( - const uint64_t tenant_id, - const uint64_t database_id, - ObIArray &synonym_infos) +int ObSchemaGetterGuard::get_routine_ids_in_database(const uint64_t tenant_id, + const uint64_t database_id, + common::ObIArray &routine_ids) { int ret = OB_SUCCESS; const ObSchemaMgr *mgr = NULL; - synonym_infos.reset(); - - ObArray schemas; - if (!check_inner_stat()) { - ret = OB_INNER_STAT_ERROR; - LOG_WARN("inner stat error", KR(ret)); - } else if (OB_INVALID_ID == tenant_id || OB_INVALID_ID == database_id) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid argument", KR(ret), K(tenant_id), K(database_id)); - } else if (OB_FAIL(check_tenant_schema_guard(tenant_id))) { - LOG_WARN("fail to check tenant schema guard", KR(ret), K(tenant_id), K_(tenant_id)); - } else if (OB_FAIL(check_lazy_guard(tenant_id, mgr))) { - LOG_WARN("fail to check lazy guard", KR(ret), K(tenant_id)); - } else if (OB_FAIL(mgr->synonym_mgr_.get_synonym_schemas_in_database(tenant_id, - database_id, schemas))) { - LOG_WARN("get synonym schemas in database failed", KR(ret), K(tenant_id), K(database_id)); - } else { - FOREACH_CNT_X(schema, schemas, OB_SUCC(ret)) { - const ObSimpleSynonymSchema *tmp_schema = *schema; - const ObSynonymInfo *synonym_info = NULL; - if (OB_ISNULL(tmp_schema)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("NULL ptr", KR(ret), KP(tmp_schema)); - } else if (OB_FAIL(get_schema(SYNONYM_SCHEMA, - tmp_schema->get_tenant_id(), - tmp_schema->get_synonym_id(), - synonym_info, - tmp_schema->get_schema_version()))) { - LOG_WARN("get schema failed", KR(ret), K(tenant_id), - "synonym_id", tmp_schema->get_synonym_id(), - "schema_version", tmp_schema->get_schema_version()); - } else if (OB_FAIL(synonym_infos.push_back(synonym_info))) { - LOG_WARN("add synonym schema failed", KR(ret)); - } - } - } - - return ret; -} - -int ObSchemaGetterGuard::get_package_infos_in_database(const uint64_t tenant_id, - const uint64_t database_id, - common::ObIArray &package_infos) -{ - int ret = OB_SUCCESS; - const ObSchemaMgr *mgr = NULL; - package_infos.reset(); - - ObArray schemas; - if (!check_inner_stat()) { - ret = OB_INNER_STAT_ERROR; - LOG_WARN("inner stat error", KR(ret)); - } else if (OB_INVALID_ID == tenant_id || OB_INVALID_ID == database_id) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid argument", KR(ret), K(tenant_id), K(database_id)); - } else if (OB_FAIL(check_tenant_schema_guard(tenant_id))) { - LOG_WARN("fail to check tenant schema guard", KR(ret), K(tenant_id), K_(tenant_id)); - } else if (OB_FAIL(check_lazy_guard(tenant_id, mgr))) { - LOG_WARN("fail to check lazy guard", KR(ret), K(tenant_id)); - } else if (OB_FAIL(mgr->package_mgr_.get_package_schemas_in_database(tenant_id, - database_id, schemas))) { - LOG_WARN("get package schemas in database failed", KR(ret), K(tenant_id), K(database_id)); - } else { - FOREACH_CNT_X(schema, schemas, OB_SUCC(ret)) { - const ObSimplePackageSchema *tmp_schema = *schema; - const ObPackageInfo *package_info = NULL; - if (OB_ISNULL(tmp_schema)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("NULL ptr", KR(ret), KP(tmp_schema)); - } else if (OB_FAIL(get_schema(PACKAGE_SCHEMA, - tmp_schema->get_tenant_id(), - tmp_schema->get_package_id(), - package_info, - tmp_schema->get_schema_version()))) { - LOG_WARN("get schema failed", KR(ret), K(tenant_id), - "package_id", tmp_schema->get_package_id(), - "schema_version", tmp_schema->get_schema_version()); - } else if (OB_FAIL(package_infos.push_back(package_info))) { - LOG_WARN("add package schema failed", KR(ret)); - } - } - } - - return ret; -} - -int ObSchemaGetterGuard::get_routine_infos_in_database(const uint64_t tenant_id, - const uint64_t database_id, - common::ObIArray &routine_infos) -{ - int ret = OB_SUCCESS; - const ObSchemaMgr *mgr = NULL; - routine_infos.reset(); + routine_ids.reset(); ObArray schemas; - if (!check_inner_stat()) { + if (OB_UNLIKELY(!check_inner_stat())) { ret = OB_INNER_STAT_ERROR; LOG_WARN("inner stat error", KR(ret)); - } else if (OB_INVALID_ID == tenant_id || OB_INVALID_ID == database_id) { + } else if (OB_UNLIKELY(OB_INVALID_ID == tenant_id || OB_INVALID_ID == database_id)) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid argument", KR(ret), K(tenant_id), K(database_id)); } else if (OB_FAIL(check_tenant_schema_guard(tenant_id))) { @@ -778,22 +632,15 @@ int ObSchemaGetterGuard::get_routine_infos_in_database(const uint64_t tenant_id, LOG_WARN("fail to check lazy guard", KR(ret), K(tenant_id)); } else if (OB_FAIL(mgr->routine_mgr_.get_routine_schemas_in_database(tenant_id, database_id, schemas))) { LOG_WARN("get routine schemas in database failed", KR(ret), K(tenant_id), K(database_id)); + } else if (OB_FAIL(routine_ids.reserve(schemas.count()))) { + LOG_WARN("fail to reserve routine_ids", KR(ret), K(tenant_id), K(database_id)); } else { FOREACH_CNT_X(schema, schemas, OB_SUCC(ret)) { const ObSimpleRoutineSchema *tmp_schema = *schema; - const ObRoutineInfo *routine_info = NULL; if (OB_ISNULL(tmp_schema)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("NULL ptr", KR(ret), KP(tmp_schema)); - } else if (OB_FAIL(get_schema(ROUTINE_SCHEMA, - tmp_schema->get_tenant_id(), - tmp_schema->get_routine_id(), - routine_info, - tmp_schema->get_schema_version()))) { - LOG_WARN("get schema failed", KR(ret), K(tenant_id), - "routine_id", tmp_schema->get_routine_id(), - "schema_version", tmp_schema->get_schema_version()); - } else if (OB_FAIL(routine_infos.push_back(routine_info))) { + } else if (OB_FAIL(routine_ids.push_back(tmp_schema->get_routine_id()))) { LOG_WARN("add routine schema failed", KR(ret)); } } @@ -991,19 +838,19 @@ int ObSchemaGetterGuard::get_routine_infos_in_package( return ret; } -int ObSchemaGetterGuard::get_udt_infos_in_database(const uint64_t tenant_id, - const uint64_t database_id, - common::ObIArray &udt_infos) +int ObSchemaGetterGuard::get_udt_ids_in_database(const uint64_t tenant_id, + const uint64_t database_id, + common::ObIArray &udt_ids) { int ret = OB_SUCCESS; const ObSchemaMgr *mgr = NULL; - udt_infos.reset(); + udt_ids.reset(); ObArray schemas; - if (!check_inner_stat()) { + if (OB_UNLIKELY(!check_inner_stat())) { ret = OB_INNER_STAT_ERROR; LOG_WARN("inner stat error", KR(ret)); - } else if (OB_INVALID_ID == tenant_id || OB_INVALID_ID == database_id) { + } else if (OB_UNLIKELY(OB_INVALID_ID == tenant_id || OB_INVALID_ID == database_id)) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid argument", KR(ret), K(tenant_id), K(database_id)); } else if (OB_FAIL(check_tenant_schema_guard(tenant_id))) { @@ -1012,22 +859,15 @@ int ObSchemaGetterGuard::get_udt_infos_in_database(const uint64_t tenant_id, LOG_WARN("fail to check lazy guard", KR(ret), K(tenant_id)); } else if (OB_FAIL(mgr->udt_mgr_.get_udt_schemas_in_database(tenant_id, database_id, schemas))) { LOG_WARN("get udt schemas in database failed", KR(ret), K(tenant_id), K(database_id)); + } else if (OB_FAIL(udt_ids.reserve(schemas.count()))) { + LOG_WARN("fail to reserve udt_ids", KR(ret), K(tenant_id), K(database_id)); } else { FOREACH_CNT_X(schema, schemas, OB_SUCC(ret)) { const ObSimpleUDTSchema *tmp_schema = *schema; - const ObUDTTypeInfo *udt_info = NULL; if (OB_ISNULL(tmp_schema)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("NULL ptr", KR(ret), KP(tmp_schema)); - } else if (OB_FAIL(get_schema(UDT_SCHEMA, - tmp_schema->get_tenant_id(), - tmp_schema->get_type_id(), - udt_info, - tmp_schema->get_schema_version()))) { - LOG_WARN("get schema failed", KR(ret), K(tenant_id), - "udt_id", tmp_schema->get_type_id(), - "schema_version", tmp_schema->get_schema_version()); - } else if (OB_FAIL(udt_infos.push_back(udt_info))) { + } else if (OB_FAIL(udt_ids.push_back(tmp_schema->get_type_id()))) { LOG_WARN("add udt schema failed", KR(ret)); } } @@ -1035,16 +875,15 @@ int ObSchemaGetterGuard::get_udt_infos_in_database(const uint64_t tenant_id, return ret; } -int ObSchemaGetterGuard::get_sequence_infos_in_database( +int ObSchemaGetterGuard::get_sequence_schemas_in_database( const uint64_t tenant_id, const uint64_t database_id, - common::ObIArray &sequence_infos) + common::ObIArray &sequence_schemas) { int ret = OB_SUCCESS; const ObSchemaMgr *mgr = NULL; - sequence_infos.reset(); + sequence_schemas.reset(); - ObArray schemas; if (!check_inner_stat()) { ret = OB_INNER_STAT_ERROR; LOG_WARN("inner stat error", KR(ret)); @@ -1055,27 +894,8 @@ int ObSchemaGetterGuard::get_sequence_infos_in_database( LOG_WARN("fail to check tenant schema guard", KR(ret), K(tenant_id), K_(tenant_id)); } else if (OB_FAIL(check_lazy_guard(tenant_id, mgr))) { LOG_WARN("fail to check lazy guard", KR(ret), K(tenant_id)); - } else if (OB_FAIL(mgr->sequence_mgr_.get_sequence_schemas_in_database(tenant_id, database_id, schemas))) { + } else if (OB_FAIL(mgr->sequence_mgr_.get_sequence_schemas_in_database(tenant_id, database_id, sequence_schemas))) { LOG_WARN("get sequence schemas in database failed", KR(ret), K(tenant_id), K(database_id)); - } else { - FOREACH_CNT_X(schema, schemas, OB_SUCC(ret)) { - const ObSequenceSchema *tmp_schema = *schema; - const ObSequenceSchema *sequence_info = NULL; - if (OB_ISNULL(tmp_schema)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("NULL ptr", KR(ret), KP(tmp_schema)); - } else if (OB_FAIL(get_schema(SEQUENCE_SCHEMA, - tmp_schema->get_tenant_id(), - tmp_schema->get_sequence_id(), - sequence_info, - tmp_schema->get_schema_version()))) { - LOG_WARN("get schema failed", KR(ret), K(tenant_id), - "sequence_id", tmp_schema->get_sequence_id(), - "schema_version", tmp_schema->get_schema_version()); - } else if (OB_FAIL(sequence_infos.push_back(sequence_info))) { - LOG_WARN("add sequence schema failed", KR(ret)); - } - } } return ret; } @@ -8211,19 +8031,20 @@ int ObSchemaGetterGuard::get_context_schema_with_name(const uint64_t tenant_id, } // mock_fk_parent_table begin -int ObSchemaGetterGuard::get_mock_fk_parent_table_schemas_in_database( +int ObSchemaGetterGuard::get_mock_fk_parent_table_ids_in_database( const uint64_t tenant_id, const uint64_t database_id, - ObIArray &full_schemas) + ObIArray &mock_fk_parent_table_ids) { int ret= OB_SUCCESS; const ObSchemaMgr *mgr = NULL; + mock_fk_parent_table_ids.reset(); ObArray simple_schemas; - if (!check_inner_stat()) { + if (OB_UNLIKELY(!check_inner_stat())) { ret = OB_INNER_STAT_ERROR; LOG_WARN("inner stat error", K(ret)); - } else if (OB_INVALID_ID == tenant_id - || OB_INVALID_ID == database_id) { + } else if (OB_UNLIKELY(OB_INVALID_ID == tenant_id + || OB_INVALID_ID == database_id)) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid argument", K(ret), K(tenant_id), K(database_id)); } else if (OB_FAIL(check_tenant_schema_guard(tenant_id))) { @@ -8233,21 +8054,16 @@ int ObSchemaGetterGuard::get_mock_fk_parent_table_schemas_in_database( } else if (OB_FAIL(mgr->mock_fk_parent_table_mgr_.get_mock_fk_parent_table_schemas_in_database( tenant_id, database_id, simple_schemas))) { LOG_WARN("get schemas failed", K(ret), K(tenant_id), K(database_id)); + } else if (OB_FAIL(mock_fk_parent_table_ids.reserve(simple_schemas.count()))) { + LOG_WARN("fail to reserve mock_fk_parent_table_ids", KR(ret), K(tenant_id), K(database_id)); } else { - - for (int64_t i = 0; OB_SUCC(ret) && i < simple_schemas.count(); ++i) { - const ObMockFKParentTableSchema *full_schema = NULL; - if (OB_ISNULL(simple_schemas.at(i))) { + FOREACH_CNT_X(schema, simple_schemas, OB_SUCC(ret)) { + const ObSimpleMockFKParentTableSchema *tmp_schema = *schema; + if (OB_ISNULL(tmp_schema)) { ret = OB_ERR_UNEXPECTED; - LOG_WARN("NULL ptr", K(ret)); - } else if (OB_FAIL(get_schema(MOCK_FK_PARENT_TABLE_SCHEMA, - simple_schemas.at(i)->get_tenant_id(), - simple_schemas.at(i)->get_mock_fk_parent_table_id(), - full_schema, - simple_schemas.at(i)->get_schema_version()))) { - LOG_WARN("get mock fk parent table schema failed", K(ret), K(simple_schemas.at(i))); - } else if (OB_FAIL(full_schemas.push_back(full_schema))) { - LOG_WARN("add outline schema failed", K(ret)); + LOG_WARN("NULL ptr", KR(ret), KP(tmp_schema)); + } else if (OB_FAIL(mock_fk_parent_table_ids.push_back(tmp_schema->get_mock_fk_parent_table_id()))) { + LOG_WARN("add parent_table ids failed", KR(ret), K(tenant_id), K(tmp_schema->get_mock_fk_parent_table_id())); } } } diff --git a/src/share/schema/ob_schema_getter_guard.h b/src/share/schema/ob_schema_getter_guard.h index 053cb1f300..121e038852 100644 --- a/src/share/schema/ob_schema_getter_guard.h +++ b/src/share/schema/ob_schema_getter_guard.h @@ -285,25 +285,15 @@ public: int get_table_ids_in_tablegroup(const uint64_t tenant_id, const uint64_t tablegroup_id, common::ObIArray &table_id_array); - int get_outline_infos_in_database(const uint64_t tenant_id, - const uint64_t database_id, - common::ObIArray &outline_infos); - int get_trigger_infos_in_database(const uint64_t tenant_id, - const uint64_t database_id, - common::ObIArray &tg_infos); - int get_synonym_infos_in_database(const uint64_t tenant_id, - const uint64_t database_id, - common::ObIArray &synonym_infos); - - int get_package_infos_in_database(const uint64_t tenant_id, - const uint64_t database_id, - common::ObIArray &package_infos); - int get_routine_infos_in_database(const uint64_t tenant_id, - const uint64_t database_id, - common::ObIArray &routine_infos); - int get_udt_infos_in_database(const uint64_t tenant_id, - const uint64_t database_id, - common::ObIArray &udt_infos); + int get_trigger_ids_in_database(const uint64_t tenant_id, + const uint64_t database_id, + common::ObIArray &trigger_ids); + int get_routine_ids_in_database(const uint64_t tenant_id, + const uint64_t database_id, + common::ObIArray &routine_ids); + int get_udt_ids_in_database(const uint64_t tenant_id, + const uint64_t database_id, + common::ObIArray &udt_ids); int get_routine_info_in_udt(const uint64_t tenant_id, const uint64_t udt_id, const uint64_t subprogram_id, @@ -318,9 +308,9 @@ public: int get_routine_infos_in_package(const uint64_t tenant_id, const uint64_t package_id, common::ObIArray &routine_infos); - int get_sequence_infos_in_database(const uint64_t tenant_id, - const uint64_t database_id, - common::ObIArray &sequence_infos); + int get_sequence_schemas_in_database(const uint64_t tenant_id, + const uint64_t database_id, + common::ObIArray &sequence_schemas); int get_label_se_policy_infos_in_tenant(const uint64_t tenant_id, common::ObIArray &label_se_policy_infos); int get_label_se_component_infos_in_tenant(const uint64_t tenant_id, @@ -793,9 +783,9 @@ public: const ObContextSchema *&context_schema); // mock_fk_parent_table begin - int get_mock_fk_parent_table_schemas_in_database(const uint64_t tenant_id, - const uint64_t database_id, - ObIArray &schemas); + int get_mock_fk_parent_table_ids_in_database(const uint64_t tenant_id, + const uint64_t database_id, + ObIArray &mock_fk_parent_table_ids); int get_simple_mock_fk_parent_table_schema(const uint64_t tenant_id, const uint64_t database_id, const common::ObString &name, diff --git a/src/share/schema/ob_sequence_sql_service.cpp b/src/share/schema/ob_sequence_sql_service.cpp index d6118e7d65..2c9b25eda7 100644 --- a/src/share/schema/ob_sequence_sql_service.cpp +++ b/src/share/schema/ob_sequence_sql_service.cpp @@ -283,7 +283,9 @@ int ObSequenceSqlService::delete_sequence(const uint64_t tenant_id, ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid sql client is NULL", K(ret)); } else if (OB_UNLIKELY(OB_INVALID_ID == tenant_id - || OB_INVALID_ID == sequence_id)) { + || OB_INVALID_ID == sequence_id + || OB_INVALID_ID == database_id + || new_schema_version < 0)) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid sequence info in drop sequence", K(tenant_id), K(database_id), K(sequence_id), K(ret)); diff --git a/src/share/schema/ob_synonym_sql_service.cpp b/src/share/schema/ob_synonym_sql_service.cpp index 2dddc2a2b0..6512f5fa14 100644 --- a/src/share/schema/ob_synonym_sql_service.cpp +++ b/src/share/schema/ob_synonym_sql_service.cpp @@ -195,33 +195,6 @@ int ObSynonymSqlService::delete_synonym(const uint64_t tenant_id, return ret; } - -int ObSynonymSqlService::drop_synonym(const ObSynonymInfo &synonym_info, - const int64_t new_schema_version, - common::ObISQLClient *sql_client, - const common::ObString *ddl_stmt_str) -{ - int ret = OB_SUCCESS; - ObSqlString sql; - const uint64_t tenant_id = synonym_info.get_tenant_id(); - const uint64_t database_id = synonym_info.get_database_id(); - const uint64_t synonym_id = synonym_info.get_synonym_id(); - if (OB_ISNULL(sql_client)) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid sql client is NULL", K(ret)); - } else if (OB_UNLIKELY(OB_INVALID_ID ==tenant_id - || OB_INVALID_ID == database_id - || OB_INVALID_ID == synonym_id)) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid synonym info in drop synonym", K(synonym_info.get_synonym_name_str()), K(ret)); - } else if (OB_FAIL(delete_synonym(tenant_id, database_id, synonym_id, - new_schema_version, sql_client, ddl_stmt_str))) { - LOG_WARN("failed to delete synonym", K(synonym_info.get_synonym_name_str()), K(ret)); - } else {/*do nothing*/} - return ret; -} - - int ObSynonymSqlService::add_synonym(common::ObISQLClient &sql_client, const ObSynonymInfo &synonym_info, const bool only_history) diff --git a/src/share/schema/ob_synonym_sql_service.h b/src/share/schema/ob_synonym_sql_service.h index 9dbb2137cb..7792c4f8b1 100644 --- a/src/share/schema/ob_synonym_sql_service.h +++ b/src/share/schema/ob_synonym_sql_service.h @@ -47,11 +47,6 @@ public: const int64_t new_schema_version, common::ObISQLClient *sql_client, const common::ObString *ddl_stmt_str = NULL); - - virtual int drop_synonym(const ObSynonymInfo &synonym_info, - const int64_t new_schema_version, - common::ObISQLClient *sql_client, - const common::ObString *ddl_stmt_str = NULL); private: int add_synonym(common::ObISQLClient &sql_client, const ObSynonymInfo &synonym_info, const bool only_history = false);