Commit 0b627377 authored by Yuchen Pei's avatar Yuchen Pei

MDEV-33661 MENT-1591 Documenting spider_mon_table_cache and friends.

Partial documentation due to time constraints. Will improve over time.

Also removed a redundant parameter link_idx from
spider_get_sys_tables_connect_info().

And deleted some commented out code.
parent fa1ae367
...@@ -307,7 +307,7 @@ int spider_udf_get_copy_tgt_tables( ...@@ -307,7 +307,7 @@ int spider_udf_get_copy_tgt_tables(
if ( if (
(error_num = spider_get_sys_tables_connect_info( (error_num = spider_get_sys_tables_connect_info(
table_tables, tmp_share, 0, mem_root)) || table_tables, tmp_share, mem_root)) ||
(error_num = spider_get_sys_tables_link_status( (error_num = spider_get_sys_tables_link_status(
table_tables, tmp_share, 0, mem_root)) || table_tables, tmp_share, 0, mem_root)) ||
(error_num = spider_get_sys_tables_link_idx( (error_num = spider_get_sys_tables_link_idx(
......
...@@ -1606,6 +1606,7 @@ typedef struct st_spider_table_mon ...@@ -1606,6 +1606,7 @@ typedef struct st_spider_table_mon
st_spider_table_mon *next; st_spider_table_mon *next;
} SPIDER_TABLE_MON; } SPIDER_TABLE_MON;
/* List of `SPIDER_TABLE_MON's */
typedef struct st_spider_table_mon_list typedef struct st_spider_table_mon_list
{ {
char *key; char *key;
......
...@@ -54,6 +54,8 @@ extern PSI_mutex_key spd_key_mutex_mon_list_update_status; ...@@ -54,6 +54,8 @@ extern PSI_mutex_key spd_key_mutex_mon_list_update_status;
extern PSI_mutex_key spd_key_mutex_mon_table_cache; extern PSI_mutex_key spd_key_mutex_mon_table_cache;
#endif #endif
/* Array (of size `spider_udf_table_mon_mutex_count') of hashes of
`SPIDER_TABLE_MON_LIST'. */
HASH *spider_udf_table_mon_list_hash; HASH *spider_udf_table_mon_list_hash;
uint spider_udf_table_mon_list_hash_id; uint spider_udf_table_mon_list_hash_id;
const char *spider_udf_table_mon_list_hash_func_name; const char *spider_udf_table_mon_list_hash_func_name;
...@@ -63,23 +65,43 @@ pthread_mutex_t *spider_udf_table_mon_mutexes; ...@@ -63,23 +65,43 @@ pthread_mutex_t *spider_udf_table_mon_mutexes;
pthread_cond_t *spider_udf_table_mon_conds; pthread_cond_t *spider_udf_table_mon_conds;
pthread_mutex_t spider_mon_table_cache_mutex; pthread_mutex_t spider_mon_table_cache_mutex;
/* A cache to store distinct SPIDER_MON_KEYs with db name, table name
and link id read from mysql.spider_link_mon_servers table. Initialised
and populated in spider_init_ping_table_mon_cache(), and used in
spider_ping_table_cache_compare(). The udf
spider_flush_table_mon_cache is used to flag a initialisation. */
DYNAMIC_ARRAY spider_mon_table_cache; DYNAMIC_ARRAY spider_mon_table_cache;
uint spider_mon_table_cache_id; uint spider_mon_table_cache_id;
const char *spider_mon_table_cache_func_name; const char *spider_mon_table_cache_func_name;
const char *spider_mon_table_cache_file_name; const char *spider_mon_table_cache_file_name;
ulong spider_mon_table_cache_line_no; ulong spider_mon_table_cache_line_no;
/* The mon table cache version, initialised at 0, and always no
greater than spider_mon_table_cache_version_req. When the inequality
is strict, an initialisation of spider_mon_table_cache will be
triggered. */
volatile ulonglong spider_mon_table_cache_version = 0; volatile ulonglong spider_mon_table_cache_version = 0;
/* The required mon table cache version, incremented by one by the
udf spider_flush_table_mon_cache */
volatile ulonglong spider_mon_table_cache_version_req = 1; volatile ulonglong spider_mon_table_cache_version_req = 1;
/* Get or create a `SPIDER_TABLE_MON_LIST' for a key `str' */
SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list(
SPIDER_TRX *trx, SPIDER_TRX *trx,
THD *thd, THD *thd,
spider_string *str, spider_string *str, /* The key to search in
`spider_udf_table_mon_list_hash',
usually in the format of
"./$db_name/$table_name000000000$link_idx" */
uint conv_name_length, uint conv_name_length,
int link_idx, int link_idx,
char *static_link_id, char *static_link_id,
uint static_link_id_length, uint static_link_id_length,
uint32 server_id, uint32 server_id, /* The server id of the monitor
server, used for creating a new
table mon list having a
`SPIDER_TABLE_MON' corresponding to
the server id as the `current'
field */
bool need_lock, bool need_lock,
int *error_num int *error_num
) { ) {
...@@ -91,6 +113,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( ...@@ -91,6 +113,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list(
my_hash_value_type hash_value; my_hash_value_type hash_value;
#endif #endif
DBUG_ENTER("spider_get_ping_table_mon_list"); DBUG_ENTER("spider_get_ping_table_mon_list");
/* Reset the cache if the version does not match the requirement */
if (spider_mon_table_cache_version != spider_mon_table_cache_version_req) if (spider_mon_table_cache_version != spider_mon_table_cache_version_req)
{ {
SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME));
...@@ -103,6 +126,9 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( ...@@ -103,6 +126,9 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list(
free_root(&mem_root, MYF(0)); free_root(&mem_root, MYF(0));
} }
/* Search for the table mon list in the hash, if one is not found or
if it is found but has the wrong cache version, create and
initialise a new one. */
mutex_hash = spider_udf_calc_hash(str->c_ptr(), mutex_hash = spider_udf_calc_hash(str->c_ptr(),
spider_param_udf_table_mon_mutex_count()); spider_param_udf_table_mon_mutex_count());
DBUG_PRINT("info",("spider hash key=%s", str->c_ptr())); DBUG_PRINT("info",("spider hash key=%s", str->c_ptr()));
...@@ -129,12 +155,15 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( ...@@ -129,12 +155,15 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list(
) )
#endif #endif
{ {
/* If table_mon_list is found but the cache version does not
match, remove it from the hash and free it. */
if ( if (
table_mon_list && table_mon_list &&
table_mon_list->mon_table_cache_version != mon_table_cache_version table_mon_list->mon_table_cache_version != mon_table_cache_version
) )
spider_release_ping_table_mon_list_loop(mutex_hash, table_mon_list); spider_release_ping_table_mon_list_loop(mutex_hash, table_mon_list);
/* create and initialise `table_mon_list' and insert it into the
hash */
if (!(table_mon_list = spider_get_ping_table_tgt(thd, str->c_ptr(), if (!(table_mon_list = spider_get_ping_table_tgt(thd, str->c_ptr(),
conv_name_length, link_idx, static_link_id, static_link_id_length, conv_name_length, link_idx, static_link_id, static_link_id_length,
server_id, str, need_lock, error_num))) server_id, str, need_lock, error_num)))
...@@ -277,6 +306,14 @@ int spider_release_ping_table_mon_list( ...@@ -277,6 +306,14 @@ int spider_release_ping_table_mon_list(
DBUG_RETURN(0); DBUG_RETURN(0);
} }
/*
Look for a `SPIDER_MON_KEY` in `spider_mon_table_cache' whose db and
table name and link_idx matching `name' and `link_idx' with wild
card matching. If a match is found, create `SPIDER_TABLE_MON's from
all rows in mysql.spider_link_mon_servers that match the info in the
`SPIDER_MON_KEY' and populate the `table_mon_list' with these
`SPIDER_TABLE_MON's.
*/
int spider_get_ping_table_mon( int spider_get_ping_table_mon(
THD *thd, THD *thd,
SPIDER_TABLE_MON_LIST *table_mon_list, SPIDER_TABLE_MON_LIST *table_mon_list,
...@@ -357,6 +394,8 @@ int spider_get_ping_table_mon( ...@@ -357,6 +394,8 @@ int spider_get_ping_table_mon(
goto error; goto error;
create_table_mon: create_table_mon:
/* Find the first row in mysql.spider_link_mon_servers matching the
db name, table name and link_idx */
if ((error_num = spider_get_sys_table_by_idx(table_link_mon, table_key, if ((error_num = spider_get_sys_table_by_idx(table_link_mon, table_key,
table_link_mon->s->primary_key, 3))) table_link_mon->s->primary_key, 3)))
{ {
...@@ -364,6 +403,9 @@ int spider_get_ping_table_mon( ...@@ -364,6 +403,9 @@ int spider_get_ping_table_mon(
goto error; goto error;
} }
/* create one `SPIDER_TABLE_MON' per row in
mysql.spider_link_mon_servers with matching db name, table name and
link_idx, and add it to `table_mon_list'. */
do { do {
if (!(table_mon = (SPIDER_TABLE_MON *) if (!(table_mon = (SPIDER_TABLE_MON *)
spider_bulk_malloc(spider_current_trx, SPD_MID_GET_PING_TABLE_MON_1, MYF(MY_WME | MY_ZEROFILL), spider_bulk_malloc(spider_current_trx, SPD_MID_GET_PING_TABLE_MON_1, MYF(MY_WME | MY_ZEROFILL),
...@@ -394,7 +436,7 @@ int spider_get_ping_table_mon( ...@@ -394,7 +436,7 @@ int spider_get_ping_table_mon(
(error_num = spider_get_sys_link_mon_server_id( (error_num = spider_get_sys_link_mon_server_id(
table_link_mon, &table_mon->server_id, mem_root)) || table_link_mon, &table_mon->server_id, mem_root)) ||
(error_num = spider_get_sys_link_mon_connect_info( (error_num = spider_get_sys_link_mon_connect_info(
table_link_mon, tmp_share, 0, mem_root)) table_link_mon, tmp_share, mem_root))
) { ) {
table_link_mon->file->print_error(error_num, MYF(0)); table_link_mon->file->print_error(error_num, MYF(0));
spider_sys_index_end(table_link_mon); spider_sys_index_end(table_link_mon);
...@@ -458,15 +500,21 @@ int spider_get_ping_table_mon( ...@@ -458,15 +500,21 @@ int spider_get_ping_table_mon(
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
/*
creates and return table_mon_list associated with table with `name'
and `link_idx'th link.
*/
SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt(
THD *thd, THD *thd,
char *name, char *name, /* The table name, usually fully qualified */
uint name_length, uint name_length,
int link_idx, int link_idx,
char *static_link_id, char *static_link_id,
uint static_link_id_length, uint static_link_id_length,
uint32 server_id, uint32 server_id, /* The server_id will determine the
spider_string *str, `current' field of the returned
`SPIDER_TABLE_MON_LIST'. */
spider_string *str, /* str->c_ptr() == name */
bool need_lock, bool need_lock,
int *error_num int *error_num
) { ) {
...@@ -511,6 +559,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( ...@@ -511,6 +559,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt(
memcpy(key_str, str->ptr(), table_mon_list->key_length); memcpy(key_str, str->ptr(), table_mon_list->key_length);
tmp_share->access_charset = thd->variables.character_set_client; tmp_share->access_charset = thd->variables.character_set_client;
/* Open mysql.spider_tables */
if ( if (
!(table_tables = spider_open_sys_table( !(table_tables = spider_open_sys_table(
thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
...@@ -520,6 +569,8 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( ...@@ -520,6 +569,8 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt(
my_error(*error_num, MYF(0)); my_error(*error_num, MYF(0));
goto error; goto error;
} }
/* store db and table names and link idx in mysql.spider_tables for
reading */
spider_store_tables_name(table_tables, name, name_length); spider_store_tables_name(table_tables, name, name_length);
if (static_link_id) if (static_link_id)
{ {
...@@ -543,9 +594,10 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( ...@@ -543,9 +594,10 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt(
goto error; goto error;
} }
} }
/* Populate tmp_share with info read from mysql.spider_tables */
if ( if (
(*error_num = spider_get_sys_tables_connect_info( (*error_num = spider_get_sys_tables_connect_info(
table_tables, tmp_share, 0, &mem_root)) || table_tables, tmp_share, &mem_root)) ||
(*error_num = spider_get_sys_tables_link_status( (*error_num = spider_get_sys_tables_link_status(
table_tables, tmp_share, 0, &mem_root)) table_tables, tmp_share, 0, &mem_root))
) { ) {
...@@ -569,9 +621,8 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( ...@@ -569,9 +621,8 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt(
tmp_share, name, name_length tmp_share, name, name_length
)) || )) ||
(*error_num = spider_create_conn_keys(tmp_share)) || (*error_num = spider_create_conn_keys(tmp_share)) ||
/* /* Pinally, populate `table_mon_list' with newly created
(*error_num = spider_db_create_table_names_str(tmp_share)) || `SPIDER_TABLE_MON's */
*/
(*error_num = spider_get_ping_table_mon( (*error_num = spider_get_ping_table_mon(
thd, table_mon_list, name, name_length, link_idx, server_id, &mem_root, thd, table_mon_list, name, name_length, link_idx, server_id, &mem_root,
need_lock)) need_lock))
...@@ -836,6 +887,11 @@ int spider_get_ping_table_gtid_pos( ...@@ -836,6 +887,11 @@ int spider_get_ping_table_gtid_pos(
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
/*
Initialise `spider_mon_table_cache' by scanning the
mysql.spider_link_mon_servers table, creating distinct
`SPIDER_MON_KEY's with the info and inserting them into the cache.
*/
int spider_init_ping_table_mon_cache( int spider_init_ping_table_mon_cache(
THD *thd, THD *thd,
MEM_ROOT *mem_root, MEM_ROOT *mem_root,
...@@ -867,6 +923,7 @@ int spider_init_ping_table_mon_cache( ...@@ -867,6 +923,7 @@ int spider_init_ping_table_mon_cache(
/* reset */ /* reset */
spider_mon_table_cache.elements = 0; spider_mon_table_cache.elements = 0;
/* start at the first row */
if ((error_num = spider_sys_index_first(table_link_mon, if ((error_num = spider_sys_index_first(table_link_mon,
table_link_mon->s->primary_key))) table_link_mon->s->primary_key)))
{ {
...@@ -883,10 +940,16 @@ int spider_init_ping_table_mon_cache( ...@@ -883,10 +940,16 @@ int spider_init_ping_table_mon_cache(
mon_key.table_name_length = SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE + 1; mon_key.table_name_length = SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE + 1;
mon_key.link_id_length = SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE + 1; mon_key.link_id_length = SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE + 1;
do { do {
/* update content of `mon_key' */
if ((error_num = spider_get_sys_link_mon_key(table_link_mon, &mon_key, if ((error_num = spider_get_sys_link_mon_key(table_link_mon, &mon_key,
mem_root, &same))) mem_root, &same)))
goto error_get_sys_link_mon_key; goto error_get_sys_link_mon_key;
/* `mon_key' has changed content. since
mysql.spider_link_mon_servers is indexed by db_name,
table_name, link_idx, and server_id, it is possible that
different server_ids share the same mon_key which only has
db_name, table_name, link_idx */
if (!same) if (!same)
{ {
mon_key.sort = spider_calc_for_sort(3, mon_key.db_name, mon_key.sort = spider_calc_for_sort(3, mon_key.db_name,
...@@ -941,6 +1004,13 @@ int spider_init_ping_table_mon_cache( ...@@ -941,6 +1004,13 @@ int spider_init_ping_table_mon_cache(
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
/*
Read from msyql.spider_link_mon_servers table fields the db name,
table name and link_id and search for them with wild card matching
in `spider_mon_table_cache'. store the db name, table name, and
link_id of the matching `SPIDER_MON_KEY' back to the table field on
success.
*/
int spider_ping_table_cache_compare( int spider_ping_table_cache_compare(
TABLE *table, TABLE *table,
MEM_ROOT *mem_root MEM_ROOT *mem_root
...@@ -1239,9 +1309,6 @@ long long spider_ping_table_body( ...@@ -1239,9 +1309,6 @@ long long spider_ping_table_body(
DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 2")); DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 2"));
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{ {
/*
pthread_mutex_lock(&table_mon_list->update_status_mutex);
*/
pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{ {
...@@ -1256,9 +1323,6 @@ long long spider_ping_table_body( ...@@ -1256,9 +1323,6 @@ long long spider_ping_table_body(
conv_name.c_ptr(), conv_name_length, link_idx, TRUE); conv_name.c_ptr(), conv_name_length, link_idx, TRUE);
status_changed_to_ng = TRUE; status_changed_to_ng = TRUE;
} }
/*
pthread_mutex_unlock(&table_mon_list->update_status_mutex);
*/
pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (status_changed_to_ng) if (status_changed_to_ng)
{ {
...@@ -1312,9 +1376,6 @@ long long spider_ping_table_body( ...@@ -1312,9 +1376,6 @@ long long spider_ping_table_body(
DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 3")); DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 3"));
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{ {
/*
pthread_mutex_lock(&table_mon_list->update_status_mutex);
*/
pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{ {
...@@ -1329,9 +1390,6 @@ long long spider_ping_table_body( ...@@ -1329,9 +1390,6 @@ long long spider_ping_table_body(
conv_name.c_ptr(), conv_name_length, link_idx, TRUE); conv_name.c_ptr(), conv_name_length, link_idx, TRUE);
status_changed_to_ng = TRUE; status_changed_to_ng = TRUE;
} }
/*
pthread_mutex_unlock(&table_mon_list->update_status_mutex);
*/
pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (status_changed_to_ng) if (status_changed_to_ng)
{ {
...@@ -1375,9 +1433,6 @@ long long spider_ping_table_body( ...@@ -1375,9 +1433,6 @@ long long spider_ping_table_body(
mon_table_result->result_status == SPIDER_LINK_MON_NG && mon_table_result->result_status == SPIDER_LINK_MON_NG &&
table_mon_list->mon_status != SPIDER_LINK_MON_NG table_mon_list->mon_status != SPIDER_LINK_MON_NG
) { ) {
/*
pthread_mutex_lock(&table_mon_list->update_status_mutex);
*/
pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{ {
...@@ -1392,9 +1447,6 @@ long long spider_ping_table_body( ...@@ -1392,9 +1447,6 @@ long long spider_ping_table_body(
conv_name.c_ptr(), conv_name_length, link_idx, TRUE); conv_name.c_ptr(), conv_name_length, link_idx, TRUE);
status_changed_to_ng = TRUE; status_changed_to_ng = TRUE;
} }
/*
pthread_mutex_unlock(&table_mon_list->update_status_mutex);
*/
pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (status_changed_to_ng) if (status_changed_to_ng)
{ {
...@@ -1565,9 +1617,9 @@ int spider_ping_table_mon_from_table( ...@@ -1565,9 +1617,9 @@ int spider_ping_table_mon_from_table(
SPIDER_SHARE *share, SPIDER_SHARE *share,
int base_link_idx, int base_link_idx,
uint32 server_id, uint32 server_id,
char *conv_name, char *conv_name, /* Usually fully qualified table name */
uint conv_name_length, uint conv_name_length,
int link_idx, int link_idx, /* The link id to ping */
char *where_clause, char *where_clause,
uint where_clause_length, uint where_clause_length,
long monitoring_kind, long monitoring_kind,
...@@ -1577,9 +1629,6 @@ int spider_ping_table_mon_from_table( ...@@ -1577,9 +1629,6 @@ int spider_ping_table_mon_from_table(
) { ) {
int error_num = 0, current_mon_count, flags; int error_num = 0, current_mon_count, flags;
uint32 first_sid; uint32 first_sid;
/*
THD *thd = trx->thd;
*/
SPIDER_TABLE_MON_LIST *table_mon_list; SPIDER_TABLE_MON_LIST *table_mon_list;
SPIDER_TABLE_MON *table_mon; SPIDER_TABLE_MON *table_mon;
SPIDER_MON_TABLE_RESULT mon_table_result; SPIDER_MON_TABLE_RESULT mon_table_result;
...@@ -1648,6 +1697,7 @@ int spider_ping_table_mon_from_table( ...@@ -1648,6 +1697,7 @@ int spider_ping_table_mon_from_table(
if (monitoring_flag & 1) if (monitoring_flag & 1)
flags |= SPIDER_UDF_PING_TABLE_USE_ALL_MONITORING_NODES; flags |= SPIDER_UDF_PING_TABLE_USE_ALL_MONITORING_NODES;
/* Get or create `table_mon_list' for `conv_name_str'. */
if (!(table_mon_list = spider_get_ping_table_mon_list(trx, thd, if (!(table_mon_list = spider_get_ping_table_mon_list(trx, thd,
&conv_name_str, conv_name_length, link_idx, &conv_name_str, conv_name_length, link_idx,
share->static_link_ids[link_idx], share->static_link_ids[link_idx],
...@@ -1679,6 +1729,8 @@ int spider_ping_table_mon_from_table( ...@@ -1679,6 +1729,8 @@ int spider_ping_table_mon_from_table(
table_mon = table_mon_list->current; table_mon = table_mon_list->current;
first_sid = table_mon->server_id; first_sid = table_mon->server_id;
current_mon_count = 1; current_mon_count = 1;
/* Call spider_ping_table on each table_mon of `table_mon_list',
until one succeeds */
while (TRUE) while (TRUE)
{ {
DBUG_PRINT("info",("spider thd->killed=%s", DBUG_PRINT("info",("spider thd->killed=%s",
...@@ -1723,16 +1775,13 @@ int spider_ping_table_mon_from_table( ...@@ -1723,16 +1775,13 @@ int spider_ping_table_mon_from_table(
if (!spider_db_udf_ping_table_mon_next( if (!spider_db_udf_ping_table_mon_next(
thd, table_mon, mon_conn, &mon_table_result, conv_name, thd, table_mon, mon_conn, &mon_table_result, conv_name,
conv_name_length, link_idx, conv_name_length, link_idx,
where_clause, where_clause_length, -1, table_mon_list->list_size, where_clause, where_clause_length, /*first_sid=*/-1, table_mon_list->list_size,
0, 0, 0, flags, monitoring_limit)) 0, 0, 0, flags, monitoring_limit))
{ {
if ( if (
mon_table_result.result_status == SPIDER_LINK_MON_NG && mon_table_result.result_status == SPIDER_LINK_MON_NG &&
table_mon_list->mon_status != SPIDER_LINK_MON_NG table_mon_list->mon_status != SPIDER_LINK_MON_NG
) { ) {
/*
pthread_mutex_lock(&table_mon_list->update_status_mutex);
*/
pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{ {
...@@ -1747,9 +1796,6 @@ int spider_ping_table_mon_from_table( ...@@ -1747,9 +1796,6 @@ int spider_ping_table_mon_from_table(
spider_sys_log_tables_link_failed(thd, conv_name, spider_sys_log_tables_link_failed(thd, conv_name,
conv_name_length, link_idx, need_lock); conv_name_length, link_idx, need_lock);
} }
/*
pthread_mutex_unlock(&table_mon_list->update_status_mutex);
*/
pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
} }
table_mon_list->last_caller_result = mon_table_result.result_status; table_mon_list->last_caller_result = mon_table_result.result_status;
......
...@@ -570,6 +570,11 @@ int spider_check_sys_table_for_update_all_columns( ...@@ -570,6 +570,11 @@ int spider_check_sys_table_for_update_all_columns(
#endif #endif
} }
/*
Creates a key (`table_key') consisting of `col_count' key parts of
`idx'th index of the table, then positions an index cursor to that
key.
*/
int spider_get_sys_table_by_idx( int spider_get_sys_table_by_idx(
TABLE *table, TABLE *table,
char *table_key, char *table_key,
...@@ -602,17 +607,6 @@ int spider_get_sys_table_by_idx( ...@@ -602,17 +607,6 @@ int spider_get_sys_table_by_idx(
key_length); key_length);
if ( if (
/*
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
(error_num = table->file->ha_index_read_idx_map(
table->record[0], idx, (uchar *) table_key,
make_prev_keypart_map(col_count), HA_READ_KEY_EXACT))
#else
(error_num = table->file->index_read_idx_map(
table->record[0], idx, (uchar *) table_key,
make_prev_keypart_map(col_count), HA_READ_KEY_EXACT))
#endif
*/
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
(error_num = table->file->ha_index_read_map( (error_num = table->file->ha_index_read_map(
table->record[0], (uchar *) table_key, table->record[0], (uchar *) table_key,
...@@ -649,7 +643,7 @@ int spider_sys_index_next_same( ...@@ -649,7 +643,7 @@ int spider_sys_index_next_same(
int spider_sys_index_first( int spider_sys_index_first(
TABLE *table, TABLE *table,
const int idx const int idx /* which index to use */
) { ) {
int error_num; int error_num;
DBUG_ENTER("spider_sys_index_first"); DBUG_ENTER("spider_sys_index_first");
...@@ -870,6 +864,10 @@ void spider_store_xa_member_info( ...@@ -870,6 +864,10 @@ void spider_store_xa_member_info(
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/*
Store db and table names from `name' to `table's corresponding
fields
*/
void spider_store_tables_name( void spider_store_tables_name(
TABLE *table, TABLE *table,
const char *name, const char *name,
...@@ -2064,14 +2062,16 @@ int spider_get_sys_tables( ...@@ -2064,14 +2062,16 @@ int spider_get_sys_tables(
DBUG_RETURN(0); DBUG_RETURN(0);
} }
/* Read table info from mysql.spider_tables into a `SPIDER_SHARE' */
int spider_get_sys_tables_connect_info( int spider_get_sys_tables_connect_info(
TABLE *table, TABLE *table, /* The mysql.spider_tables table */
SPIDER_SHARE *share, SPIDER_SHARE *share, /* The `SPIDER_SHARE' to
int link_idx, update info */
MEM_ROOT *mem_root MEM_ROOT *mem_root
) { ) {
char *ptr; char *ptr;
int error_num = 0; int error_num = 0;
const int link_idx= 0;
DBUG_ENTER("spider_get_sys_tables_connect_info"); DBUG_ENTER("spider_get_sys_tables_connect_info");
if ((ptr = get_field(mem_root, table->field[3]))) if ((ptr = get_field(mem_root, table->field[3])))
{ {
...@@ -2297,9 +2297,14 @@ int spider_get_sys_tables_monitoring_binlog_pos_at_failing( ...@@ -2297,9 +2297,14 @@ int spider_get_sys_tables_monitoring_binlog_pos_at_failing(
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
/*
Read the link status from mysql.spider_tables into a `SPIDER_SHARE'
with default value 1 (`SPIDER_LINK_STATUS_OK')
*/
int spider_get_sys_tables_link_status( int spider_get_sys_tables_link_status(
TABLE *table, TABLE *table, /* The mysql.spider_tables table */
SPIDER_SHARE *share, SPIDER_SHARE *share, /* The share to read link
status into */
int link_idx, int link_idx,
MEM_ROOT *mem_root MEM_ROOT *mem_root
) { ) {
...@@ -2484,11 +2489,17 @@ int spider_sys_log_xa_failed( ...@@ -2484,11 +2489,17 @@ int spider_sys_log_xa_failed(
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
/* Populate `mon_key' from the current row in `table' */
int spider_get_sys_link_mon_key( int spider_get_sys_link_mon_key(
TABLE *table, TABLE *table, /* the mysql.spider_link_mon_servers
SPIDER_MON_KEY *mon_key, table */
SPIDER_MON_KEY *mon_key, /* output, to be populated in this
function */
MEM_ROOT *mem_root, MEM_ROOT *mem_root,
int *same int *same /* output, true if the data from the
current row in the table agrees with
existing data in `mon_key' and false
otherwise */
) { ) {
char *db_name, *table_name, *link_id; char *db_name, *table_name, *link_id;
uint db_name_length, table_name_length, link_id_length; uint db_name_length, table_name_length, link_id_length;
...@@ -2504,6 +2515,7 @@ int spider_get_sys_link_mon_key( ...@@ -2504,6 +2515,7 @@ int spider_get_sys_link_mon_key(
DBUG_RETURN(ER_SPIDER_SYS_TABLE_VERSION_NUM); DBUG_RETURN(ER_SPIDER_SYS_TABLE_VERSION_NUM);
} }
/* get data for `mon_key' from the table record */
if (!(db_name = get_field(mem_root, table->field[0]))) if (!(db_name = get_field(mem_root, table->field[0])))
DBUG_RETURN(HA_ERR_OUT_OF_MEM); DBUG_RETURN(HA_ERR_OUT_OF_MEM);
if (!(table_name = get_field(mem_root, table->field[1]))) if (!(table_name = get_field(mem_root, table->field[1])))
...@@ -2549,9 +2561,12 @@ int spider_get_sys_link_mon_key( ...@@ -2549,9 +2561,12 @@ int spider_get_sys_link_mon_key(
DBUG_RETURN(0); DBUG_RETURN(0);
} }
/* Get the server id from the spider_link_mon_servers table field */
int spider_get_sys_link_mon_server_id( int spider_get_sys_link_mon_server_id(
TABLE *table, TABLE *table, /* the
uint32 *server_id, mysql.spider_link_mon_servers
table */
uint32 *server_id, /* output to server_id */
MEM_ROOT *mem_root MEM_ROOT *mem_root
) { ) {
char *ptr; char *ptr;
...@@ -2564,14 +2579,17 @@ int spider_get_sys_link_mon_server_id( ...@@ -2564,14 +2579,17 @@ int spider_get_sys_link_mon_server_id(
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
/* Get connect info from the spider_link_mon_servers table fields */
int spider_get_sys_link_mon_connect_info( int spider_get_sys_link_mon_connect_info(
TABLE *table, TABLE *table, /* The
SPIDER_SHARE *share, mysql.spider_link_mon_servers
int link_idx, table */
SPIDER_SHARE *share, /* The output spider_share */
MEM_ROOT *mem_root MEM_ROOT *mem_root
) { ) {
char *ptr; char *ptr;
int error_num = 0; int error_num = 0;
const int link_idx= 0;
DBUG_ENTER("spider_get_sys_link_mon_connect_info"); DBUG_ENTER("spider_get_sys_link_mon_connect_info");
if ( if (
!table->field[4]->is_null() && !table->field[4]->is_null() &&
...@@ -2753,9 +2771,6 @@ int spider_get_link_statuses( ...@@ -2753,9 +2771,6 @@ int spider_get_link_statuses(
if ( if (
(error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE) (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE)
) { ) {
/*
table->file->print_error(error_num, MYF(0));
*/
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
} else if ((error_num = } else if ((error_num =
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#define SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE 64 #define SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE 64
#define SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE 64 #define SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE 64
/* For insertion into `spider_mon_table_cache'. */
class SPIDER_MON_KEY: public SPIDER_SORT class SPIDER_MON_KEY: public SPIDER_SORT
{ {
public: public:
...@@ -425,7 +426,6 @@ int spider_get_sys_tables( ...@@ -425,7 +426,6 @@ int spider_get_sys_tables(
int spider_get_sys_tables_connect_info( int spider_get_sys_tables_connect_info(
TABLE *table, TABLE *table,
SPIDER_SHARE *share, SPIDER_SHARE *share,
int link_idx,
MEM_ROOT *mem_root MEM_ROOT *mem_root
); );
...@@ -502,7 +502,6 @@ int spider_get_sys_link_mon_server_id( ...@@ -502,7 +502,6 @@ int spider_get_sys_link_mon_server_id(
int spider_get_sys_link_mon_connect_info( int spider_get_sys_link_mon_connect_info(
TABLE *table, TABLE *table,
SPIDER_SHARE *share, SPIDER_SHARE *share,
int link_idx,
MEM_ROOT *mem_root MEM_ROOT *mem_root
); );
......
...@@ -3421,13 +3421,15 @@ int spider_parse_connect_info( ...@@ -3421,13 +3421,15 @@ int spider_parse_connect_info(
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
/* Set default connect info of a SPIDER_SHARE if needed */
int spider_set_connect_info_default( int spider_set_connect_info_default(
SPIDER_SHARE *share, SPIDER_SHARE *share, /* The `SPIDER_SHARE' to set
default connect info */
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
partition_element *part_elem, partition_element *part_elem, /* partition info used as input */
partition_element *sub_elem, partition_element *sub_elem, /* subpartition info used as input */
#endif #endif
TABLE_SHARE *table_share TABLE_SHARE *table_share /* table share info used as input */
) { ) {
int error_num, roop_count; int error_num, roop_count;
DBUG_ENTER("spider_set_connect_info_default"); DBUG_ENTER("spider_set_connect_info_default");
...@@ -3558,22 +3560,6 @@ int spider_set_connect_info_default( ...@@ -3558,22 +3560,6 @@ int spider_set_connect_info_default(
} }
} }
/*
if (!share->static_link_ids[roop_count])
{
DBUG_PRINT("info",("spider create default static_link_ids"));
share->static_link_ids_lengths[roop_count] =
SPIDER_DB_STATIC_LINK_ID_LEN;
if (
!(share->static_link_ids[roop_count] = spider_create_string(
SPIDER_DB_STATIC_LINK_ID_STR,
share->static_link_ids_lengths[roop_count]))
) {
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
}
*/
if (share->tgt_ports[roop_count] == -1) if (share->tgt_ports[roop_count] == -1)
{ {
share->tgt_ports[roop_count] = MYSQL_PORT; share->tgt_ports[roop_count] = MYSQL_PORT;
...@@ -3705,6 +3691,11 @@ int spider_set_connect_info_default( ...@@ -3705,6 +3691,11 @@ int spider_set_connect_info_default(
DBUG_RETURN(0); DBUG_RETURN(0);
} }
/*
This function is a no-op if all share->tgt_dbs and
share->tgt_table_names are non-null, otherwise it may assign them
with db_name and table_name
*/
int spider_set_connect_info_default_db_table( int spider_set_connect_info_default_db_table(
SPIDER_SHARE *share, SPIDER_SHARE *share,
const char *db_name, const char *db_name,
...@@ -3748,6 +3739,11 @@ int spider_set_connect_info_default_db_table( ...@@ -3748,6 +3739,11 @@ int spider_set_connect_info_default_db_table(
DBUG_RETURN(0); DBUG_RETURN(0);
} }
/*
Parse `dbtable_name' into db name and table name, and call
spider_set_connect_info_default_db_table() to set the db/table name
values of `share' if needed
*/
int spider_set_connect_info_default_dbtable( int spider_set_connect_info_default_dbtable(
SPIDER_SHARE *share, SPIDER_SHARE *share,
const char *dbtable_name, const char *dbtable_name,
...@@ -6062,7 +6058,7 @@ int spider_open_all_tables( ...@@ -6062,7 +6058,7 @@ int spider_open_all_tables(
(error_num = spider_get_sys_tables( (error_num = spider_get_sys_tables(
table_tables, &db_name, &table_name, &mem_root)) || table_tables, &db_name, &table_name, &mem_root)) ||
(error_num = spider_get_sys_tables_connect_info( (error_num = spider_get_sys_tables_connect_info(
table_tables, &tmp_share, 0, &mem_root)) || table_tables, &tmp_share, &mem_root)) ||
(error_num = spider_set_connect_info_default( (error_num = spider_set_connect_info_default(
&tmp_share, &tmp_share,
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
...@@ -6676,16 +6672,6 @@ int spider_db_init( ...@@ -6676,16 +6672,6 @@ int spider_db_init(
#ifdef HTON_CAN_READ_CONNECT_STRING_IN_PARTITION #ifdef HTON_CAN_READ_CONNECT_STRING_IN_PARTITION
spider_hton->flags |= HTON_CAN_READ_CONNECT_STRING_IN_PARTITION; spider_hton->flags |= HTON_CAN_READ_CONNECT_STRING_IN_PARTITION;
#endif #endif
/* spider_hton->db_type = DB_TYPE_SPIDER; */
/*
spider_hton->savepoint_offset;
spider_hton->savepoint_set = spider_savepoint_set;
spider_hton->savepoint_rollback = spider_savepoint_rollback;
spider_hton->savepoint_release = spider_savepoint_release;
spider_hton->create_cursor_read_view = spider_create_cursor_read_view;
spider_hton->set_cursor_read_view = spider_set_cursor_read_view;
spider_hton->close_cursor_read_view = spider_close_cursor_read_view;
*/
spider_hton->panic = spider_panic; spider_hton->panic = spider_panic;
spider_hton->close_connection = spider_close_connection; spider_hton->close_connection = spider_close_connection;
spider_hton->start_consistent_snapshot = spider_start_consistent_snapshot; spider_hton->start_consistent_snapshot = spider_start_consistent_snapshot;
......
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