Commit 653050ac authored by Yuchen Pei's avatar Yuchen Pei

MDEV-32492 MDEV-29676 Spider: some code documentation and cleanup

Some documentations come from commit for MDEV-29676, and the rest are
mainly related to SPIDER_TRX_HA.

Removed SPIDER_TRX_HA::trx as it is unused.
parent 26192a46
......@@ -67,8 +67,10 @@ class ha_spider final : public handler
char *conn_keys_first_ptr;
char **conn_keys;
SPIDER_CONN **conns;
/* for active-standby mode */
/* array of indexes of active servers */
uint *conn_link_idx;
/* A bitmap indicating whether each active server have some higher
numbered server in the same "group" left to try (can fail over) */
uchar *conn_can_fo;
void **quick_targets;
int *need_mons;
......
......@@ -3958,6 +3958,24 @@ void *spider_bg_mon_action(
}
#endif
/**
Returns a random (active) server with a maximum required link status
Calculate the sum of balances of all servers whose link status is at
most the specified status ("eligible"), generate a random number
less than this balance, then find the first server cumulatively
exceeding this balance
@param thd Connection used for generating a random number
@param link_statuses The link statuses of servers
@param access_balances The access balances of servers
@param conn_link_idx Array of indexes to servers
@param link_count Number of servers
@param link_status The maximum required link status
@retval Index to the found server
@retval -1 if no eligible servers
@retval -2 if out of memory
*/
int spider_conn_first_link_idx(
THD *thd,
long *link_statuses,
......@@ -4053,6 +4071,17 @@ int spider_conn_next_link_idx(
DBUG_RETURN(tmp_link_idx);
}
/**
Finds the next active server with a maximum required link status
@param link_statuses The statuses of servers
@param conn_link_idx The array of active servers
@param link_idx The index of the current active server
@param link_count The number of active servers
@param link_status The required maximum link status
@return The next active server whose link status is
at most the required one.
*/
int spider_conn_link_idx_next(
long *link_statuses,
uint *conn_link_idx,
......@@ -4065,6 +4094,8 @@ int spider_conn_link_idx_next(
link_idx++;
if (link_idx >= link_count)
break;
/* Asserts that the `link_idx`th active server is in the correct
"group" */
DBUG_ASSERT((conn_link_idx[link_idx] - link_idx) % link_count == 0);
} while (link_statuses[conn_link_idx[link_idx]] > link_status);
DBUG_PRINT("info",("spider link_idx=%d", link_idx));
......
......@@ -1023,15 +1023,24 @@ typedef struct st_spider_share
char *table_name;
uint table_name_length;
uint use_count;
/**
Probably equals `active_link_count`. See also commit ddff602 of
https://github.com/nayuta-yanagisawa/spider-history
FIXME: consider removing it and using `active_link_count` instead.
*/
uint link_count;
/* Number of all links, i.e. all remote servers for the spider
table. */
uint all_link_count;
/*
The bitmap size of ha_spider::conn_can_fo, where the ha_spider
is the one `this' associates with (i.e. spider->share == this)
*/
uint link_bitmap_size;
pthread_mutex_t mutex;
pthread_mutex_t sts_mutex;
pthread_mutex_t crd_mutex;
/*
pthread_mutex_t auto_increment_mutex;
*/
TABLE_SHARE *table_share;
SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
......@@ -1574,16 +1583,42 @@ class SPIDER_SORT
ulong sort;
};
/*
A SPIDER_TRX_HA contains the HA information of a spider table or
partition.
Each SPIDER_TRX_HA is stored in a hash belonging to a SPIDER_TRX
i.e. its trx_ha_hash field.
It thus may have a different lifespan from the ha_spider or
SPIDER_SHARE associated with the same spider table/partition.
*/
typedef struct st_spider_trx_ha
{
/*
A fully qualified table name, used as the key in
SPIDER_TRX::trx_ha_hash
*/
char *table_name;
uint table_name_length;
SPIDER_TRX *trx;
/*
The associated SPIDER_SHARE. Will be used to check against a
given SPIDER_SHARE
*/
SPIDER_SHARE *share;
/*
link_count and link_bitmap_size are read from and checked against
the corresponding fields of the associated SPIDER_SHARE.
*/
uint link_count;
uint link_bitmap_size;
/*
conn_link_idx and conn_can_fo are read from and written to the
corresponding fields of the associated ha_spider.
*/
uint *conn_link_idx;
uchar *conn_can_fo;
/* TODO: document */
bool wait_for_reusing;
} SPIDER_TRX_HA;
......
......@@ -3767,6 +3767,13 @@ void spider_free_tmp_thd(
DBUG_VOID_RETURN;
}
/*
Check the info of a given SPIDER_TRX_HA with spider->share. If it
does not match or if the given SPIDER_TRX_HA is NULL, then create a
new one from spider and spider->share, and add the new SPIDER_TRX_HA
to trx->trx_ha_hash. On mismatch and non-NULL trx_ha, then it will
be removed from the hash and freed before the creation of a new one.
*/
int spider_create_trx_ha(
SPIDER_TRX *trx,
ha_spider *spider,
......@@ -3817,7 +3824,6 @@ int spider_create_trx_ha(
memcpy(trx_ha->table_name, share->table_name, share->table_name_length);
trx_ha->table_name[share->table_name_length] = '\0';
trx_ha->table_name_length = share->table_name_length;
trx_ha->trx = trx;
trx_ha->share = share;
trx_ha->link_count = share->link_count;
trx_ha->link_bitmap_size = share->link_bitmap_size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment