From 7674ece9706fc8e5591be54cf222640e4e9262ec Mon Sep 17 00:00:00 2001 From: qiuyang19960521 Date: Thu, 30 May 2024 17:37:15 +0800 Subject: [PATCH] fix: index directory error and nullPtr bool check_unsupported_index(dd::Table *table_def);# fix: index directory error and nullptr fix: index directory error and nullPtr fix: index directory error and nullPtr# fix: index directory error and nullPtr bool check_unsupported_index(dd::Table *table_def);# ix: index directory error and nullPtr# fix: index directory error and nullptr fix: partition index directory error fix: index directory error and nullpt# fix: partition index directory error fix: partition index directory error fix: index directory error and nullPtr# --- storage/tianchi/ha_tse.cc | 30 +++++++++++++++--- storage/tianchi/ha_tse.h | 2 ++ storage/tianchi/ha_tsepart.cc | 32 +++++++++++++++++++ storage/tianchi/ha_tsepart.h | 6 ++++ storage/tianchi/tse_ddl_rewriter_plugin.cc | 36 ---------------------- storage/tianchi/tse_util.cc | 34 ++++++++++++++++++++ storage/tianchi/tse_util.h | 2 ++ 7 files changed, 102 insertions(+), 40 deletions(-) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index 703d903..cfa9d90 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -106,6 +106,9 @@ #include "sql/dd/upgrade/server.h" // UPGRADE_FORCE #include "sql/abstract_query_plan.h" +#include "sql/dd/properties.h" +#include "sql/dd/types/partition.h" + #include "tse_stats.h" #include "tse_error.h" #include "tse_log.h" @@ -117,6 +120,7 @@ #include "sql/mysqld.h" #include "sql/plugin_table.h" #include "sql/dd/object_id.h" +#include "sql/dd/string_type.h" #include "sql/dd/cache/dictionary_client.h" #include "sql/dd/dd_schema.h" #include "sql/sql_table.h" @@ -148,8 +152,8 @@ static MYSQL_SYSVAR_BOOL(db_datafile_autoextend, tse_db_datafile_autoextend, PLU uint32_t tse_db_datafile_size = 32; static MYSQL_SYSVAR_UINT(db_datafile_size, tse_db_datafile_size, PLUGIN_VAR_RQCMDARG, "Size of the tablespace data file of the TSE database, in MB.", nullptr, nullptr, 32, 1, 8192 * 1024, 0); -/* 创库的表空间datafile自动扩展大小, 单位M, 默认8M, 最小1M, 最大8T */ -uint32_t tse_db_datafile_extend_size = 8; +/* 创库的表空间datafile自动扩展大小, 单位M, 默认128M, 最小1M, 最大8T */ +uint32_t tse_db_datafile_extend_size = 128; static MYSQL_SYSVAR_UINT(db_datafile_extend_size, tse_db_datafile_extend_size, PLUGIN_VAR_RQCMDARG, "Size of the TSE database tablespace data file automatically extended, in MB.", nullptr, nullptr, 8, 1, 8192 * 1024, 0); @@ -775,7 +779,10 @@ bool ha_tse::check_unsupported_operation(THD *thd, HA_CREATE_INFO *create_info) my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); return HA_ERR_UNSUPPORTED; } - + if (create_info != nullptr && create_info->index_file_name) { + my_error(ER_ILLEGAL_HA, MYF(0), table_share->table_name.str, HA_WRONG_CREATE_OPTION); + return true; + } return false; } @@ -2002,7 +2009,22 @@ static bool tse_notify_exclusive_mdl(THD *thd, const MDL_key *mdl_key, static bool tse_notify_alter_table(THD *thd, const MDL_key *mdl_key, ha_notification_type notification_type) { - return tse_notify_exclusive_mdl(thd, mdl_key, notification_type, nullptr); + vector ticket_list; + if (IS_METADATA_NORMALIZATION() && notification_type == HA_NOTIFY_PRE_EVENT) { + int pre_lock_ret = tse_lock_table_pre(thd, ticket_list); + if (pre_lock_ret != 0) { + tse_lock_table_post(thd, ticket_list); + my_printf_error(ER_LOCK_WAIT_TIMEOUT, "[tse_notify_alter_table]: LOCK TABLE FAILED", MYF(0)); + return true; + } + } + + bool ret = tse_notify_exclusive_mdl(thd, mdl_key, notification_type, nullptr); + + if (IS_METADATA_NORMALIZATION() && notification_type == HA_NOTIFY_PRE_EVENT) { + tse_lock_table_post(thd, ticket_list); + } + return ret; } static const unsigned int MAX_SAVEPOINT_NAME_LEN = 64; diff --git a/storage/tianchi/ha_tse.h b/storage/tianchi/ha_tse.h index 9cdeedb..33ec26a 100644 --- a/storage/tianchi/ha_tse.h +++ b/storage/tianchi/ha_tse.h @@ -36,6 +36,7 @@ #include "sql/abstract_query_plan.h" #include "sql/dd/types/schema.h" #include "sql/dd/types/object_table_definition.h" +#include "sql/dd/string_type.h" #pragma GCC visibility push(default) @@ -148,6 +149,7 @@ again. */ #define IS_PRIMARY_ROLE() (tse_get_cluster_role() == (int32_t)dis_cluster_role::PRIMARY) #define IS_STANDBY_ROLE() (tse_get_cluster_role() == (int32_t)dis_cluster_role::STANDBY) +static const dd::String_type index_file_name_val_key("index_file_name"); static const uint ROW_ID_LENGTH = sizeof(uint64_t); static const uint TSE_START_TIMEOUT = 120; // seconds extern const char *tse_hton_name; diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index dc0ad9c..f906393 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -53,6 +53,9 @@ #include "typelib.h" #include "tse_cbo.h" #include "sql/sql_alter.h" +#include "sql/dd/properties.h" +#include "sql/dd/types/partition.h" +#include "sql/dd/string_type.h" #define INVALID_PART_ID (uint32)0xFFFFFFFF; @@ -1130,3 +1133,32 @@ uint32 ha_tsepart::calculate_key_hash_value(Field **field_array) return (Partition_helper::ph_calculate_key_hash_value(field_array)); } +bool ha_tsepart::check_unsupported_index(dd::Table *table_def) { + // 遍历分区,存在index_file_name_val,创建表失败 + for (const auto dd_part : *table_def->leaf_partitions()) { + dd::String_type index_file_name; + if(dd_part == nullptr){ + continue; + } + const dd::Properties &options = dd_part->options(); + if (options.exists(index_file_name_val_key)) { + options.get(index_file_name_val_key, &index_file_name); + } + if (!index_file_name.empty()) { + my_error(ER_ILLEGAL_HA, MYF(0), table_share != nullptr ? table_share->table_name.str : " "); + return true; + } + } + return false; +} + +EXTER_ATTACK int ha_tsepart::create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, + dd::Table *table_def) { + THD *thd = ha_thd(); + if(table_def != nullptr && check_unsupported_index(table_def)){ + tse_log_system("Unsupported operation. sql = %s", thd->query().str); + return HA_ERR_WRONG_COMMAND; + } + return ha_tse::create(name, form, create_info, table_def); +} + diff --git a/storage/tianchi/ha_tsepart.h b/storage/tianchi/ha_tsepart.h index 0cb0759..ed53454 100644 --- a/storage/tianchi/ha_tsepart.h +++ b/storage/tianchi/ha_tsepart.h @@ -24,6 +24,7 @@ #include "tse_srv.h" #include "tse_util.h" #include "sql/partitioning/partition_handler.h" +#include "sql/dd/string_type.h" class Tsepart_share : public Partition_share { public: @@ -64,6 +65,8 @@ class ha_tsepart : public ha_tse, */ int truncate_partition_low(dd::Table *dd_table) override; + bool check_unsupported_index(dd::Table *table_def); + /** Write a row in specific partition. Stores a row in an TSE database, to the table specified in this handle. @@ -368,6 +371,9 @@ class ha_tsepart : public ha_tse, int optimize(THD *thd, HA_CHECK_OPT *check_opt) override; + int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, + dd::Table *table_def) override; + /* Get partition row type @param[in] partition_table partition table @param[in] part_id Id of partition for which row type to be retrieved diff --git a/storage/tianchi/tse_ddl_rewriter_plugin.cc b/storage/tianchi/tse_ddl_rewriter_plugin.cc index 4aa9269..d5ee53a 100644 --- a/storage/tianchi/tse_ddl_rewriter_plugin.cc +++ b/storage/tianchi/tse_ddl_rewriter_plugin.cc @@ -706,9 +706,6 @@ static int tse_read_only_ddl(string &, MYSQL_THD thd, bool &need_forward) { return 0; } -int tse_lock_table_pre(THD* thd, vector& ticket_list); -void tse_lock_table_post(THD* thd, vector& ticket_list); - static int tse_lock_tables_ddl(string &, MYSQL_THD thd, bool &) { TABLE_LIST *tables = thd->lex->query_tables; int ret = 0; @@ -952,39 +949,6 @@ static int plugin_init(MYSQL_PLUGIN) { #define key_memory_tse_ddl_rewriter PSI_NOT_INSTRUMENTED #endif /* HAVE_PSI_INTERFACE */ -static inline bool is_temporary_table_being_opened(const TABLE_LIST *table) { - return table->open_type == OT_TEMPORARY_ONLY || - (table->open_type == OT_TEMPORARY_OR_BASE && - is_temporary_table(table)); -} - -int tse_lock_table_pre(THD* thd, vector& ticket_list) { - TABLE_LIST *tables_start = thd->lex->query_tables; - TABLE_LIST *tables_end = thd->lex->first_not_own_table(); - TABLE_LIST *table; - for (table = tables_start; table && table != tables_end; - table = table->next_global) { - if (is_temporary_table_being_opened(table)) { - continue; - } - MDL_request req; - MDL_REQUEST_INIT(&req, MDL_key::TABLE, table->db, table->table_name, - MDL_SHARED_NO_READ_WRITE, MDL_EXPLICIT); - if (thd->mdl_context.acquire_lock(&req, 1)) { - return 1; - } - ticket_list.push_back(req.ticket); - } - return 0; -} - -void tse_lock_table_post(THD* thd, vector& ticket_list) { - for (auto it = ticket_list.begin(); it != ticket_list.end(); ++it) { - thd->mdl_context.release_lock(*it); - } - ticket_list.clear(); -} - static void tse_ddl_rewrite_handle_error(MYSQL_THD thd, int ret, tse_ddl_broadcast_request &broadcast_req, uint8_t sql_cmd) { if (ret == TSE_DDL_VERSION_NOT_MATCH) { broadcast_req.err_code = ER_DISALLOWED_OPERATION; diff --git a/storage/tianchi/tse_util.cc b/storage/tianchi/tse_util.cc index 4d8619d..835c38b 100644 --- a/storage/tianchi/tse_util.cc +++ b/storage/tianchi/tse_util.cc @@ -21,6 +21,7 @@ #include "tse_proxy_util.h" #include "sql/sql_class.h" +#include "sql/sql_lex.h" #include "sql/tztime.h" #include "m_ctype.h" #include "my_sys.h" @@ -723,4 +724,37 @@ int tse_check_unlock_instance(MYSQL_THD thd) { tse_unlock_instance(&is_mysqld_starting, &tch); tse_log_system("[TSE_UNLOCK_INSTANCE]: SUCCESS. tse_inst:%u, conn_id:%u", tch.inst_id, tch.thd_id); return 0; +} + +static inline bool is_temporary_table_being_opened(const TABLE_LIST *table) { + return table->open_type == OT_TEMPORARY_ONLY || + (table->open_type == OT_TEMPORARY_OR_BASE && + is_temporary_table(table)); +} + +int tse_lock_table_pre(MYSQL_THD thd, vector& ticket_list) { + TABLE_LIST *tables_start = thd->lex->query_tables; + TABLE_LIST *tables_end = thd->lex->first_not_own_table(); + TABLE_LIST *table; + for (table = tables_start; table && table != tables_end; + table = table->next_global) { + if (is_temporary_table_being_opened(table)) { + continue; + } + MDL_request req; + MDL_REQUEST_INIT(&req, MDL_key::TABLE, table->db, table->table_name, + MDL_SHARED_NO_READ_WRITE, MDL_EXPLICIT); + if (thd->mdl_context.acquire_lock(&req, 1)) { + return 1; + } + ticket_list.push_back(req.ticket); + } + return 0; +} + +void tse_lock_table_post(MYSQL_THD thd, vector& ticket_list) { + for (auto it = ticket_list.begin(); it != ticket_list.end(); ++it) { + thd->mdl_context.release_lock(*it); + } + ticket_list.clear(); } \ No newline at end of file diff --git a/storage/tianchi/tse_util.h b/storage/tianchi/tse_util.h index 3cad7f2..305409f 100644 --- a/storage/tianchi/tse_util.h +++ b/storage/tianchi/tse_util.h @@ -66,6 +66,8 @@ void tse_print_cantian_err_msg(const ddl_ctrl_t *ddl_ctrl, ct_errno_t ret); int tse_check_lock_instance(MYSQL_THD thd, bool &need_forward); int tse_check_unlock_instance(MYSQL_THD thd); int ctc_record_sql(MYSQL_THD thd, bool need_select_db); +int tse_lock_table_pre(MYSQL_THD thd, vector& ticket_list); +void tse_lock_table_post(MYSQL_THD thd, vector& ticket_list); #pragma GCC visibility push(default) -- Gitee