[root@bj2-mysql-huoyun-prod-01 data]# mysql -uroot -p -S /data/mysql_3310/run/mysql.sock Enter password: Welcome to the MySQL monitor. Commands endwith ; or \g. Your MySQL connection id is 126072 Server version: 8.0.22-13 Percona Server (GPL), Release13, Revision 6f7822f
Copyright (c) 2009-2020 Percona LLC and/or its affiliates Copyright (c) 2000, 2020, Oracleand/or its affiliates. All rights reserved.
Oracleis a registered trademark ofOracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type'help;'or'\h'for help. Type'\c'toclear the currentinput statement.
CREATEFUNCTION gr_applier_queue_length() RETURNSINT DETERMINISTIC BEGIN RETURN (SELECT sys.gtid_count( GTID_SUBTRACT( (SELECT Received_transaction_set FROM performance_schema.replication_connection_status WHERE Channel_name = 'group_replication_applier' ), (SELECT @@global.GTID_EXECUTED) ))); END$$
CREATEFUNCTION gr_member_in_primary_partition() RETURNSVARCHAR(3) DETERMINISTIC BEGIN RETURN (SELECTIF( MEMBER_STATE='ONLINE'AND ((SELECTCOUNT(*) FROM performance_schema.replication_group_members WHERE MEMBER_STATE != 'ONLINE') >= ((SELECTCOUNT(*) FROM performance_schema.replication_group_members)/2) = 0), 'YES', 'NO' ) FROM performance_schema.replication_group_members JOIN performance_schema.replication_group_member_stats rgms USING(member_id) WHERE rgms.MEMBER_ID=@@SERVER_UUID ) ; END$$
CREATEFUNCTION gr_transactions_to_cert() RETURNSint(11) DETERMINISTIC BEGIN RETURN (select performance_schema.replication_group_member_stats.COUNT_TRANSACTIONS_IN_QUEUE AS transactions_to_cert FROM performance_schema.replication_group_member_stats where MEMBER_ID=@@SERVER_UUID ); END$$
CREATEVIEW gr_member_routing_candidate_status AS SELECT IFNULL(sys.gr_member_in_primary_partition(),'NO') AS viable_candidate, IF((SELECT ((SELECT GROUP_CONCAT(performance_schema.global_variables.VARIABLE_VALUE SEPARATOR ',') FROM performance_schema.global_variables WHERE (performance_schema.global_variables.VARIABLE_NAME IN ('read_only' , 'super_read_only'))) <> 'OFF,OFF') ), 'YES', 'NO') AS read_only, IFNULL(sys.gr_applier_queue_length(),0) AS transactions_behind, IFNULL(sys.gr_transactions_to_cert(),0) AS transactions_to_cert;$$
SET @TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN; SET @@SESSION.SQL_LOG_BIN= 0; SET @TEMP_READ_ONLY = @@GLOBAL.READ_ONLY; SET @TEMP_SUPER_READ_ONLY = @@GLOBAL.SUPER_READ_ONLY; SET @@GLOBAL.READ_ONLY = 0; USEsys;
CREATEFUNCTION GTID_COUNT(gtid_set TEXT(10000)) RETURNSINT DETERMINISTIC BEGIN DECLAREresultBIGINTDEFAULT0; DECLARE colon_pos INT; DECLARE next_dash_pos INT; DECLARE next_colon_pos INT; DECLARE next_comma_pos INT; SET gtid_set = GTID_NORMALIZE(gtid_set); SET colon_pos = LOCATE2(':', gtid_set, 1); WHILE colon_pos != LENGTH(gtid_set) + 1 DO SET next_dash_pos = LOCATE2('-', gtid_set, colon_pos + 1); SET next_colon_pos = LOCATE2(':', gtid_set, colon_pos + 1); SET next_comma_pos = LOCATE2(',', gtid_set, colon_pos + 1); IF next_dash_pos < next_colon_pos AND next_dash_pos < next_comma_pos THEN SETresult = result + SUBSTR(gtid_set, next_dash_pos + 1, LEAST(next_colon_pos, next_comma_pos) - (next_dash_pos + 1)) - SUBSTR(gtid_set, colon_pos + 1, next_dash_pos - (colon_pos + 1)) + 1; ELSE SETresult = result + 1; ENDIF; SET colon_pos = next_colon_pos; ENDWHILE; RETURN result; END$$
CREATEFUNCTION gr_applier_queue_length() RETURNSINT DETERMINISTIC BEGIN RETURN (SELECT sys.gtid_count( GTID_SUBTRACT( (SELECT Received_transaction_set FROM performance_schema.replication_connection_status WHERE Channel_name = 'group_replication_applier' ), (SELECT @@global.GTID_EXECUTED) ))); END$$
CREATEFUNCTION gr_transactions_to_cert() RETURNSint(11) DETERMINISTIC BEGIN RETURN (select performance_schema.replication_group_member_stats.COUNT_TRANSACTIONS_IN_QUEUE AS transactions_to_cert FROM performance_schema.replication_group_member_stats where MEMBER_ID=@@SERVER_UUID ); END$$
CREATEFUNCTION my_server_uuid() RETURNSTEXT(36) DETERMINISTICNOSQLRETURN (SELECT @@global.server_uuid as my_id);$$
CREATEVIEW gr_member_routing_candidate_status AS SELECT IFNULL((SELECT IF(MEMBER_STATE = 'ONLINE' AND ((SELECT COUNT(*) FROM performance_schema.replication_group_members WHERE MEMBER_STATE != 'ONLINE') >= ((SELECT COUNT(*) FROM performance_schema.replication_group_members) / 2) = 0), 'YES', 'NO') FROM performance_schema.replication_group_members JOIN performance_schema.replication_group_member_stats rgms USING (member_id) WHERE rgms.MEMBER_ID = my_server_uuid()), 'NO') AS viable_candidate, IF((SELECT ((SELECT GROUP_CONCAT(performance_schema.global_variables.VARIABLE_VALUE SEPARATOR ',') FROM performance_schema.global_variables WHERE (performance_schema.global_variables.VARIABLE_NAME IN ('read_only' , 'super_read_only'))) <> 'OFF,OFF') ), 'YES', 'NO') AS read_only, IFNULL(sys.gr_applier_queue_length(), 0) AS transactions_behind, IFNULL(sys.gr_transactions_to_cert(), 0) AS transactions_to_cert;$$
DELIMITER ; SET @@SESSION.SQL_LOG_BIN = @TEMP_LOG_BIN; SET @@GLOBAL.READ_ONLY = @TEMP_READ_ONLY; SET @@GLOBAL.SUPER_READ_ONLY = @TEMP_SUPER_READ_ONLY;
-- SET @TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN; -- SET @@SESSION.SQL_LOG_BIN= 0; -- SET @TEMP_READ_ONLY = @@GLOBAL.READ_ONLY; -- SET @TEMP_SUPER_READ_ONLY = @@GLOBAL.SUPER_READ_ONLY; -- SET @@GLOBAL.READ_ONLY = 0; USEsys;
CREATEFUNCTION GTID_COUNT(gtid_set TEXT(10000)) RETURNSINT DETERMINISTIC BEGIN DECLAREresultBIGINTDEFAULT0; DECLARE colon_pos INT; DECLARE next_dash_pos INT; DECLARE next_colon_pos INT; DECLARE next_comma_pos INT; SET gtid_set = GTID_NORMALIZE(gtid_set); SET colon_pos = LOCATE2(':', gtid_set, 1); WHILE colon_pos != LENGTH(gtid_set) + 1 DO SET next_dash_pos = LOCATE2('-', gtid_set, colon_pos + 1); SET next_colon_pos = LOCATE2(':', gtid_set, colon_pos + 1); SET next_comma_pos = LOCATE2(',', gtid_set, colon_pos + 1); IF next_dash_pos < next_colon_pos AND next_dash_pos < next_comma_pos THEN SETresult = result + SUBSTR(gtid_set, next_dash_pos + 1, LEAST(next_colon_pos, next_comma_pos) - (next_dash_pos + 1)) - SUBSTR(gtid_set, colon_pos + 1, next_dash_pos - (colon_pos + 1)) + 1; ELSE SETresult = result + 1; ENDIF; SET colon_pos = next_colon_pos; ENDWHILE; RETURN result; END$$
CREATEFUNCTION gr_applier_queue_length() RETURNSINT DETERMINISTIC BEGIN RETURN (SELECT sys.gtid_count( GTID_SUBTRACT( (SELECT Received_transaction_set FROM performance_schema.replication_connection_status WHERE Channel_name = 'group_replication_applier' ), (SELECT @@global.GTID_EXECUTED) ))); END$$
CREATEFUNCTION gr_transactions_to_cert() RETURNSint(11) DETERMINISTIC BEGIN RETURN (select performance_schema.replication_group_member_stats.COUNT_TRANSACTIONS_IN_QUEUE AS transactions_to_cert FROM performance_schema.replication_group_member_stats where MEMBER_ID=@@SERVER_UUID ); END$$
CREATEFUNCTION my_server_uuid() RETURNSTEXT(36) DETERMINISTICNOSQLRETURN (SELECT @@global.server_uuid as my_id);$$
CREATEVIEW gr_member_routing_candidate_status AS SELECT IFNULL((SELECT IF(MEMBER_STATE = 'ONLINE' AND ((SELECT COUNT(*) FROM performance_schema.replication_group_members WHERE MEMBER_STATE != 'ONLINE') >= ((SELECT COUNT(*) FROM performance_schema.replication_group_members) / 2) = 0), 'YES', 'NO') FROM performance_schema.replication_group_members JOIN performance_schema.replication_group_member_stats rgms USING (member_id) WHERE rgms.MEMBER_ID = my_server_uuid()), 'NO') AS viable_candidate, IF((SELECT ((SELECT GROUP_CONCAT(performance_schema.global_variables.VARIABLE_VALUE SEPARATOR ',') FROM performance_schema.global_variables WHERE (performance_schema.global_variables.VARIABLE_NAME IN ('read_only' , 'super_read_only'))) <> 'OFF,OFF') ), 'YES', 'NO') AS read_only, IFNULL(sys.gr_applier_queue_length(), 0) AS transactions_behind, IFNULL(sys.gr_transactions_to_cert(), 0) AS transactions_to_cert;$$
DELIMITER ; -- SET @@SESSION.SQL_LOG_BIN = @TEMP_LOG_BIN; -- SET @@GLOBAL.READ_ONLY = @TEMP_READ_ONLY; -- SET @@GLOBAL.SUPER_READ_ONLY = @TEMP_SUPER_READ_ONLY;