From e7d1b14fca043e610d4faf0e278480b52c29ac07 Mon Sep 17 00:00:00 2001 From: obdev Date: Tue, 8 Nov 2022 07:35:36 +0000 Subject: [PATCH] fix drop index task continually reports 4007 when cancelling it. --- src/rootserver/ddl_task/ob_drop_index_task.cpp | 2 +- src/rootserver/ddl_task/ob_index_build_task.cpp | 3 ++- src/rootserver/ob_ddl_service.cpp | 4 ++-- src/rootserver/ob_index_builder.cpp | 4 ++-- src/share/ob_rpc_struct.cpp | 6 ++++-- src/share/ob_rpc_struct.h | 3 +++ src/sql/engine/cmd/ob_ddl_executor_util.cpp | 7 ++++--- src/sql/engine/cmd/ob_ddl_executor_util.h | 3 ++- src/sql/engine/cmd/ob_table_executor.cpp | 5 ++++- 9 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/rootserver/ddl_task/ob_drop_index_task.cpp b/src/rootserver/ddl_task/ob_drop_index_task.cpp index 32c82eac8..3e30b88d9 100644 --- a/src/rootserver/ddl_task/ob_drop_index_task.cpp +++ b/src/rootserver/ddl_task/ob_drop_index_task.cpp @@ -210,7 +210,7 @@ int ObDropIndexTask::drop_index_impl() ret = OB_SCHEMA_ERROR; LOG_WARN("index schema is null", K(ret), K(target_object_id_)); } else if (OB_FAIL(index_schema->get_index_name(index_name))) { - LOG_WARN("get index name failed", K(ret)); + LOG_WARN("get index name failed", K(ret), K(index_schema->get_table_type()), KPC(index_schema)); } else if (OB_FAIL(schema_guard.get_database_schema(tenant_id_, index_schema->get_database_id(), database_schema))) { LOG_WARN("get database schema failed", K(ret), K(index_schema->get_database_id())); } else if (OB_FAIL(schema_guard.get_table_schema(tenant_id_, index_schema->get_data_table_id(), data_table_schema))) { diff --git a/src/rootserver/ddl_task/ob_index_build_task.cpp b/src/rootserver/ddl_task/ob_index_build_task.cpp index 9c7fe6342..f289983d2 100644 --- a/src/rootserver/ddl_task/ob_index_build_task.cpp +++ b/src/rootserver/ddl_task/ob_index_build_task.cpp @@ -1027,7 +1027,7 @@ int ObIndexBuildTask::clean_on_failed() LOG_WARN("generate drop index sql failed", K(ret)); } } else { - if (OB_FAIL(drop_index_sql.append_fmt("drop index \"%.*s\" on \"%.*s\"", index_name.length(), index_name.ptr(), + if (OB_FAIL(drop_index_sql.append_fmt("drop index %.*s on %.*s", index_name.length(), index_name.ptr(), data_table_schema->get_table_name_str().length(), data_table_schema->get_table_name_str().ptr()))) { LOG_WARN("generate drop index sql failed", K(ret)); } @@ -1048,6 +1048,7 @@ int ObIndexBuildTask::clean_on_failed() drop_index_arg.is_add_to_scheduler_ = false; drop_index_arg.is_hidden_ = index_schema->is_user_hidden_table(); drop_index_arg.is_in_recyclebin_ = index_schema->is_in_recyclebin(); + drop_index_arg.is_inner_ = true; if (OB_FAIL(root_service_->get_common_rpc_proxy().drop_index(drop_index_arg, drop_index_res))) { LOG_WARN("drop index failed", K(ret)); } diff --git a/src/rootserver/ob_ddl_service.cpp b/src/rootserver/ob_ddl_service.cpp index a7e2da982..ac8828025 100644 --- a/src/rootserver/ob_ddl_service.cpp +++ b/src/rootserver/ob_ddl_service.cpp @@ -4904,9 +4904,9 @@ int ObDDLService::alter_table_index(const obrpc::ObAlterTableArg &alter_table_ar ret = OB_ERR_CANT_DROP_FIELD_OR_KEY; LOG_WARN("index table schema should not be null", K(*drop_index_arg), K(ret)); LOG_USER_ERROR(OB_ERR_CANT_DROP_FIELD_OR_KEY, drop_index_arg->index_name_.length(), drop_index_arg->index_name_.ptr()); - } else if (index_table_schema->is_unavailable_index()) { + } else if (!drop_index_arg->is_inner_ && index_table_schema->is_unavailable_index()) { ret = OB_NOT_SUPPORTED; - LOG_WARN("not support to drop a building index", K(ret), KPC(index_table_schema)); + LOG_WARN("not support to drop a building index", K(ret), K(drop_index_arg->is_inner_), KPC(index_table_schema)); LOG_USER_ERROR(OB_NOT_SUPPORTED, "dropping a building index is"); } else if (drop_index_arg->is_add_to_scheduler_) { ObDDLRes ddl_res; diff --git a/src/rootserver/ob_index_builder.cpp b/src/rootserver/ob_index_builder.cpp index 75b02c909..fc0cd2d2b 100644 --- a/src/rootserver/ob_index_builder.cpp +++ b/src/rootserver/ob_index_builder.cpp @@ -164,9 +164,9 @@ int ObIndexBuilder::drop_index(const ObDropIndexArg &arg, obrpc::ObDropIndexRes ret = OB_ERR_CANT_DROP_FIELD_OR_KEY; LOG_WARN("index table schema should not be null", K(arg.index_name_), K(ret)); LOG_USER_ERROR(OB_ERR_CANT_DROP_FIELD_OR_KEY, arg.index_name_.length(), arg.index_name_.ptr()); - } else if (index_table_schema->is_unavailable_index()) { + } else if (!arg.is_inner_ && index_table_schema->is_unavailable_index()) { ret = OB_NOT_SUPPORTED; - LOG_WARN("not support to drop a building index", K(ret), KPC(index_table_schema)); + LOG_WARN("not support to drop a building index", K(ret), K(arg.is_inner_), KPC(index_table_schema)); LOG_USER_ERROR(OB_NOT_SUPPORTED, "dropping a building index is"); } else if (arg.is_add_to_scheduler_) { ObDDLOperator ddl_operator(ddl_service_.get_schema_service(), ddl_service_.get_sql_proxy()); diff --git a/src/share/ob_rpc_struct.cpp b/src/share/ob_rpc_struct.cpp index ed51a0d30..f5995621d 100644 --- a/src/share/ob_rpc_struct.cpp +++ b/src/share/ob_rpc_struct.cpp @@ -2176,7 +2176,8 @@ DEF_TO_STRING(ObDropIndexArg) { K_(index_table_id), K_(is_add_to_scheduler), K_(is_in_recyclebin), - K_(is_hidden)); + K_(is_hidden), + K_(is_inner)); J_OBJ_END(); return pos; } @@ -2189,7 +2190,8 @@ OB_SERIALIZE_MEMBER((ObDropIndexArg, ObIndexArg), index_table_id_, is_add_to_scheduler_, is_in_recyclebin_, - is_hidden_); + is_hidden_, + is_inner_); OB_SERIALIZE_MEMBER(ObDropIndexRes, tenant_id_, index_table_id_, schema_version_, task_id_); diff --git a/src/share/ob_rpc_struct.h b/src/share/ob_rpc_struct.h index 55086b1b5..616dfe791 100644 --- a/src/share/ob_rpc_struct.h +++ b/src/share/ob_rpc_struct.h @@ -1274,6 +1274,7 @@ public: is_add_to_scheduler_ = false; is_hidden_ = false; is_in_recyclebin_ = false; + is_inner_ = false; } virtual ~ObDropIndexArg() {} void reset() @@ -1283,12 +1284,14 @@ public: is_add_to_scheduler_ = false; is_hidden_ = false; is_in_recyclebin_ = false; + is_inner_ = false; } bool is_valid() const { return ObIndexArg::is_valid(); } uint64_t index_table_id_; bool is_add_to_scheduler_; bool is_hidden_; bool is_in_recyclebin_; + bool is_inner_; DECLARE_VIRTUAL_TO_STRING; }; diff --git a/src/sql/engine/cmd/ob_ddl_executor_util.cpp b/src/sql/engine/cmd/ob_ddl_executor_util.cpp index cbd294c0c..d96f566ec 100644 --- a/src/sql/engine/cmd/ob_ddl_executor_util.cpp +++ b/src/sql/engine/cmd/ob_ddl_executor_util.cpp @@ -48,7 +48,8 @@ int ObDDLExecutorUtil::wait_ddl_finish( const uint64_t tenant_id, const int64_t task_id, ObSQLSessionInfo &session, - obrpc::ObCommonRpcProxy *common_rpc_proxy) + obrpc::ObCommonRpcProxy *common_rpc_proxy, + const bool is_support_cancel) { int ret = OB_SUCCESS; const int64_t retry_interval = 100 * 1000; @@ -70,8 +71,8 @@ int ObDDLExecutorUtil::wait_ddl_finish( } break; } else if (OB_FAIL(handle_session_exception(session))) { - LOG_WARN("session exeception happened", K(ret)); - if (OB_FAIL(cancel_ddl_task(tenant_id, common_rpc_proxy))) { + LOG_WARN("session exeception happened", K(ret), K(is_support_cancel)); + if (is_support_cancel && OB_FAIL(cancel_ddl_task(tenant_id, common_rpc_proxy))) { LOG_WARN("cancel ddl task failed", K(ret)); } else { break; diff --git a/src/sql/engine/cmd/ob_ddl_executor_util.h b/src/sql/engine/cmd/ob_ddl_executor_util.h index 4878f59c4..fdf6661e1 100644 --- a/src/sql/engine/cmd/ob_ddl_executor_util.h +++ b/src/sql/engine/cmd/ob_ddl_executor_util.h @@ -55,7 +55,8 @@ public: const uint64_t tenant_id, const int64_t task_id, ObSQLSessionInfo &session, - obrpc::ObCommonRpcProxy *common_rpc_proxy); + obrpc::ObCommonRpcProxy *common_rpc_proxy, + const bool is_support_cancel = true); static int wait_ddl_retry_task_finish( const uint64_t tenant_id, const int64_t task_id, diff --git a/src/sql/engine/cmd/ob_table_executor.cpp b/src/sql/engine/cmd/ob_table_executor.cpp index c1302e2e7..130641edd 100644 --- a/src/sql/engine/cmd/ob_table_executor.cpp +++ b/src/sql/engine/cmd/ob_table_executor.cpp @@ -685,6 +685,8 @@ int ObAlterTableExecutor::alter_table_rpc_v2( const bool is_sync_ddl_user) { int ret = OB_SUCCESS; + // do not support cancel drop_index_task. + bool is_support_cancel = true; const ObSArray index_arg_list = alter_table_arg.index_arg_list_; ObSArray add_index_arg_list; ObSArray drop_index_args; @@ -714,6 +716,7 @@ int ObAlterTableExecutor::alter_table_rpc_v2( } else { ObDropIndexArg *drop_index_arg = static_cast(index_arg); drop_index_arg->is_add_to_scheduler_ = true; + is_support_cancel = false; } } else { // for rename/drop index action if (OB_FAIL(alter_table_arg.index_arg_list_.push_back(index_arg))) { @@ -744,7 +747,7 @@ int ObAlterTableExecutor::alter_table_rpc_v2( ObIArray &ddl_ress = res.ddl_res_array_; for (int64_t i = 0; OB_SUCC(ret) && i < ddl_ress.count(); ++i) { ObDDLRes &ddl_res = ddl_ress.at(i); - if (OB_FAIL(ObDDLExecutorUtil::wait_ddl_finish(ddl_res.tenant_id_, ddl_res.task_id_, *my_session, common_rpc_proxy))) { + if (OB_FAIL(ObDDLExecutorUtil::wait_ddl_finish(ddl_res.tenant_id_, ddl_res.task_id_, *my_session, common_rpc_proxy, is_support_cancel))) { LOG_WARN("wait drop index finish", K(ret)); } }