From bb20204a7cd9ea79b6f4b6e020541a0b159e6322 Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Tue, 14 May 2024 11:39:56 +0800 Subject: [PATCH 01/15] update code --- storage/tianchi/ha_tse.cc | 18 ++++++++++++++++++ storage/tianchi/tse_cbo.cc | 25 +++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index 6819c62..4ae3b16 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -311,6 +311,12 @@ handlerton *get_tse_hton() { return tse_hton; } * reference: populate_table */ static inline bool is_create_table_check(MYSQL_THD thd) { + if (thd == nullptr) { + return false; + } + if (thd->lex == nullptr) { + return false; + } if (thd->lex->sql_command == SQLCOM_CREATE_TABLE && thd->lex->is_exec_started()) { return true; @@ -319,8 +325,20 @@ static inline bool is_create_table_check(MYSQL_THD thd) { } bool user_var_set(MYSQL_THD thd, string target_str) { + if (thd == nullptr) { + return false; + } + if (target_str[0] == '\0') { + return false; + } user_var_entry *var_entry; var_entry = find_or_nullptr(thd->user_vars, target_str); + if (var_entry == nullptr) { + return false; + } + if (var_entry->ptr() == nullptr) { + return false; + } if (var_entry != nullptr && var_entry->ptr() != nullptr) { tse_log_debug("thd (%d) has user variable %s", thd->thread_id(), target_str.data()); return true; diff --git a/storage/tianchi/tse_cbo.cc b/storage/tianchi/tse_cbo.cc index f1d1239..31794a8 100644 --- a/storage/tianchi/tse_cbo.cc +++ b/storage/tianchi/tse_cbo.cc @@ -137,7 +137,10 @@ static double calc_frequency_hist_equal_density(tse_cbo_stats_column_t *col_stat static double calc_balance_hist_equal_density(tse_cbo_stats_column_t *col_stat, cache_variant_t *val, enum_field_types field_type) -{ +{ + if (col_stat->hist_count == 0) { + return col_stat->density; + } uint32 popular_count = 0; en_tse_compare_type cmp_result; tse_cbo_column_hist_t *hist_infos = col_stat->column_hist; @@ -240,9 +243,14 @@ double percent_in_bucket(tse_cbo_stats_column_t *col_stat, uint32 high, { double percent = 0.0D; tse_cbo_column_hist_t *hist_infos = col_stat->column_hist; + if (col_stat->hist_count == 0 || high >= col_stat->hist_count) { + return DEFAULT_RANGE_DENSITY; + } cache_variant_t *ep_high = high >= col_stat->hist_count ? &col_stat->high_value : &hist_infos[high].ep_value; cache_variant_t *ep_low = high < 1 ? &col_stat->low_value : &hist_infos[high - 1].ep_value; - + if (ep_high == nullptr || ep_low == nullptr) { + return DEFAULT_RANGE_DENSITY; + } switch(field_type) { case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: @@ -276,7 +284,9 @@ static int calc_hist_range_boundary(field_stats_val stats_val, enum_field_types uint32 i, lo_pos, hi_pos; uint32 hist_count = col_stat->hist_count; tse_cbo_column_hist_t *hist_infos = col_stat->column_hist; - + if (hist_count == 0) { + return 0; + } lo_pos = hi_pos = hist_count - 1; for (i = 0; i < hist_count; i++) { @@ -354,7 +364,14 @@ static double calc_hist_between_density(tse_cbo_stats_table_t cbo_stats, double calc_density_by_cond(tse_cbo_stats_table_t cbo_stats, KEY_PART_INFO cur_index_part, tse_range_key *key, uint32_t key_offset) -{ +{ + if (key == nullptr || key->min_key == nullptr || key->max_key == nullptr) { + return DEFAULT_RANGE_DENSITY; + } + + if (cur_index_part.field == nullptr) { + return DEFAULT_RANGE_DENSITY; + } double density = DEFAULT_RANGE_DENSITY; uint32 col_id = cur_index_part.field->field_index(); tse_key *min_key = key->min_key; -- Gitee From 53804fc26ab3a1c775ba634bc8e5f52c949888b7 Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Tue, 14 May 2024 14:19:44 +0800 Subject: [PATCH 02/15] update code --- storage/tianchi/ha_tse.cc | 18 ------------------ storage/tianchi/tse_cbo.cc | 25 ++++--------------------- 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index 4ae3b16..6819c62 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -311,12 +311,6 @@ handlerton *get_tse_hton() { return tse_hton; } * reference: populate_table */ static inline bool is_create_table_check(MYSQL_THD thd) { - if (thd == nullptr) { - return false; - } - if (thd->lex == nullptr) { - return false; - } if (thd->lex->sql_command == SQLCOM_CREATE_TABLE && thd->lex->is_exec_started()) { return true; @@ -325,20 +319,8 @@ static inline bool is_create_table_check(MYSQL_THD thd) { } bool user_var_set(MYSQL_THD thd, string target_str) { - if (thd == nullptr) { - return false; - } - if (target_str[0] == '\0') { - return false; - } user_var_entry *var_entry; var_entry = find_or_nullptr(thd->user_vars, target_str); - if (var_entry == nullptr) { - return false; - } - if (var_entry->ptr() == nullptr) { - return false; - } if (var_entry != nullptr && var_entry->ptr() != nullptr) { tse_log_debug("thd (%d) has user variable %s", thd->thread_id(), target_str.data()); return true; diff --git a/storage/tianchi/tse_cbo.cc b/storage/tianchi/tse_cbo.cc index 31794a8..f1d1239 100644 --- a/storage/tianchi/tse_cbo.cc +++ b/storage/tianchi/tse_cbo.cc @@ -137,10 +137,7 @@ static double calc_frequency_hist_equal_density(tse_cbo_stats_column_t *col_stat static double calc_balance_hist_equal_density(tse_cbo_stats_column_t *col_stat, cache_variant_t *val, enum_field_types field_type) -{ - if (col_stat->hist_count == 0) { - return col_stat->density; - } +{ uint32 popular_count = 0; en_tse_compare_type cmp_result; tse_cbo_column_hist_t *hist_infos = col_stat->column_hist; @@ -243,14 +240,9 @@ double percent_in_bucket(tse_cbo_stats_column_t *col_stat, uint32 high, { double percent = 0.0D; tse_cbo_column_hist_t *hist_infos = col_stat->column_hist; - if (col_stat->hist_count == 0 || high >= col_stat->hist_count) { - return DEFAULT_RANGE_DENSITY; - } cache_variant_t *ep_high = high >= col_stat->hist_count ? &col_stat->high_value : &hist_infos[high].ep_value; cache_variant_t *ep_low = high < 1 ? &col_stat->low_value : &hist_infos[high - 1].ep_value; - if (ep_high == nullptr || ep_low == nullptr) { - return DEFAULT_RANGE_DENSITY; - } + switch(field_type) { case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: @@ -284,9 +276,7 @@ static int calc_hist_range_boundary(field_stats_val stats_val, enum_field_types uint32 i, lo_pos, hi_pos; uint32 hist_count = col_stat->hist_count; tse_cbo_column_hist_t *hist_infos = col_stat->column_hist; - if (hist_count == 0) { - return 0; - } + lo_pos = hi_pos = hist_count - 1; for (i = 0; i < hist_count; i++) { @@ -364,14 +354,7 @@ static double calc_hist_between_density(tse_cbo_stats_table_t cbo_stats, double calc_density_by_cond(tse_cbo_stats_table_t cbo_stats, KEY_PART_INFO cur_index_part, tse_range_key *key, uint32_t key_offset) -{ - if (key == nullptr || key->min_key == nullptr || key->max_key == nullptr) { - return DEFAULT_RANGE_DENSITY; - } - - if (cur_index_part.field == nullptr) { - return DEFAULT_RANGE_DENSITY; - } +{ double density = DEFAULT_RANGE_DENSITY; uint32 col_id = cur_index_part.field->field_index(); tse_key *min_key = key->min_key; -- Gitee From 47a3b78d85fb3983f44f4d73306e7dfff8ad9bcc Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Tue, 14 May 2024 14:33:20 +0800 Subject: [PATCH 03/15] update code --- storage/tianchi/datatype_cnvrtr.cc | 5 +++++ storage/tianchi/ha_tse.cc | 11 ++++++++++- storage/tianchi/ha_tse_ddl.h | 4 ++++ storage/tianchi/ha_tsepart.cc | 23 ++++++++++++++++++++++- storage/tianchi/mysql_daac_plugin.cc | 4 ++++ 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/storage/tianchi/datatype_cnvrtr.cc b/storage/tianchi/datatype_cnvrtr.cc index f1ec7a5..029cdf2 100644 --- a/storage/tianchi/datatype_cnvrtr.cc +++ b/storage/tianchi/datatype_cnvrtr.cc @@ -1586,6 +1586,11 @@ void copy_column_data_to_mysql(field_info_t *field_info, const field_cnvrt_aux_t if (is_index_only) { uint32_t blob_len = field_info->field_len; char *blob_buf = (char *)my_malloc(PSI_NOT_INSTRUMENTED, blob_len * sizeof(char), MYF(MY_WME)); + if (blob_buf == nullptr) { + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); + my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); + return; + } memcpy(blob_buf, field_info->cantian_cur_field, blob_len); memcpy(field_info->mysql_cur_field, &blob_buf, sizeof(char *)); bitmap_set_bit(field_info->field->table->read_set, field_info->field->field_index()); diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index 6819c62..2c35560 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -5230,13 +5230,22 @@ int ha_tse::initialize_cbo_stats() m_share->cbo_stats->tse_cbo_stats_table.columns = (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); THD* thd = ha_thd(); + if (m_share->cbo_stats->tse_cbo_stats_table.columns == nullptr) { + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); + my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); + return; + } if (user_var_set(thd, "ctc_show_alloc_cbo_stats_mem")) { tse_log_system("[alloc memory]normal table : %s alloc size :%lu", table->alias, calculate_size_of_cbo_stats(table)); } m_share->cbo_stats->tse_cbo_stats_table.ndv_keys = (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); - + if (m_share->cbo_stats->tse_cbo_stats_table.ndv_keys == nullptr) { + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); + my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); + return; + } m_share->cbo_stats->msg_len = table->s->fields * sizeof(tse_cbo_stats_column_t); m_share->cbo_stats->key_len = table->s->keys * sizeof(uint32_t); return CT_SUCCESS; diff --git a/storage/tianchi/ha_tse_ddl.h b/storage/tianchi/ha_tse_ddl.h index 04f6680..14dd20c 100644 --- a/storage/tianchi/ha_tse_ddl.h +++ b/storage/tianchi/ha_tse_ddl.h @@ -189,6 +189,10 @@ class tse_ddl_stack_mem { buf_obj = stack_obj; } else { buf_obj = my_malloc(PSI_NOT_INSTRUMENTED, mem_size, MYF(MY_WME)); + if (buf_obj == nullptr) { + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); + my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); + } tse_ddl_req_msg_mem_use_heap_cnt++; } tse_ddl_req_msg_mem_max_size = diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index 0a93cb3..cffce30 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -75,7 +75,11 @@ static uint32_t get_ct_part_no(uint num_subparts, uint part_id) { static void get_used_partitions(partition_info *part_info, uint32_t **part_ids, uint32_t *used_parts) { *used_parts = part_info->num_partitions_used(); *part_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); - + if (part_ids == nullptr) { + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); + my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); + return; + } uint32_t part_id = part_info->get_first_used_partition(); **part_ids = part_id; for (uint32_t i = 1; i < *used_parts; i++) { @@ -257,6 +261,11 @@ void ha_tsepart::start_bulk_insert(ha_rows rows) { // m_max_batch_num is fixed after open table, if table structrue is changed, it should be closed and reopened m_bulk_insert_parts = (ctc_part_t *)my_malloc(PSI_NOT_INSTRUMENTED, m_max_batch_num * sizeof(ctc_part_t), MYF(MY_WME)); + if (m_bulk_insert_parts == nullptr) { + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); + my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); + return; + } } } } @@ -979,12 +988,24 @@ int ha_tsepart::initialize_cbo_stats() { m_part_share->cbo_stats->tse_cbo_stats_part_table = (tse_cbo_stats_table_t*)my_malloc(PSI_NOT_INSTRUMENTED, part_num * sizeof(tse_cbo_stats_table_t), MYF(MY_WME)); + if (m_part_share->cbo_stats->tse_cbo_stats_part_table == nullptr) { + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); + return ERR_ALLOC_MEMORY; + } for (uint i = 0; i < part_num; i++) { m_part_share->cbo_stats->tse_cbo_stats_part_table[i].columns = (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); + if (m_part_share->cbo_stats->tse_cbo_stats_part_table[i].columns == nullptr) { + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); + return ERR_ALLOC_MEMORY; + } m_part_share->cbo_stats->tse_cbo_stats_part_table[i].ndv_keys = (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); + if (m_part_share->cbo_stats->tse_cbo_stats_part_table[i].ndv_keys == nullptr) { + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); + return ERR_ALLOC_MEMORY; + } } m_part_share->cbo_stats->msg_len = table->s->fields * sizeof(tse_cbo_stats_column_t); m_part_share->cbo_stats->key_len = table->s->keys * sizeof(uint32_t); diff --git a/storage/tianchi/mysql_daac_plugin.cc b/storage/tianchi/mysql_daac_plugin.cc index 91c6b10..59262c6 100644 --- a/storage/tianchi/mysql_daac_plugin.cc +++ b/storage/tianchi/mysql_daac_plugin.cc @@ -119,6 +119,10 @@ int daemon_daac_plugin_init() { daac_context = (struct mysql_daac_context *)my_malloc( PSI_NOT_INSTRUMENTED, sizeof(struct mysql_daac_context), MYF(0)); + if (daac_context == nullptr) { + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); + return ERR_ALLOC_MEMORY; + } my_thread_attr_t startup_attr; /* Thread attributes */ my_thread_attr_init(&startup_attr); -- Gitee From bdfacc09ee3faed222eece6ea9608ac4b1cef060 Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Tue, 14 May 2024 14:53:28 +0800 Subject: [PATCH 04/15] update code --- storage/tianchi/ha_tse.cc | 14 +++++++------- storage/tianchi/ha_tse_ddl.h | 4 ---- storage/tianchi/ha_tsepart.cc | 8 ++++---- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index 2c35560..d963cab 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -2283,7 +2283,7 @@ int ha_tse::initialize() { // size is limited by struct defined in shared mem m_prefetch_buf = (uchar *)my_malloc(PSI_NOT_INSTRUMENTED, MAX_RECORD_SIZE, MYF(MY_WME)); if (m_prefetch_buf == nullptr) { - tse_log_error("alloc mem failed, m_prefetch_buf size(%u)", MAX_RECORD_SIZE); + tse_log_error("alloc mem failed, m_prefetch_buf size(%u)",); return HA_ERR_OUT_OF_MEM; } @@ -5231,9 +5231,9 @@ int ha_tse::initialize_cbo_stats() (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); THD* thd = ha_thd(); if (m_share->cbo_stats->tse_cbo_stats_table.columns == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); - my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); - return; + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed"); + my_error(ER_OUT_OF_RESOURCES, MYF(0)); + return ERR_ALLOC_MEMORY; } if (user_var_set(thd, "ctc_show_alloc_cbo_stats_mem")) { tse_log_system("[alloc memory]normal table : %s alloc size :%lu", table->alias, calculate_size_of_cbo_stats(table)); @@ -5242,9 +5242,9 @@ int ha_tse::initialize_cbo_stats() m_share->cbo_stats->tse_cbo_stats_table.ndv_keys = (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); if (m_share->cbo_stats->tse_cbo_stats_table.ndv_keys == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); - my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); - return; + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed"); + my_error(ER_OUT_OF_RESOURCES, MYF(0)); + return ERR_ALLOC_MEMORY; } m_share->cbo_stats->msg_len = table->s->fields * sizeof(tse_cbo_stats_column_t); m_share->cbo_stats->key_len = table->s->keys * sizeof(uint32_t); diff --git a/storage/tianchi/ha_tse_ddl.h b/storage/tianchi/ha_tse_ddl.h index 14dd20c..04f6680 100644 --- a/storage/tianchi/ha_tse_ddl.h +++ b/storage/tianchi/ha_tse_ddl.h @@ -189,10 +189,6 @@ class tse_ddl_stack_mem { buf_obj = stack_obj; } else { buf_obj = my_malloc(PSI_NOT_INSTRUMENTED, mem_size, MYF(MY_WME)); - if (buf_obj == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); - my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); - } tse_ddl_req_msg_mem_use_heap_cnt++; } tse_ddl_req_msg_mem_max_size = diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index cffce30..72e8d02 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -76,8 +76,8 @@ static void get_used_partitions(partition_info *part_info, uint32_t **part_ids, *used_parts = part_info->num_partitions_used(); *part_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); if (part_ids == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); - my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed"); + my_error(ER_OUT_OF_RESOURCES, MYF(0)); return; } uint32_t part_id = part_info->get_first_used_partition(); @@ -262,8 +262,8 @@ void ha_tsepart::start_bulk_insert(ha_rows rows) { m_bulk_insert_parts = (ctc_part_t *)my_malloc(PSI_NOT_INSTRUMENTED, m_max_batch_num * sizeof(ctc_part_t), MYF(MY_WME)); if (m_bulk_insert_parts == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); - my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed"); + my_error(ER_OUT_OF_RESOURCES, MYF(0)); return; } } -- Gitee From 3f3322322fc10208c05f073a75c0143af39d5c5f Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Tue, 14 May 2024 15:04:58 +0800 Subject: [PATCH 05/15] update code --- storage/tianchi/ha_tse.cc | 6 +++--- storage/tianchi/ha_tsepart.cc | 4 ++-- storage/tianchi/mysql_daac_plugin.cc | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index d963cab..efeaa83 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -2283,7 +2283,7 @@ int ha_tse::initialize() { // size is limited by struct defined in shared mem m_prefetch_buf = (uchar *)my_malloc(PSI_NOT_INSTRUMENTED, MAX_RECORD_SIZE, MYF(MY_WME)); if (m_prefetch_buf == nullptr) { - tse_log_error("alloc mem failed, m_prefetch_buf size(%u)",); + tse_log_error("alloc mem failed, m_prefetch_buf size(%u)",0); return HA_ERR_OUT_OF_MEM; } @@ -5231,7 +5231,7 @@ int ha_tse::initialize_cbo_stats() (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); THD* thd = ha_thd(); if (m_share->cbo_stats->tse_cbo_stats_table.columns == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed"); + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed",0); my_error(ER_OUT_OF_RESOURCES, MYF(0)); return ERR_ALLOC_MEMORY; } @@ -5242,7 +5242,7 @@ int ha_tse::initialize_cbo_stats() m_share->cbo_stats->tse_cbo_stats_table.ndv_keys = (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); if (m_share->cbo_stats->tse_cbo_stats_table.ndv_keys == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed"); + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed",0); my_error(ER_OUT_OF_RESOURCES, MYF(0)); return ERR_ALLOC_MEMORY; } diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index 72e8d02..58bf299 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -76,7 +76,7 @@ static void get_used_partitions(partition_info *part_info, uint32_t **part_ids, *used_parts = part_info->num_partitions_used(); *part_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); if (part_ids == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed"); + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed",0); my_error(ER_OUT_OF_RESOURCES, MYF(0)); return; } @@ -262,7 +262,7 @@ void ha_tsepart::start_bulk_insert(ha_rows rows) { m_bulk_insert_parts = (ctc_part_t *)my_malloc(PSI_NOT_INSTRUMENTED, m_max_batch_num * sizeof(ctc_part_t), MYF(MY_WME)); if (m_bulk_insert_parts == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed"); + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed",0); my_error(ER_OUT_OF_RESOURCES, MYF(0)); return; } diff --git a/storage/tianchi/mysql_daac_plugin.cc b/storage/tianchi/mysql_daac_plugin.cc index 59262c6..f48fca2 100644 --- a/storage/tianchi/mysql_daac_plugin.cc +++ b/storage/tianchi/mysql_daac_plugin.cc @@ -130,7 +130,7 @@ int daemon_daac_plugin_init() { /* now create the startup thread */ if (my_thread_create(&daac_context->daac_startup_thread, &startup_attr, mysql_daac_startup_thread, (void *)daac_context) != 0) { - tse_log_error("Could not create daac startup thread!"); + tse_log_error("Could not create daac startup thread!",0); return -1; } return 0; -- Gitee From b4c1ef54b773fcbdc060b716fca24a5cc1484581 Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Tue, 14 May 2024 15:46:43 +0800 Subject: [PATCH 06/15] update code --- storage/tianchi/ha_tse.cc | 4 ++-- storage/tianchi/ha_tsepart.cc | 8 ++++---- storage/tianchi/mysql_daac_plugin.cc | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index efeaa83..17656b6 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -5231,7 +5231,7 @@ int ha_tse::initialize_cbo_stats() (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); THD* thd = ha_thd(); if (m_share->cbo_stats->tse_cbo_stats_table.columns == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed",0); + tse_log_error("[alloc memory]Failed",0); my_error(ER_OUT_OF_RESOURCES, MYF(0)); return ERR_ALLOC_MEMORY; } @@ -5242,7 +5242,7 @@ int ha_tse::initialize_cbo_stats() m_share->cbo_stats->tse_cbo_stats_table.ndv_keys = (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); if (m_share->cbo_stats->tse_cbo_stats_table.ndv_keys == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed",0); + tse_log_error("[alloc memory]Failed",0); my_error(ER_OUT_OF_RESOURCES, MYF(0)); return ERR_ALLOC_MEMORY; } diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index 58bf299..2ca151a 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -979,7 +979,7 @@ int ha_tsepart::initialize_cbo_stats() { m_part_share->cbo_stats = (tianchi_cbo_stats_t*)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(tianchi_cbo_stats_t), MYF(MY_WME)); if (m_part_share->cbo_stats == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", 0); return ERR_ALLOC_MEMORY; } *m_part_share->cbo_stats = {0, 0, 0, 0, 0, 0, 0, nullptr, nullptr, nullptr}; @@ -989,7 +989,7 @@ int ha_tsepart::initialize_cbo_stats() { m_part_share->cbo_stats->tse_cbo_stats_part_table = (tse_cbo_stats_table_t*)my_malloc(PSI_NOT_INSTRUMENTED, part_num * sizeof(tse_cbo_stats_table_t), MYF(MY_WME)); if (m_part_share->cbo_stats->tse_cbo_stats_part_table == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", 0); return ERR_ALLOC_MEMORY; } @@ -997,13 +997,13 @@ int ha_tsepart::initialize_cbo_stats() { m_part_share->cbo_stats->tse_cbo_stats_part_table[i].columns = (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); if (m_part_share->cbo_stats->tse_cbo_stats_part_table[i].columns == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", 0); return ERR_ALLOC_MEMORY; } m_part_share->cbo_stats->tse_cbo_stats_part_table[i].ndv_keys = (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); if (m_part_share->cbo_stats->tse_cbo_stats_part_table[i].ndv_keys == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", 0); return ERR_ALLOC_MEMORY; } } diff --git a/storage/tianchi/mysql_daac_plugin.cc b/storage/tianchi/mysql_daac_plugin.cc index f48fca2..0359cb2 100644 --- a/storage/tianchi/mysql_daac_plugin.cc +++ b/storage/tianchi/mysql_daac_plugin.cc @@ -120,7 +120,7 @@ int daemon_daac_plugin_init() { PSI_NOT_INSTRUMENTED, sizeof(struct mysql_daac_context), MYF(0)); if (daac_context == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", 0); return ERR_ALLOC_MEMORY; } -- Gitee From 1183c33fc3f52b4964c7e4d3cdf3bde22019e6dd Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Tue, 14 May 2024 16:03:30 +0800 Subject: [PATCH 07/15] update code --- storage/tianchi/ha_tse.cc | 8 +++----- storage/tianchi/ha_tsepart.cc | 18 ++++++++---------- storage/tianchi/mysql_daac_plugin.cc | 2 +- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index 17656b6..dc632f9 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -2283,7 +2283,7 @@ int ha_tse::initialize() { // size is limited by struct defined in shared mem m_prefetch_buf = (uchar *)my_malloc(PSI_NOT_INSTRUMENTED, MAX_RECORD_SIZE, MYF(MY_WME)); if (m_prefetch_buf == nullptr) { - tse_log_error("alloc mem failed, m_prefetch_buf size(%u)",0); + tse_log_error("alloc mem failed, m_prefetch_buf size(%u)",MAX_RECORD_SIZE); return HA_ERR_OUT_OF_MEM; } @@ -5231,8 +5231,7 @@ int ha_tse::initialize_cbo_stats() (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); THD* thd = ha_thd(); if (m_share->cbo_stats->tse_cbo_stats_table.columns == nullptr) { - tse_log_error("[alloc memory]Failed",0); - my_error(ER_OUT_OF_RESOURCES, MYF(0)); + tse_log_error("[alloc memory]Failed", table->s->fields * sizeof(tse_cbo_stats_column_t)); return ERR_ALLOC_MEMORY; } if (user_var_set(thd, "ctc_show_alloc_cbo_stats_mem")) { @@ -5242,8 +5241,7 @@ int ha_tse::initialize_cbo_stats() m_share->cbo_stats->tse_cbo_stats_table.ndv_keys = (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); if (m_share->cbo_stats->tse_cbo_stats_table.ndv_keys == nullptr) { - tse_log_error("[alloc memory]Failed",0); - my_error(ER_OUT_OF_RESOURCES, MYF(0)); + tse_log_error("[alloc memory]Failed", table->s->keys * sizeof(uint32_t)); return ERR_ALLOC_MEMORY; } m_share->cbo_stats->msg_len = table->s->fields * sizeof(tse_cbo_stats_column_t); diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index 2ca151a..7d3d7dd 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -76,9 +76,8 @@ static void get_used_partitions(partition_info *part_info, uint32_t **part_ids, *used_parts = part_info->num_partitions_used(); *part_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); if (part_ids == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed",0); - my_error(ER_OUT_OF_RESOURCES, MYF(0)); - return; + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", (*used_parts) * sizeof(uint32_t)); + return ERR_ALLOC_MEMORY; } uint32_t part_id = part_info->get_first_used_partition(); **part_ids = part_id; @@ -262,9 +261,8 @@ void ha_tsepart::start_bulk_insert(ha_rows rows) { m_bulk_insert_parts = (ctc_part_t *)my_malloc(PSI_NOT_INSTRUMENTED, m_max_batch_num * sizeof(ctc_part_t), MYF(MY_WME)); if (m_bulk_insert_parts == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed",0); - my_error(ER_OUT_OF_RESOURCES, MYF(0)); - return; + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", m_max_batch_num * sizeof(ctc_part_t)); + return ERR_ALLOC_MEMORY; } } } @@ -979,7 +977,7 @@ int ha_tsepart::initialize_cbo_stats() { m_part_share->cbo_stats = (tianchi_cbo_stats_t*)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(tianchi_cbo_stats_t), MYF(MY_WME)); if (m_part_share->cbo_stats == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", 0); + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); return ERR_ALLOC_MEMORY; } *m_part_share->cbo_stats = {0, 0, 0, 0, 0, 0, 0, nullptr, nullptr, nullptr}; @@ -989,7 +987,7 @@ int ha_tsepart::initialize_cbo_stats() { m_part_share->cbo_stats->tse_cbo_stats_part_table = (tse_cbo_stats_table_t*)my_malloc(PSI_NOT_INSTRUMENTED, part_num * sizeof(tse_cbo_stats_table_t), MYF(MY_WME)); if (m_part_share->cbo_stats->tse_cbo_stats_part_table == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", 0); + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", part_num * sizeof(tse_cbo_stats_table_t)); return ERR_ALLOC_MEMORY; } @@ -997,13 +995,13 @@ int ha_tsepart::initialize_cbo_stats() { m_part_share->cbo_stats->tse_cbo_stats_part_table[i].columns = (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); if (m_part_share->cbo_stats->tse_cbo_stats_part_table[i].columns == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", 0); + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", table->s->fields * sizeof(tse_cbo_stats_column_t)); return ERR_ALLOC_MEMORY; } m_part_share->cbo_stats->tse_cbo_stats_part_table[i].ndv_keys = (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); if (m_part_share->cbo_stats->tse_cbo_stats_part_table[i].ndv_keys == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", 0); + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", table->s->keys * sizeof(uint32_t)); return ERR_ALLOC_MEMORY; } } diff --git a/storage/tianchi/mysql_daac_plugin.cc b/storage/tianchi/mysql_daac_plugin.cc index 0359cb2..37ab42b 100644 --- a/storage/tianchi/mysql_daac_plugin.cc +++ b/storage/tianchi/mysql_daac_plugin.cc @@ -120,7 +120,7 @@ int daemon_daac_plugin_init() { PSI_NOT_INSTRUMENTED, sizeof(struct mysql_daac_context), MYF(0)); if (daac_context == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", 0); + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(struct mysql_daac_context)); return ERR_ALLOC_MEMORY; } -- Gitee From 7e3a123c89d4e5c3d7665e198f76aeb023219cc6 Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Tue, 14 May 2024 16:15:15 +0800 Subject: [PATCH 08/15] update code --- storage/tianchi/ha_tse.cc | 4 ++-- storage/tianchi/ha_tsepart.cc | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index dc632f9..ddb706d 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -5231,7 +5231,7 @@ int ha_tse::initialize_cbo_stats() (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); THD* thd = ha_thd(); if (m_share->cbo_stats->tse_cbo_stats_table.columns == nullptr) { - tse_log_error("[alloc memory]Failed", table->s->fields * sizeof(tse_cbo_stats_column_t)); + tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", table->s->fields * sizeof(tse_cbo_stats_column_t)); return ERR_ALLOC_MEMORY; } if (user_var_set(thd, "ctc_show_alloc_cbo_stats_mem")) { @@ -5241,7 +5241,7 @@ int ha_tse::initialize_cbo_stats() m_share->cbo_stats->tse_cbo_stats_table.ndv_keys = (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); if (m_share->cbo_stats->tse_cbo_stats_table.ndv_keys == nullptr) { - tse_log_error("[alloc memory]Failed", table->s->keys * sizeof(uint32_t)); + tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", table->s->keys * sizeof(uint32_t)); return ERR_ALLOC_MEMORY; } m_share->cbo_stats->msg_len = table->s->fields * sizeof(tse_cbo_stats_column_t); diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index 7d3d7dd..a940cc9 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -76,8 +76,7 @@ static void get_used_partitions(partition_info *part_info, uint32_t **part_ids, *used_parts = part_info->num_partitions_used(); *part_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); if (part_ids == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", (*used_parts) * sizeof(uint32_t)); - return ERR_ALLOC_MEMORY; + tse_log_error("[cantian2mysql]Apply for blob buf:%lu Failed", (*used_parts) * sizeof(uint32_t)); } uint32_t part_id = part_info->get_first_used_partition(); **part_ids = part_id; @@ -261,8 +260,7 @@ void ha_tsepart::start_bulk_insert(ha_rows rows) { m_bulk_insert_parts = (ctc_part_t *)my_malloc(PSI_NOT_INSTRUMENTED, m_max_batch_num * sizeof(ctc_part_t), MYF(MY_WME)); if (m_bulk_insert_parts == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", m_max_batch_num * sizeof(ctc_part_t)); - return ERR_ALLOC_MEMORY; + tse_log_error("[cantian2mysql]Apply for blob buf:%lu Failed", m_max_batch_num * sizeof(ctc_part_t)); } } } -- Gitee From 04e2e9defdfe89ff52b0ac7dd81d4643b905fe24 Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Tue, 14 May 2024 16:28:28 +0800 Subject: [PATCH 09/15] update code --- storage/tianchi/mysql_daac_plugin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/tianchi/mysql_daac_plugin.cc b/storage/tianchi/mysql_daac_plugin.cc index 37ab42b..b0c665c 100644 --- a/storage/tianchi/mysql_daac_plugin.cc +++ b/storage/tianchi/mysql_daac_plugin.cc @@ -130,7 +130,7 @@ int daemon_daac_plugin_init() { /* now create the startup thread */ if (my_thread_create(&daac_context->daac_startup_thread, &startup_attr, mysql_daac_startup_thread, (void *)daac_context) != 0) { - tse_log_error("Could not create daac startup thread!",0); + tse_log_error("Could not create daac startup thread!"); return -1; } return 0; -- Gitee From b1ff4d6181eb87b21ce084814d5e909740bdc7f9 Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Tue, 14 May 2024 16:52:09 +0800 Subject: [PATCH 10/15] update code --- storage/tianchi/ha_tse.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index ddb706d..628005c 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -2283,7 +2283,7 @@ int ha_tse::initialize() { // size is limited by struct defined in shared mem m_prefetch_buf = (uchar *)my_malloc(PSI_NOT_INSTRUMENTED, MAX_RECORD_SIZE, MYF(MY_WME)); if (m_prefetch_buf == nullptr) { - tse_log_error("alloc mem failed, m_prefetch_buf size(%u)",MAX_RECORD_SIZE); + tse_log_error("alloc mem failed, m_prefetch_buf size(%u)", MAX_RECORD_SIZE); return HA_ERR_OUT_OF_MEM; } -- Gitee From 23f5c4f4c28378fd7c558dda2a2cc17a54deeb8a Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Tue, 14 May 2024 17:30:41 +0800 Subject: [PATCH 11/15] update code --- storage/tianchi/ha_tsepart.cc | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index 0560ab2..2f13fab 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -75,17 +75,6 @@ static uint32_t get_ct_part_no(uint num_subparts, uint part_id) { static bool get_used_partitions(partition_info *part_info, uint32_t **part_ids,uint32_t **subpart_ids, uint32_t *used_parts) { *used_parts = part_info->num_partitions_used(); -<<<<<<< HEAD - *part_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); - if (part_ids == nullptr) { - tse_log_error("[cantian2mysql]Apply for blob buf:%lu Failed", (*used_parts) * sizeof(uint32_t)); - } - uint32_t part_id = part_info->get_first_used_partition(); - **part_ids = part_id; - for (uint32_t i = 1; i < *used_parts; i++) { - part_id = part_info->get_next_used_partition(part_id); - *(*part_ids + i) = part_id; -======= if (*used_parts > 0) { *part_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); if (*part_ids == NULL) { @@ -119,7 +108,6 @@ static bool get_used_partitions(partition_info *part_info, } }else{ tse_log_system("invalid used_parts :%u", *used_parts); ->>>>>>> ceb04ce73622f4076606dfe88a5a004e503ffc3b } return true; } -- Gitee From df66bb8e9cfa26d2abdd7b5d2f16ad0680b11441 Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Tue, 14 May 2024 19:27:29 +0800 Subject: [PATCH 12/15] update code --- storage/tianchi/datatype_cnvrtr.cc | 3 ++ storage/tianchi/ha_tse.cc | 16 +++++++++++ storage/tianchi/ha_tsepart.cc | 42 ++++++++++++---------------- storage/tianchi/mysql_daac_plugin.cc | 1 + 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/storage/tianchi/datatype_cnvrtr.cc b/storage/tianchi/datatype_cnvrtr.cc index 029cdf2..2a91584 100644 --- a/storage/tianchi/datatype_cnvrtr.cc +++ b/storage/tianchi/datatype_cnvrtr.cc @@ -466,6 +466,7 @@ int convert_blob_to_cantian(uchar *cantian_ptr, uint32 &cantian_offset, if (lob_locator == nullptr) { tse_log_error("[mysql2cantian]Apply for lob locator:%u Failed", locator_size); my_error(ER_OUT_OF_RESOURCES, MYF(0), "LOB LOCATOR"); + my_free(lob_locator); field_len = 0; return HA_ERR_SE_OUT_OF_MEMORY; } @@ -549,6 +550,7 @@ void convert_blob_to_mysql(uchar *cantian_ptr, Field *mysql_field, tianchi_handl if (blob_buf == nullptr) { tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); + my_free(blob_buf); return; } @@ -1589,6 +1591,7 @@ void copy_column_data_to_mysql(field_info_t *field_info, const field_cnvrt_aux_t if (blob_buf == nullptr) { tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); + my_free(blob_buf); return; } memcpy(blob_buf, field_info->cantian_cur_field, blob_len); diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index 4a1a557..bf9d434 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -1228,6 +1228,7 @@ thd_sess_ctx_s *get_or_init_sess_ctx(handlerton *hton, THD *thd) { sess_ctx = (thd_sess_ctx_s *)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(thd_sess_ctx_s), MYF(MY_WME)); if (sess_ctx == nullptr) { + my_free(sess_ctx); return nullptr; } @@ -2117,6 +2118,7 @@ int ha_tse::prefetch_and_fill_record_buffer(uchar *buf, tse_prefetch_fn prefetch } if (m_prefetch_buf == nullptr) { tse_log_error("alloc mem failed, m_prefetch_buf size(%u)", MAX_RECORD_SIZE); + my_free(m_prefetch_buf); return HA_ERR_OUT_OF_MEM; } @@ -2640,6 +2642,11 @@ void ha_tse::start_bulk_insert(ha_rows rows) { if (m_rec_buf_data == nullptr) { m_rec_buf_data = (uchar *)my_malloc(PSI_NOT_INSTRUMENTED, MAX_RECORD_BUFFER_SIZE_TSE, MYF(MY_WME)); } + if (m_rec_buf_data == nullptr) { + tse_log_error("alloc mem failed, m_prefetch_buf size(%u)", MAX_RECORD_BUFFER_SIZE_TSE); + my_free(m_rec_buf_data); + return; + } if (rows == 1 || m_is_insert_dup || m_is_replace || m_ignore_dup || table->s->blob_fields > 0 || table->next_number_field || m_rec_buf_data == nullptr) { @@ -2862,6 +2869,7 @@ int ha_tse::set_prefetch_buffer() { } if (m_rec_buf_data == nullptr) { tse_log_error("alloc mem failed, m_rec_buf_data size(%u)", MAX_RECORD_BUFFER_SIZE_TSE); + my_free(m_rec_buf_data); return ERR_ALLOC_MEMORY; } @@ -5237,16 +5245,23 @@ int ha_tse::initialize_cbo_stats() m_share->cbo_stats = (tianchi_cbo_stats_t*)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(tianchi_cbo_stats_t), MYF(MY_WME)); if (m_share->cbo_stats == nullptr) { tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); + myfree(m_share->cbo_stats); return ERR_ALLOC_MEMORY; } *m_share->cbo_stats = {0, 0, 0, 0, 0, nullptr, nullptr}; m_share->cbo_stats->tse_cbo_stats_table = (tse_cbo_stats_table_t*)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(tse_cbo_stats_table_t), MYF(MY_WME)); + if (m_share->cbo_stats->tse_cbo_stats_table == nullptr) { + tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", sizeof(tse_cbo_stats_table_t)); + my_free(m_share->cbo_stats->tse_cbo_stats_table); + return ERR_ALLOC_MEMORY; + } m_share->cbo_stats->tse_cbo_stats_table->columns = (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); THD* thd = ha_thd(); if (m_share->cbo_stats->tse_cbo_stats_table.columns == nullptr) { tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", table->s->fields * sizeof(tse_cbo_stats_column_t)); + my_free(m_share->cbo_stats->tse_cbo_stats_table.columns); return ERR_ALLOC_MEMORY; } if (user_var_set(thd, "ctc_show_alloc_cbo_stats_mem")) { @@ -5257,6 +5272,7 @@ int ha_tse::initialize_cbo_stats() (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); if (m_share->cbo_stats->tse_cbo_stats_table.ndv_keys == nullptr) { tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", table->s->keys * sizeof(uint32_t)); + my_free(m_share->cbo_stats->tse_cbo_stats_table.ndv_keys); return ERR_ALLOC_MEMORY; } m_share->cbo_stats->msg_len = table->s->fields * sizeof(tse_cbo_stats_column_t); diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index 2f13fab..58e6224 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -84,7 +84,7 @@ static bool get_used_partitions(partition_info *part_info, *subpart_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); if (*subpart_ids == NULL) { tse_log_system("Failed to allocate memory for subpart_ids. Freeing previously allocated memory..."); - my_free(*part_ids); + my_free(*subpart_ids); return false; } uint32_t part_id = part_info->get_first_used_partition(); @@ -286,6 +286,7 @@ void ha_tsepart::start_bulk_insert(ha_rows rows) { m_max_batch_num * sizeof(ctc_part_t), MYF(MY_WME)); if (m_bulk_insert_parts == nullptr) { tse_log_error("[cantian2mysql]Apply for blob buf:%lu Failed", m_max_batch_num * sizeof(ctc_part_t)); + my_free(m_bulk_insert_parts); } } } @@ -1012,42 +1013,35 @@ int ha_tsepart::initialize_cbo_stats() { m_part_share->cbo_stats = (tianchi_cbo_stats_t*)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(tianchi_cbo_stats_t), MYF(MY_WME)); if (m_part_share->cbo_stats == nullptr) { tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); + my_free(m_part_share->cbo_stats); return ERR_ALLOC_MEMORY; } *m_part_share->cbo_stats = {0, 0, 0, 0, 0, nullptr, nullptr}; m_part_share->cbo_stats->part_cnt = part_num; -<<<<<<< HEAD - m_part_share->cbo_stats->tse_cbo_stats_part_table = - (tse_cbo_stats_table_t*)my_malloc(PSI_NOT_INSTRUMENTED, part_num * sizeof(tse_cbo_stats_table_t), MYF(MY_WME)); - if (m_part_share->cbo_stats->tse_cbo_stats_part_table == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", part_num * sizeof(tse_cbo_stats_table_t)); - return ERR_ALLOC_MEMORY; - } - - for (uint i = 0; i < part_num; i++) { - m_part_share->cbo_stats->tse_cbo_stats_part_table[i].columns = - (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); - if (m_part_share->cbo_stats->tse_cbo_stats_part_table[i].columns == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", table->s->fields * sizeof(tse_cbo_stats_column_t)); - return ERR_ALLOC_MEMORY; - } - m_part_share->cbo_stats->tse_cbo_stats_part_table[i].ndv_keys = - (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); - if (m_part_share->cbo_stats->tse_cbo_stats_part_table[i].ndv_keys == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", table->s->keys * sizeof(uint32_t)); - return ERR_ALLOC_MEMORY; - } -======= m_part_share->cbo_stats->tse_cbo_stats_table = (tse_cbo_stats_table_t*)my_malloc(PSI_NOT_INSTRUMENTED, part_num * sizeof(tse_cbo_stats_table_t), MYF(MY_WME)); + if (m_part_share->cbo_stats->tse_cbo_stats_table == nullptr) { + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", part_num * sizeof(tse_cbo_stats_table_t)); + my_free(m_part_share->cbo_stats->tse_cbo_stats_table); + return ERR_ALLOC_MEMORY; + } m_part_share->cbo_stats->ndv_keys = (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); + if (m_part_share->cbo_stats->ndv_keys == nullptr) { + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", table->s->keys * sizeof(uint32_t)); + my_free(m_part_share->cbo_stats->ndv_keys); + return ERR_ALLOC_MEMORY; + } for (uint i = 0; i < part_num; i++) { m_part_share->cbo_stats->tse_cbo_stats_table[i].columns = (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); ->>>>>>> ceb04ce73622f4076606dfe88a5a004e503ffc3b + if (m_part_share->cbo_stats->tse_cbo_stats_table[i].columns == nullptr) { + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", table->s->fields * sizeof(tse_cbo_stats_column_t)); + my_free(m_part_share->cbo_stats->tse_cbo_stats_table[i].columns); + return ERR_ALLOC_MEMORY; + } } m_part_share->cbo_stats->msg_len = table->s->fields * sizeof(tse_cbo_stats_column_t); m_part_share->cbo_stats->key_len = table->s->keys * sizeof(uint32_t); diff --git a/storage/tianchi/mysql_daac_plugin.cc b/storage/tianchi/mysql_daac_plugin.cc index b0c665c..4d2bde8 100644 --- a/storage/tianchi/mysql_daac_plugin.cc +++ b/storage/tianchi/mysql_daac_plugin.cc @@ -121,6 +121,7 @@ int daemon_daac_plugin_init() { sizeof(struct mysql_daac_context), MYF(0)); if (daac_context == nullptr) { tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(struct mysql_daac_context)); + my_free(daac_context); return ERR_ALLOC_MEMORY; } -- Gitee From e14da4c3aebc522dc5ee645a43fedd4edb306473 Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Tue, 14 May 2024 19:49:53 +0800 Subject: [PATCH 13/15] update code --- storage/tianchi/ha_tse.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index bf9d434..8608f2d 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -5245,7 +5245,7 @@ int ha_tse::initialize_cbo_stats() m_share->cbo_stats = (tianchi_cbo_stats_t*)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(tianchi_cbo_stats_t), MYF(MY_WME)); if (m_share->cbo_stats == nullptr) { tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); - myfree(m_share->cbo_stats); + my_free(m_share->cbo_stats); return ERR_ALLOC_MEMORY; } *m_share->cbo_stats = {0, 0, 0, 0, 0, nullptr, nullptr}; @@ -5259,9 +5259,9 @@ int ha_tse::initialize_cbo_stats() m_share->cbo_stats->tse_cbo_stats_table->columns = (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); THD* thd = ha_thd(); - if (m_share->cbo_stats->tse_cbo_stats_table.columns == nullptr) { + if (m_share->cbo_stats->tse_cbo_stats_table->columns == nullptr) { tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", table->s->fields * sizeof(tse_cbo_stats_column_t)); - my_free(m_share->cbo_stats->tse_cbo_stats_table.columns); + my_free(m_share->cbo_stats->tse_cbo_stats_table->columns); return ERR_ALLOC_MEMORY; } if (user_var_set(thd, "ctc_show_alloc_cbo_stats_mem")) { @@ -5270,9 +5270,9 @@ int ha_tse::initialize_cbo_stats() m_share->cbo_stats->ndv_keys = (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); - if (m_share->cbo_stats->tse_cbo_stats_table.ndv_keys == nullptr) { + if (m_share->cbo_stats->ndv_keys == nullptr) { tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", table->s->keys * sizeof(uint32_t)); - my_free(m_share->cbo_stats->tse_cbo_stats_table.ndv_keys); + my_free(m_share->cbo_stats->ndv_keys); return ERR_ALLOC_MEMORY; } m_share->cbo_stats->msg_len = table->s->fields * sizeof(tse_cbo_stats_column_t); -- Gitee From 2ff3b1ddeee2e6a7715ad043a29ad1344ec882a7 Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Wed, 15 May 2024 09:17:37 +0800 Subject: [PATCH 14/15] update code --- storage/tianchi/ha_tse.cc | 4 ++-- storage/tianchi/ha_tsepart.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index bcda491..47709cf 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -5269,9 +5269,9 @@ int ha_tse::initialize_cbo_stats() } m_share->cbo_stats->ndv_keys = - (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); + (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t) * MAX_KEY_COLUMNS, MYF(MY_WME)); if (m_share->cbo_stats->ndv_keys == nullptr) { - tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", table->s->keys * sizeof(uint32_t)); + tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", table->s->keys * sizeof(uint32_t) * MAX_KEY_COLUMNS); my_free(m_share->cbo_stats->ndv_keys); return ERR_ALLOC_MEMORY; } diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index 74c4f62..ab4749a 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -1028,9 +1028,9 @@ int ha_tsepart::initialize_cbo_stats() { return ERR_ALLOC_MEMORY; } m_part_share->cbo_stats->ndv_keys = - (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); + (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t) * MAX_KEY_COLUMNS, MYF(MY_WME)); if (m_part_share->cbo_stats->ndv_keys == nullptr) { - tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", table->s->keys * sizeof(uint32_t)); + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", table->s->keys * sizeof(uint32_t) * MAX_KEY_COLUMNS); my_free(m_part_share->cbo_stats->ndv_keys); return ERR_ALLOC_MEMORY; } -- Gitee From c746baab6fdb7162e23d6f5c0036dcd098eb5063 Mon Sep 17 00:00:00 2001 From: hezijian1111 Date: Wed, 15 May 2024 09:45:16 +0800 Subject: [PATCH 15/15] update code --- storage/tianchi/ha_tsepart.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index ab4749a..f9cfe2c 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -79,6 +79,7 @@ static bool get_used_partitions(partition_info *part_info, *part_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); if (*part_ids == NULL) { tse_log_system("Failed to allocate memory for part_ids."); + my_free(*part_ids); return false; } *subpart_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); -- Gitee