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;
......
This diff is collapsed.
...@@ -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