The cleanup is a bit more involved than I expected which is why I opened this ticket separately from MDEV-31787.
We can just factor out the portion in the gif, but it is not a "logical" block by it self, but rather a block before a for loop, and the if branch inside the for loop. There are (often minor) differences in the else branches, which may not be real differences, but require a bit more effort to the cleanup properly.
For example, I suspect the following are not real differences, and just redundancy in data structure
--- /home/ycp/source/mariadb-server/mdev-26151/repeats/rnd_next_internal.cc 2023-07-28 12:49:48.384561252 +1000
|
+++ /home/ycp/source/mariadb-server/mdev-26151/repeats/ft_read_internal.cc 2023-07-28 12:49:56.304500405 +1000
|
} else {
|
+ uint dbton_id = share->use_sql_dbton_ids[roop_count];
|
+ spider_db_handler *dbton_hdl = dbton_handler[dbton_id];
|
SPIDER_CONN *conn = conns[roop_count];
|
- ulong sql_type;
|
- sql_type= SPIDER_SQL_TYPE_SELECT_SQL;
|
- spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id];
|
I suspect share->use_sql_dbton_ids[roop_count] and conn->dbton_id are always the same value.
Another issues is the pattern in calls to spider_ping_table_mon_from_table(), and the patterns like the following in setup and teardown of queries
pthread_mutex_lock(&conn->mta_conn_mutex);
|
SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
|
conn->need_mon = &need_mons[roop_count];
|
DBUG_ASSERT(!conn->mta_conn_mutex_lock_already);
|
DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later);
|
conn->mta_conn_mutex_lock_already = TRUE;
|
conn->mta_conn_mutex_unlock_later = TRUE;
|
if ((error_num = spider_db_set_names(this, conn, roop_count)))
|
{
|
DBUG_ASSERT(conn->mta_conn_mutex_lock_already);
|
DBUG_ASSERT(conn->mta_conn_mutex_unlock_later);
|
conn->mta_conn_mutex_lock_already = FALSE;
|
conn->mta_conn_mutex_unlock_later = FALSE;
|
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
|
pthread_mutex_unlock(&conn->mta_conn_mutex);
|
They come in variants (sometimes missing the set / clear file pos part, sometimes without assigning to conn->need_mon) and is scattered all around the codebase, and need a proper cleanup based on understanding (see also my previous attempt in MDEV-29502 https://github.com/MariaDB/server/commit/3b5cecbacd46ea8607b4e5379633e60a98d71bc5). Therefore we defer this ticket to later, maybe when relevant to another task
The cleanup is a bit more involved than I expected which is why I opened this ticket separately from
MDEV-31787.We can just factor out the portion in the gif, but it is not a "logical" block by it self, but rather a block before a for loop, and the if branch inside the for loop. There are (often minor) differences in the else branches, which may not be real differences, but require a bit more effort to the cleanup properly.
For example, I suspect the following are not real differences, and just redundancy in data structure
--- /home/ycp/source/mariadb-server/mdev-26151/repeats/rnd_next_internal.cc 2023-07-28 12:49:48.384561252 +1000
+++ /home/ycp/source/mariadb-server/mdev-26151/repeats/ft_read_internal.cc 2023-07-28 12:49:56.304500405 +1000
} else {
+ uint dbton_id = share->use_sql_dbton_ids[roop_count];
+ spider_db_handler *dbton_hdl = dbton_handler[dbton_id];
SPIDER_CONN *conn = conns[roop_count];
- ulong sql_type;
- sql_type= SPIDER_SQL_TYPE_SELECT_SQL;
I suspect share->use_sql_dbton_ids[roop_count] and conn->dbton_id are always the same value.
Another issues is the pattern in calls to spider_ping_table_mon_from_table(), and the patterns like the following in setup and teardown of queries
pthread_mutex_lock(&conn->mta_conn_mutex);
SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
conn->need_mon = &need_mons[roop_count];
DBUG_ASSERT(!conn->mta_conn_mutex_lock_already);
DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later);
conn->mta_conn_mutex_lock_already = TRUE;
conn->mta_conn_mutex_unlock_later = TRUE;
{
DBUG_ASSERT(conn->mta_conn_mutex_lock_already);
DBUG_ASSERT(conn->mta_conn_mutex_unlock_later);
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
pthread_mutex_unlock(&conn->mta_conn_mutex);
They come in variants (sometimes missing the set / clear file pos part, sometimes without assigning to conn->need_mon) and is scattered all around the codebase, and need a proper cleanup based on understanding (see also my previous attempt in
MDEV-29502https://github.com/MariaDB/server/commit/3b5cecbacd46ea8607b4e5379633e60a98d71bc5). Therefore we defer this ticket to later, maybe when relevant to another task