Skip to content

Commit

Permalink
MDEV-27902 Some Spider code documentation regarding first_link_idx an…
Browse files Browse the repository at this point in the history
…d remote HANDLER commands
  • Loading branch information
mariadb-YuchenPei committed Jul 16, 2024
1 parent 14c4050 commit 85a3695
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
19 changes: 19 additions & 0 deletions storage/spider/ha_spider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12918,6 +12918,15 @@ void ha_spider::sync_from_clone_source_base(
DBUG_VOID_RETURN;
}

/*
Set the initial values for each dbton_handler's first_link_idx and
strict_group_by.

First, reset first_link_idx to -1.
Then, for each active remote server, if the corresponding
dbton_handler has not been set yet (first_link_idx == -1), set its
first_link_idx to be the index of the connection.
*/
void ha_spider::set_first_link_idx()
{
int roop_count, all_link_idx;
Expand Down Expand Up @@ -12957,6 +12966,16 @@ void ha_spider::set_first_link_idx()
DBUG_VOID_RETURN;
}

/*
Reset the initial values for each dbton_handler's first_link_idx to
-1.

Also, set the search_link_idx'th active server's first_link_idx to
search_link_idx.

search_link_idx is commonly randomly set using
spider_conn_first_link_idx - see the commentary of that function.
*/
void ha_spider::reset_first_link_idx()
{
int all_link_idx;
Expand Down
6 changes: 6 additions & 0 deletions storage/spider/ha_spider.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ class ha_spider final : public handler
ulonglong *db_request_id;
uchar *db_request_phase;
uchar *m_handler_opened;
/* ids for use in HANDLER command */
uint *m_handler_id;
/*
aliases for use in HANDLER command, in the format of t%5u on
m_handler_id. So for example, if m_handler_id is 3, then the
corresponding m_handler_cid is t00003
*/
char **m_handler_cid;
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
bool do_direct_update;
Expand Down
1 change: 1 addition & 0 deletions storage/spider/spd_db_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,7 @@ class spider_db_handler
uint dbton_id;
ha_spider *spider;
spider_db_share *db_share;
/* Index of active server, used in query construction. */
int first_link_idx;
bool strict_group_by= false;
bool no_where_cond= false;
Expand Down
9 changes: 9 additions & 0 deletions storage/spider/spd_trx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3933,6 +3933,15 @@ void spider_reuse_trx_ha(
DBUG_VOID_RETURN;
}

/**
Sets link indices for load balancing read connections
Assuming `spider->share->link_count` is the number of active servers
to use, this function updates `spider->conn_link_idx` with the first
server in the same "modulus group" whose link status is not
`SPIDER_LINK_STATUS_NG`, or if one cannot be found, use the
`link_idx`th server
*/
void spider_trx_set_link_idx_for_all(
ha_spider *spider
) {
Expand Down

0 comments on commit 85a3695

Please sign in to comment.