Skip to content

Commit

Permalink
MDEV-32524 Use enums for ids passed to spider mem alloc functions
Browse files Browse the repository at this point in the history
This will avoid issues like MDEV-32486

IDs used in
- spider_alloc_calc_mem_init()
- spider_string::init_calc_mem()
- spider_malloc()
- spider_bulk_alloc_mem()
- spider_bulk_malloc()
  • Loading branch information
mariadb-YuchenPei committed Nov 19, 2023
1 parent 4cf3a1b commit 0b36694
Show file tree
Hide file tree
Showing 14 changed files with 529 additions and 258 deletions.
36 changes: 18 additions & 18 deletions storage/spider/ha_spider.cc
Expand Up @@ -73,7 +73,7 @@ ha_spider::ha_spider(
{
DBUG_ENTER("ha_spider::ha_spider");
DBUG_PRINT("info",("spider this=%p", this));
spider_alloc_calc_mem_init(mem_calc, 139);
spider_alloc_calc_mem_init(mem_calc, SPD_MID_HA_SPIDER_HA_SPIDER_1);
spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this));
share = NULL;
trx = NULL;
Expand Down Expand Up @@ -185,7 +185,7 @@ ha_spider::ha_spider(
{
DBUG_ENTER("ha_spider::ha_spider");
DBUG_PRINT("info",("spider this=%p", this));
spider_alloc_calc_mem_init(mem_calc, 0);
spider_alloc_calc_mem_init(mem_calc, SPD_MID_HA_SPIDER_HA_SPIDER_2);
spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this));
share = NULL;
trx = NULL;
Expand Down Expand Up @@ -394,7 +394,7 @@ int ha_spider::open(
if (create_pt_handler_share)
{
if (!(searched_bitmap = (uchar *)
spider_bulk_malloc(spider_current_trx, 15, MYF(MY_WME),
spider_bulk_malloc(spider_current_trx, SPD_MID_HA_SPIDER_OPEN_1, MYF(MY_WME),
&searched_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
&ft_discard_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
&position_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
Expand Down Expand Up @@ -462,7 +462,7 @@ int ha_spider::open(
} else {
#endif
if (!(searched_bitmap = (uchar *)
spider_bulk_malloc(spider_current_trx, 16, MYF(MY_WME),
spider_bulk_malloc(spider_current_trx, SPD_MID_HA_SPIDER_OPEN_2, MYF(MY_WME),
&searched_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
&ft_discard_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
&position_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set),
Expand Down Expand Up @@ -520,10 +520,10 @@ int ha_spider::open(
}
for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
{
result_list.sqls[roop_count].init_calc_mem(80);
result_list.insert_sqls[roop_count].init_calc_mem(81);
result_list.update_sqls[roop_count].init_calc_mem(82);
result_list.tmp_sqls[roop_count].init_calc_mem(83);
result_list.sqls[roop_count].init_calc_mem(SPD_MID_HA_SPIDER_OPEN_3);
result_list.insert_sqls[roop_count].init_calc_mem(SPD_MID_HA_SPIDER_OPEN_4);
result_list.update_sqls[roop_count].init_calc_mem(SPD_MID_HA_SPIDER_OPEN_5);
result_list.tmp_sqls[roop_count].init_calc_mem(SPD_MID_HA_SPIDER_OPEN_6);
uint all_link_idx = conn_link_idx[roop_count];
uint dbton_id = share->sql_dbton_ids[all_link_idx];
if (share->dbton_share[dbton_id]->need_change_db_table_name())
Expand Down Expand Up @@ -554,7 +554,7 @@ int ha_spider::open(
}
for (roop_count = 0; roop_count < (int) table_share->fields; roop_count++)
{
blob_buff[roop_count].init_calc_mem(84);
blob_buff[roop_count].init_calc_mem(SPD_MID_HA_SPIDER_OPEN_7);
blob_buff[roop_count].set_charset(table->field[roop_count]->charset());
}
}
Expand Down Expand Up @@ -5065,13 +5065,13 @@ int ha_spider::read_multi_range_first_internal(
}
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
if (!(multi_range_keys = (range_id_t *)
spider_malloc(spider_current_trx, 1, sizeof(range_id_t) *
spider_malloc(spider_current_trx, SPD_MID_HA_SPIDER_MULTI_RANGE_READ_NEXT_FIRST_1, sizeof(range_id_t) *
(multi_range_num < result_list.multi_split_read ?
multi_range_num : result_list.multi_split_read), MYF(MY_WME)))
)
#else
if (!(multi_range_keys = (char **)
spider_malloc(spider_current_trx, 1, sizeof(char *) *
spider_malloc(spider_current_trx, SPD_MID_HA_SPIDER_MULTI_RANGE_READ_NEXT_FIRST_2, sizeof(char *) *
(multi_range_num < result_list.multi_split_read ?
multi_range_num : result_list.multi_split_read), MYF(MY_WME)))
)
Expand All @@ -5085,7 +5085,7 @@ int ha_spider::read_multi_range_first_internal(
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
for (roop_count = 0; roop_count < 2; roop_count++)
mrr_key_buff[roop_count].init_calc_mem(235);
mrr_key_buff[roop_count].init_calc_mem(SPD_MID_HA_SPIDER_MULTI_RANGE_READ_NEXT_FIRST_3);
}
#else
multi_range_ranges = ranges;
Expand Down Expand Up @@ -8201,7 +8201,7 @@ FT_INFO *ha_spider::ft_init_ext(
if (!ft_current)
{
if (!(ft_current = (st_spider_ft_info *)
spider_malloc(spider_current_trx, 2, sizeof(st_spider_ft_info),
spider_malloc(spider_current_trx, SPD_MID_HA_SPIDER_FT_INIT_EXT_1, sizeof(st_spider_ft_info),
MYF(MY_WME | MY_ZEROFILL))))
{
my_error(HA_ERR_OUT_OF_MEM, MYF(0));
Expand Down Expand Up @@ -11479,7 +11479,7 @@ int ha_spider::create(
if (form->s->keys > 0)
{
if (!(tmp_share.static_key_cardinality = (longlong *)
spider_bulk_malloc(spider_current_trx, 246, MYF(MY_WME),
spider_bulk_malloc(spider_current_trx, SPD_MID_HA_SPIDER_CREATE_1, MYF(MY_WME),
&tmp_share.static_key_cardinality,
sizeof(*tmp_share.static_key_cardinality) * form->s->keys,
NullS))
Expand All @@ -11494,7 +11494,7 @@ int ha_spider::create(
}
}
for (roop_count = 0; roop_count < form->s->keys; roop_count++)
tmp_share.key_hint[roop_count].init_calc_mem(85);
tmp_share.key_hint[roop_count].init_calc_mem(SPD_MID_HA_SPIDER_CREATE_2);
DBUG_PRINT("info",("spider tmp_share.key_hint=%p", tmp_share.key_hint));
if ((error_num = spider_parse_connect_info(&tmp_share, form->s,
#ifdef WITH_PARTITION_STORAGE_ENGINE
Expand Down Expand Up @@ -12216,7 +12216,7 @@ const COND *ha_spider::cond_push(
{
SPIDER_CONDITION *tmp_cond;
if (!(tmp_cond = (SPIDER_CONDITION *)
spider_malloc(spider_current_trx, 3, sizeof(*tmp_cond), MYF(MY_WME)))
spider_malloc(spider_current_trx, SPD_MID_HA_SPIDER_COND_PUSH_1, sizeof(*tmp_cond), MYF(MY_WME)))
)
DBUG_RETURN(cond);
tmp_cond->cond = (COND *) cond;
Expand Down Expand Up @@ -12290,7 +12290,7 @@ int ha_spider::info_push(
if (hs_pushed_ret_fields)
spider_free(spider_current_trx, hs_pushed_ret_fields, MYF(0));
if (!(hs_pushed_ret_fields = (uint32 *)
spider_bulk_malloc(spider_current_trx, 17, MYF(MY_WME),
spider_bulk_malloc(spider_current_trx, SPD_MID_HA_SPIDER_INFO_PUSH_1, MYF(MY_WME),
&hs_pushed_ret_fields, sizeof(uint32) * hs_pushed_ret_fields_num,
NullS))
) {
Expand Down Expand Up @@ -13853,7 +13853,7 @@ SPIDER_BULK_ACCESS_LINK *ha_spider::create_bulk_access_link()
}
*/
if (!(bulk_access_link = (SPIDER_BULK_ACCESS_LINK *)
spider_bulk_malloc(spider_current_trx, 168, MYF(MY_WME),
spider_bulk_malloc(spider_current_trx, SPD_MID_HA_SPIDER_CREATE_BULK_ACCESS_LINK_1, MYF(MY_WME),
&bulk_access_link, sizeof(SPIDER_BULK_ACCESS_LINK),
&ref, ALIGN_SIZE(ref_length) * 2,
NullS))
Expand Down
18 changes: 9 additions & 9 deletions storage/spider/spd_conn.cc
Expand Up @@ -475,7 +475,7 @@ SPIDER_CONN *spider_create_conn(
{
#endif
if (!(conn = (SPIDER_CONN *)
spider_bulk_malloc(spider_current_trx, 18, MYF(MY_WME | MY_ZEROFILL),
spider_bulk_malloc(spider_current_trx, SPD_MID_CREATE_CONN_1, MYF(MY_WME | MY_ZEROFILL),
&conn, sizeof(*conn),
&tmp_name, share->conn_keys_lengths[link_idx] + 1,
&tmp_host, share->tgt_hosts_lengths[link_idx] + 1,
Expand Down Expand Up @@ -506,7 +506,7 @@ SPIDER_CONN *spider_create_conn(
goto error_alloc_conn;
}

conn->default_database.init_calc_mem(75);
conn->default_database.init_calc_mem(SPD_MID_CREATE_CONN_2);
conn->conn_key_length = share->conn_keys_lengths[link_idx];
conn->conn_key = tmp_name;
memcpy(conn->conn_key, share->conn_keys[link_idx],
Expand Down Expand Up @@ -604,7 +604,7 @@ SPIDER_CONN *spider_create_conn(
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
} else if (conn_kind == SPIDER_CONN_KIND_HS_READ) {
if (!(conn = (SPIDER_CONN *)
spider_bulk_malloc(spider_current_trx, 19, MYF(MY_WME | MY_ZEROFILL),
spider_bulk_malloc(spider_current_trx, SPD_MID_CREATE_CONN_3, MYF(MY_WME | MY_ZEROFILL),
&conn, sizeof(*conn),
&tmp_name, share->hs_read_conn_keys_lengths[link_idx] + 1,
&tmp_host, share->tgt_hosts_lengths[link_idx] + 1,
Expand All @@ -618,7 +618,7 @@ SPIDER_CONN *spider_create_conn(
goto error_alloc_conn;
}

conn->default_database.init_calc_mem(76);
conn->default_database.init_calc_mem(SPD_MID_CREATE_CONN_4);
conn->conn_key_length = share->hs_read_conn_keys_lengths[link_idx];
conn->conn_key = tmp_name;
memcpy(conn->conn_key, share->hs_read_conn_keys[link_idx],
Expand Down Expand Up @@ -646,7 +646,7 @@ SPIDER_CONN *spider_create_conn(
conn->dbton_id = share->hs_dbton_ids[link_idx];
} else {
if (!(conn = (SPIDER_CONN *)
spider_bulk_malloc(spider_current_trx, 20, MYF(MY_WME | MY_ZEROFILL),
spider_bulk_malloc(spider_current_trx, SPD_MID_CREATE_CONN_5, MYF(MY_WME | MY_ZEROFILL),
&conn, sizeof(*conn),
&tmp_name, share->hs_write_conn_keys_lengths[link_idx] + 1,
&tmp_host, share->tgt_hosts_lengths[link_idx] + 1,
Expand All @@ -660,7 +660,7 @@ SPIDER_CONN *spider_create_conn(
goto error_alloc_conn;
}

conn->default_database.init_calc_mem(77);
conn->default_database.init_calc_mem(SPD_MID_CREATE_CONN_6);
conn->conn_key_length = share->hs_write_conn_keys_lengths[link_idx];
conn->conn_key = tmp_name;
memcpy(conn->conn_key, share->hs_write_conn_keys[link_idx],
Expand Down Expand Up @@ -1930,7 +1930,7 @@ int spider_create_conn_thread(
error_num = HA_ERR_OUT_OF_MEM;
goto error_job_stack_init;
}
spider_alloc_calc_mem_init(conn->bg_job_stack, 163);
spider_alloc_calc_mem_init(conn->bg_job_stack, SPD_MID_CREATE_CONN_THREAD_1);
spider_alloc_calc_mem(spider_current_trx,
conn->bg_job_stack,
conn->bg_job_stack.max_element *
Expand Down Expand Up @@ -3691,7 +3691,7 @@ int spider_create_mon_threads(
char *buf = (char *) my_alloca(share->table_name_length + SPIDER_SQL_INT_LEN + 1);
spider_string conv_name_str(buf, share->table_name_length +
SPIDER_SQL_INT_LEN + 1, system_charset_info);
conv_name_str.init_calc_mem(105);
conv_name_str.init_calc_mem(SPD_MID_CREATE_MON_THREADS_1);
conv_name_str.length(0);
conv_name_str.q_append(share->table_name, share->table_name_length);
for (roop_count = 0; roop_count < (int) share->all_link_count;
Expand Down Expand Up @@ -3724,7 +3724,7 @@ int spider_create_mon_threads(
}
}
if (!(share->bg_mon_thds = (THD **)
spider_bulk_malloc(spider_current_trx, 23, MYF(MY_WME | MY_ZEROFILL),
spider_bulk_malloc(spider_current_trx, SPD_MID_CREATE_MON_THREADS_2, MYF(MY_WME | MY_ZEROFILL),
&share->bg_mon_thds, sizeof(THD *) * share->all_link_count,
&share->bg_mon_threads, sizeof(pthread_t) * share->all_link_count,
&share->bg_mon_mutexes, sizeof(pthread_mutex_t) *
Expand Down
14 changes: 7 additions & 7 deletions storage/spider/spd_copy_tables.cc
Expand Up @@ -286,7 +286,7 @@ int spider_udf_get_copy_tgt_tables(
}
do {
if (!(table_conn = (SPIDER_COPY_TABLE_CONN *)
spider_bulk_malloc(spider_current_trx, 25, MYF(MY_WME | MY_ZEROFILL),
spider_bulk_malloc(spider_current_trx, SPD_MID_UDF_GET_COPY_TGT_TABLES_1, MYF(MY_WME | MY_ZEROFILL),
&table_conn, sizeof(SPIDER_COPY_TABLE_CONN),
&tmp_share, sizeof(SPIDER_SHARE),
&tmp_connect_info, sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT,
Expand Down Expand Up @@ -601,7 +601,7 @@ int spider_udf_copy_tables_create_table_list(
}

if (!(copy_tables->link_idxs[0] = (int *)
spider_bulk_malloc(spider_current_trx, 26, MYF(MY_WME | MY_ZEROFILL),
spider_bulk_malloc(spider_current_trx, SPD_MID_UDF_COPY_TABLES_CREATE_TABLE_LIST_1, MYF(MY_WME | MY_ZEROFILL),
&copy_tables->link_idxs[0],
sizeof(int) * copy_tables->link_idx_count[0],
&copy_tables->link_idxs[1],
Expand Down Expand Up @@ -802,7 +802,7 @@ long long spider_copy_tables_body(
}

if (!(copy_tables = (SPIDER_COPY_TABLES *)
spider_bulk_malloc(spider_current_trx, 27, MYF(MY_WME | MY_ZEROFILL),
spider_bulk_malloc(spider_current_trx, SPD_MID_COPY_TABLES_BODY_1, MYF(MY_WME | MY_ZEROFILL),
&copy_tables, sizeof(SPIDER_COPY_TABLES),
NullS))
) {
Expand Down Expand Up @@ -1018,7 +1018,7 @@ long long spider_copy_tables_body(
{
tmp_spider = &spider[roop_count];
if (!(tmp_spider->dbton_handler = (spider_db_handler **)
spider_bulk_alloc_mem(spider_current_trx, 205,
spider_bulk_alloc_mem(spider_current_trx, SPD_MID_COPY_TABLES_BODY_2,
__func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL),
&tmp_spider->dbton_handler,
sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE,
Expand All @@ -1037,7 +1037,7 @@ long long spider_copy_tables_body(
}
*/
tmp_spider->conns = &table_conn->conn;
tmp_sql[roop_count].init_calc_mem(122);
tmp_sql[roop_count].init_calc_mem(SPD_MID_COPY_TABLES_BODY_3);
tmp_sql[roop_count].set_charset(copy_tables->access_charset);
tmp_spider->result_list.sqls = &tmp_sql[roop_count];
tmp_spider->need_mons = &table_conn->need_mon;
Expand All @@ -1062,7 +1062,7 @@ long long spider_copy_tables_body(
{
tmp_spider = &spider[roop_count];
if (!(tmp_spider->dbton_handler = (spider_db_handler **)
spider_bulk_alloc_mem(spider_current_trx, 206,
spider_bulk_alloc_mem(spider_current_trx, SPD_MID_COPY_TABLES_BODY_4,
__func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL),
&tmp_spider->dbton_handler,
sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE,
Expand All @@ -1081,7 +1081,7 @@ long long spider_copy_tables_body(
}
*/
tmp_spider->conns = &table_conn->conn;
tmp_sql[roop_count].init_calc_mem(201);
tmp_sql[roop_count].init_calc_mem(SPD_MID_COPY_TABLES_BODY_5);
tmp_sql[roop_count].set_charset(copy_tables->access_charset);
tmp_spider->result_list.sqls = &tmp_sql[roop_count];
tmp_spider->need_mons = &table_conn->need_mon;
Expand Down

0 comments on commit 0b36694

Please sign in to comment.