From 25802234e0e112ab3fb7cc48afb0d5cf0093315d Mon Sep 17 00:00:00 2001 From: obdev Date: Tue, 25 Jul 2023 15:12:29 +0000 Subject: [PATCH] fill ddl_stmt_str when enabling index for create index syntax. --- .../ddl_task/ob_index_build_task.cpp | 18 ++++++++++++++++-- src/rootserver/ob_ddl_operator.cpp | 5 +++-- src/rootserver/ob_ddl_operator.h | 3 ++- src/rootserver/ob_ddl_service.cpp | 13 ++++++++----- src/share/schema/ob_table_sql_service.cpp | 8 +++++--- src/share/schema/ob_table_sql_service.h | 3 ++- 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/rootserver/ddl_task/ob_index_build_task.cpp b/src/rootserver/ddl_task/ob_index_build_task.cpp index 27812e9b8f..7ce82b5e10 100755 --- a/src/rootserver/ddl_task/ob_index_build_task.cpp +++ b/src/rootserver/ddl_task/ob_index_build_task.cpp @@ -1214,6 +1214,19 @@ int ObIndexBuildTask::update_index_status_in_schema(const ObTableSchema &index_s arg.task_id_ = task_id_; int64_t ddl_rpc_timeout = 0; int64_t tmp_timeout = 0; + if (INDEX_STATUS_AVAILABLE == new_status) { + const bool is_create_index_syntax = create_index_arg_.ddl_stmt_str_.trim().prefix_match_ci("create"); + if (create_index_arg_.ddl_stmt_str_.empty()) { + // alter table syntax. + } else if (OB_UNLIKELY(!is_create_index_syntax)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected err", K(ret), "ddl_stmt_str", create_index_arg_.ddl_stmt_str_, K(create_index_arg_)); + } else { + // For create index syntax, create_index_arg_ will record the user sql, and generate the ddl_stmt_str when anabling index. + // For alter table add index syntax, create_index_arg_ will not record the user sql, and generate the ddl_stmt_str when generating index schema. + arg.ddl_stmt_str_ = create_index_arg_.ddl_stmt_str_; + } + } DEBUG_SYNC(BEFORE_UPDATE_GLOBAL_INDEX_STATUS); if (OB_FAIL(ObDDLUtil::get_ddl_rpc_timeout(index_schema.get_all_part_num(), ddl_rpc_timeout))) { @@ -1224,7 +1237,7 @@ int ObIndexBuildTask::update_index_status_in_schema(const ObTableSchema &index_s } else if (OB_FAIL(root_service_->get_common_rpc_proxy().to(GCTX.self_addr()).timeout(ddl_rpc_timeout).update_index_status(arg))) { LOG_WARN("update index status failed", K(ret), K(arg)); } else { - LOG_INFO("notify index status changed finish", K(new_status), K(index_table_id_), K(ddl_rpc_timeout)); + LOG_INFO("notify index status changed finish", K(new_status), K(index_table_id_), K(ddl_rpc_timeout), "ddl_stmt_str", arg.ddl_stmt_str_); } } return ret; @@ -1302,7 +1315,8 @@ int ObIndexBuildTask::clean_on_failed() index_name = "__fake"; } else if (OB_FAIL(index_schema->get_index_name(index_name))) { LOG_WARN("get index name failed", K(ret)); - } else if (0 == parent_task_id_) { + } else if (0 == parent_task_id_ + && !create_index_arg_.ddl_stmt_str_.trim().prefix_match_ci("create")) { // generate ddl_stmt if it is not a child task. if (is_oracle_mode) { if (OB_FAIL(drop_index_sql.append_fmt("drop index \"%.*s\"", index_name.length(), index_name.ptr()))) { diff --git a/src/rootserver/ob_ddl_operator.cpp b/src/rootserver/ob_ddl_operator.cpp index 33e3ad9510..21072aa1e8 100644 --- a/src/rootserver/ob_ddl_operator.cpp +++ b/src/rootserver/ob_ddl_operator.cpp @@ -3796,7 +3796,8 @@ int ObDDLOperator::update_index_status( const uint64_t index_table_id, const share::schema::ObIndexStatus status, const bool in_offline_ddl_white_list, - common::ObMySQLTransaction &trans) + common::ObMySQLTransaction &trans, + const common::ObString *ddl_stmt_str) { int ret = OB_SUCCESS; int64_t new_schema_version = OB_INVALID_VERSION; @@ -3825,7 +3826,7 @@ int ObDDLOperator::update_index_status( LOG_WARN("fail to gen new schema_version", K(ret), K(tenant_id)); } else if (FALSE_IT(copy_data_table_schema.set_in_offline_ddl_white_list(in_offline_ddl_white_list))) { } else if (OB_FAIL(schema_service->get_table_sql_service().update_index_status( - copy_data_table_schema, index_table_id, status, new_schema_version, trans))) { + copy_data_table_schema, index_table_id, status, new_schema_version, trans, ddl_stmt_str))) { LOG_WARN("update index status failed", K(ret), K(data_table_id), K(index_table_id), K(status)); } diff --git a/src/rootserver/ob_ddl_operator.h b/src/rootserver/ob_ddl_operator.h index 13d3143723..06d21eac03 100644 --- a/src/rootserver/ob_ddl_operator.h +++ b/src/rootserver/ob_ddl_operator.h @@ -510,7 +510,8 @@ public: const uint64_t index_table_id, const share::schema::ObIndexStatus status, const bool in_offline_ddl_white_list, - common::ObMySQLTransaction &trans); + common::ObMySQLTransaction &trans, + const common::ObString *ddl_stmt_str); // tablespace virtual int create_tablespace(share::schema::ObTablespaceSchema &tablespace_schema, diff --git a/src/rootserver/ob_ddl_service.cpp b/src/rootserver/ob_ddl_service.cpp index e441d65805..344ee44b1e 100755 --- a/src/rootserver/ob_ddl_service.cpp +++ b/src/rootserver/ob_ddl_service.cpp @@ -537,7 +537,6 @@ int ObDDLService::create_index_table( ObMySQLTransaction &sql_trans) { int ret = OB_SUCCESS; - const ObString *ddl_stmt_str = &arg.ddl_stmt_str_; uint64_t new_table_id = table_schema.get_table_id(); // You can specify the data table id to build an index uint64_t tenant_id = table_schema.get_tenant_id(); ObSchemaService *schema_service = NULL; @@ -575,9 +574,11 @@ int ObDDLService::create_index_table( } else {} // no more to do } if (OB_SUCC(ret)) { + // For create index operation, generate ddl_stmt_str when index enables, but + // for alter table add index operation, keep generating ddl_stmt_str same as 3.x while generating index schema. if (OB_FAIL(create_table_in_trans(table_schema, - ddl_stmt_str, &sql_trans, schema_guard, true/*need_check_tablet_cnt*/))) { - LOG_WARN("create_table_in_trans failed", KR(ret), K(ddl_stmt_str), K(table_schema)); + nullptr/* ddl_stmt_str */, &sql_trans, schema_guard, true/*need_check_tablet_cnt*/))) { + LOG_WARN("create_table_in_trans failed", KR(ret), K(arg), K(table_schema)); } } } @@ -9607,7 +9608,8 @@ int ObDDLService::update_global_index(ObAlterTableArg &arg, index_table_schema->get_table_id(), INDEX_STATUS_UNUSABLE, orig_table_schema.get_in_offline_ddl_white_list(), - trans))) { + trans, + nullptr /* ddl_stmt_str */))) { LOG_WARN("update_index_status failed", K(index_table_schema->get_data_table_id())); } } else { @@ -20367,6 +20369,7 @@ int ObDDLService::update_index_status(const obrpc::ObUpdateIndexStatusArg &arg) ObDDLSQLTransaction trans(schema_service_); ObDDLOperator ddl_operator(*schema_service_, *sql_proxy_); int64_t refreshed_schema_version = 0; + const ObString *ddl_stmt_str = arg.ddl_stmt_str_.empty() ? nullptr : &arg.ddl_stmt_str_; if (OB_FAIL(schema_guard.get_schema_version(tenant_id, refreshed_schema_version))) { LOG_WARN("failed to get tenant schema version", KR(ret), K(tenant_id)); } else if (is_available_index_status(new_status) && !table->is_unavailable_index()) { @@ -20376,7 +20379,7 @@ int ObDDLService::update_index_status(const obrpc::ObUpdateIndexStatusArg &arg) LOG_WARN("start transaction failed", KR(ret), K(tenant_id), K(refreshed_schema_version)); } else if (OB_FAIL(ddl_operator.update_index_status( tenant_id, table->get_data_table_id(), table_id, - new_status, arg.in_offline_ddl_white_list_, trans))) { + new_status, arg.in_offline_ddl_white_list_, trans, ddl_stmt_str))) { } if (OB_SUCC(ret) && arg.task_id_ != 0) { diff --git a/src/share/schema/ob_table_sql_service.cpp b/src/share/schema/ob_table_sql_service.cpp index 1553769c25..ffd3fca60b 100644 --- a/src/share/schema/ob_table_sql_service.cpp +++ b/src/share/schema/ob_table_sql_service.cpp @@ -2434,7 +2434,8 @@ int ObTableSqlService::update_index_status( const uint64_t index_table_id, const ObIndexStatus status, const int64_t new_schema_version, - common::ObISQLClient &sql_client) + common::ObISQLClient &sql_client, + const common::ObString *ddl_stmt_str) { int ret = OB_SUCCESS; ObSqlString sql; @@ -2495,11 +2496,12 @@ int ObTableSqlService::update_index_status( if (OB_SUCC(ret)) { ObSchemaOperation opt; opt.tenant_id_ = tenant_id; - opt.database_id_ = 0; - opt.tablegroup_id_ = 0; + opt.database_id_ = index_schema.get_database_id(); + opt.tablegroup_id_ = index_schema.get_tablegroup_id(); opt.table_id_ = index_table_id; opt.op_type_ = index_schema.is_global_index_table() ? OB_DDL_MODIFY_GLOBAL_INDEX_STATUS : OB_DDL_MODIFY_INDEX_STATUS; opt.schema_version_ = new_schema_version; + opt.ddl_stmt_str_ = ddl_stmt_str ? *ddl_stmt_str : ObString(); if (OB_FAIL(log_operation_wrapper(opt, sql_client))) { LOG_WARN("log operation failed", K(opt), K(ret)); } diff --git a/src/share/schema/ob_table_sql_service.h b/src/share/schema/ob_table_sql_service.h index ad5745b2d1..3c4722ca7a 100644 --- a/src/share/schema/ob_table_sql_service.h +++ b/src/share/schema/ob_table_sql_service.h @@ -131,7 +131,8 @@ public: const uint64_t index_table_id, const ObIndexStatus status, const int64_t new_schema_version, - common::ObISQLClient &sql_client); + common::ObISQLClient &sql_client, + const common::ObString *ddl_stmt_str); // TODO: merge these two API int sync_aux_schema_version_for_history(common::ObISQLClient &sql_client,