Commit beb73f29 authored by Julius Goryavsky's avatar Julius Goryavsky

MDEV-33677 : Port Performance Schema for Galera from ES

Added performance schema tables for Galera.
This is a port of the code from ES 10.6

Refs:
MENT-346  commit 86c06851
MENT-346  commit 10d0fcaf
MENT-1333 commit 2005adc3
MENT-347  commit aaca43b4
MENT-1370 commit 1f460e6b
parent f131c609
......@@ -58,6 +58,7 @@ Then restart the build.
endif()
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/wsrep-lib/include)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/wsrep-lib/wsrep-API/v26)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/wsrep-lib/wsrep-API/ps)
SET(old_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
SET(BUILD_SHARED_LIBS OFF)
......
......@@ -3,10 +3,17 @@ connection node_1;
use performance_schema;
SELECT name
FROM threads
WHERE name LIKE 'thread/sql/wsrep%'
WHERE name LIKE 'thread/sql/wsrep%' AND
name NOT LIKE 'thread/sql/wsrep_provider%'
ORDER BY name;
name thread/sql/wsrep_applier_thread
name thread/sql/wsrep_rollbacker_thread
SELECT COUNT(*) > 0 FROM threads WHERE name LIKE 'thread/sql/wsrep_provider%';
COUNT(*) > 0 0
connection node_2;
use performance_schema;
use test;
connection node_1;
use test;
create table t1 (a int not null primary key) engine=innodb;
insert into t1 values (1),(2);
......@@ -35,6 +42,19 @@ name wait/synch/cond/sql/COND_wsrep_sst
name wait/synch/cond/sql/COND_wsrep_sst_init
name wait/synch/cond/sql/COND_wsrep_wsrep_slave_threads
connection node_2;
select * from t1;
a 1
a 2
connection node_1;
connection node_2;
use performance_schema;
use test;
connection node_1;
SET GLOBAL wsrep_on=OFF;
select * from galera_group_members;
select * from galera_group_member_stats;
SET GLOBAL wsrep_on=ON;
connection node_2;
use test;
SET SESSION wsrep_on=OFF;
CREATE TABLE t2 (f1 INTEGER) engine=innodb;
......
......@@ -5,16 +5,69 @@
--source include/galera_cluster.inc
--source include/have_perfschema.inc
--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
--source include/wait_condition.inc
use performance_schema;
--vertical_results
--disable_ps_protocol
# Server side threads are known, but provider threads may vary
# between provider versions. Exclued provider threads from the
# first select and check that some provider threads are visible
# in the second.
SELECT name
FROM threads
WHERE name LIKE 'thread/sql/wsrep%'
WHERE name LIKE 'thread/sql/wsrep%' AND
name NOT LIKE 'thread/sql/wsrep_provider%'
ORDER BY name;
SELECT COUNT(*) > 0 FROM threads WHERE name LIKE 'thread/sql/wsrep_provider%';
--enable_ps_protocol
# Check for a compatible version of the Galera library:
--let $rows = `SELECT COUNT(*) FROM galera_group_members`
if ($rows == 0)
{
die Incompatible or old version of the Galera library;
}
# Let's keep the initial values of the most characteristic fields:
--let $index1 = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_index';`
--let $wsrep_last_committed = `SELECT wsrep_last_committed FROM galera_group_members WHERE wsrep_local_index = $index1`
--let $wsrep_replicated = `SELECT wsrep_replicated FROM galera_group_members WHERE wsrep_local_index = $index1`
--let $wsrep_replicated_bytes = `SELECT wsrep_replicated_bytes FROM galera_group_members WHERE wsrep_local_index = $index1`
--let $wsrep_local_commits = `SELECT wsrep_local_commits FROM galera_group_members WHERE wsrep_local_index = $index1`
--let $wsrep_repl_keys = `SELECT wsrep_repl_keys FROM galera_group_member_stats WHERE wsrep_local_index = $index1`
--let $wsrep_repl_keys_bytes = `SELECT wsrep_repl_keys_bytes FROM galera_group_member_stats WHERE wsrep_local_index = $index1`
--let $wsrep_repl_data_bytes = `SELECT wsrep_repl_data_bytes FROM galera_group_member_stats WHERE wsrep_local_index = $index1`
--let $wsrep_apply_window = `SELECT CEILING(wsrep_apply_window) FROM galera_group_members WHERE wsrep_local_index = $index1`
--let $wsrep_commit_window = `SELECT CEILING(wsrep_commit_window) FROM galera_group_members WHERE wsrep_local_index = $index1`
--connection node_2
--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
--source include/wait_condition.inc
use performance_schema;
--let $index2 = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_index';`
--let $wsrep_last_committed2 = `SELECT wsrep_last_committed FROM galera_group_members WHERE wsrep_local_index = $index2`
--let $wsrep_received2 = `SELECT wsrep_received FROM galera_group_members WHERE wsrep_local_index = $index2`
--let $wsrep_received_bytes2 = `SELECT wsrep_received_bytes FROM galera_group_members WHERE wsrep_local_index = $index2`
--let $wsrep_apply_window2 = `SELECT CEILING(wsrep_apply_window) FROM galera_group_members WHERE wsrep_local_index = $index2`
--let $wsrep_commit_window2 = `SELECT CEILING(wsrep_commit_window) FROM galera_group_members WHERE wsrep_local_index = $index2`
use test;
--connection node_1
--let $wsrep_cluster_address_orig = `SELECT @@wsrep_cluster_address`
use test;
create table t1 (a int not null primary key) engine=innodb;
insert into t1 values (1),(2);
......@@ -22,6 +75,146 @@ insert into t1 values (1),(2);
use performance_schema;
select name from mutex_instances where name like 'wait/synch/mutex/sql/LOCK_wsrep%' order by name;
select name from cond_instances where name like 'wait/synch/cond/sql/COND_wsrep%' order by name;
# Make sure that the second node sees the changes:
--connection node_2
select * from t1;
# Let's check the presence and functionality of the new tables
# that reflect the state of the current cluster node and show
# which nodes are in the cluster:
--connection node_1
# Let's request new values for the most characteristic fields:
--let $wsrep_last_committed_new = `SELECT wsrep_last_committed FROM galera_group_members WHERE wsrep_local_index = $index1`
--let $wsrep_replicated_new = `SELECT wsrep_replicated FROM galera_group_members WHERE wsrep_local_index = $index1`
--let $wsrep_replicated_bytes_new = `SELECT wsrep_replicated_bytes FROM galera_group_members WHERE wsrep_local_index = $index1`
--let $wsrep_local_commits_new = `SELECT wsrep_local_commits FROM galera_group_members WHERE wsrep_local_index = $index1`
--let $wsrep_repl_keys_new = `SELECT wsrep_repl_keys FROM galera_group_member_stats WHERE wsrep_local_index = $index1`
--let $wsrep_repl_keys_bytes_new = `SELECT wsrep_repl_keys_bytes FROM galera_group_member_stats WHERE wsrep_local_index = $index1`
--let $wsrep_repl_data_bytes_new = `SELECT wsrep_repl_data_bytes FROM galera_group_member_stats WHERE wsrep_local_index = $index1`
--let $wsrep_apply_window_new = `SELECT CEILING(wsrep_apply_window) FROM galera_group_members WHERE wsrep_local_index = $index1`
--let $wsrep_commit_window_new = `SELECT CEILING(wsrep_commit_window) FROM galera_group_members WHERE wsrep_local_index = $index1`
# Let's calculate the differences between the old and new values:
--let $wsrep_last_committed_diff = `SELECT $wsrep_last_committed_new - $wsrep_last_committed`
--let $wsrep_replicated_diff = `SELECT $wsrep_replicated_new - $wsrep_replicated`
--let $wsrep_replicated_bytes_diff = `SELECT $wsrep_replicated_bytes_new - $wsrep_replicated_bytes`
--let $wsrep_local_commits_diff = `SELECT $wsrep_local_commits_new - $wsrep_local_commits`
--let $wsrep_repl_keys_diff = `SELECT $wsrep_repl_keys_new - $wsrep_repl_keys`
--let $wsrep_repl_keys_bytes_diff = `SELECT $wsrep_repl_keys_bytes_new - $wsrep_repl_keys_bytes`
--let $wsrep_repl_data_bytes_diff = `SELECT $wsrep_repl_data_bytes_new - $wsrep_repl_data_bytes`
# Check that the fields have changed to the correct values:
if ($wsrep_last_committed_diff != 2)
{
die bad wsrep_last_committed difference: $wsrep_last_committed_diff;
}
if ($wsrep_replicated_diff != 2)
{
die bad wsrep_replicated difference: $wsrep_replicated_diff;
}
if ($wsrep_replicated_bytes_diff <= 0)
{
die bad wsrep_replicated_bytes difference: $wsrep_replicated_bytes_diff;
}
if ($wsrep_local_commits_new < 1)
{
die bad wsrep_local_commits difference: $wsrep_local_commits_new;
}
if ($wsrep_apply_window_new < 0)
{
die bad wsrep_apply_window: $wsrep_apply_window_new;
}
if ($wsrep_commit_window_new < 0)
{
die bad wsrep_commit_window: $wsrep_commit_window_new;
}
if ($wsrep_repl_keys_diff < 6)
{
die bad wsrep_repl_keys difference: $wsrep_repl_keys_diff;
}
if ($wsrep_repl_keys_bytes_diff <= 0)
{
die bad wsrep_repl_keys_bytes difference: $wsrep_repl_keys_bytes_diff;
}
if ($wsrep_repl_data_bytes_diff <= 0)
{
die bad wsrep_repl_keys_bytes difference: $wsrep_repl_keys_bytes_diff;
}
--connection node_2
# Let's request new values for the most characteristic fields:
use performance_schema;
--let $wsrep_last_committed_new2 = `SELECT wsrep_last_committed FROM galera_group_members WHERE wsrep_local_index = $index2`
--let $wsrep_received_new2 = `SELECT wsrep_received FROM galera_group_members WHERE wsrep_local_index = $index2`
--let $wsrep_received_bytes_new2 = `SELECT wsrep_received_bytes FROM galera_group_members WHERE wsrep_local_index = $index2`
--let $wsrep_apply_window_new2 = `SELECT CEILING(wsrep_apply_window) FROM galera_group_members WHERE wsrep_local_index = $index2`
--let $wsrep_commit_window_new2 = `SELECT CEILING(wsrep_commit_window) FROM galera_group_members WHERE wsrep_local_index = $index2`
use test;
# Let's calculate the differences between the old and new values:
--let $wsrep_last_committed_diff2 = `SELECT $wsrep_last_committed_new2 - $wsrep_last_committed2`
--let $wsrep_received_diff2 = `SELECT $wsrep_received_new2 - $wsrep_received2`
--let $wsrep_received_bytes_diff2 = `SELECT $wsrep_received_bytes_new2 - $wsrep_received_bytes2`
# Check that the fields have changed to the correct values:
if ($wsrep_last_committed_diff2 != 2)
{
die bad wsrep_last_committed difference: $wsrep_last_committed_diff2;
}
if ($wsrep_received_diff2 != 2)
{
die bad wsrep_received difference: $wsrep_received_diff2;
}
if ($wsrep_received_bytes_diff2 <= 0)
{
die bad wsrep_received_bytes difference: $wsrep_received_bytes_diff2;
}
if ($wsrep_apply_window_new2 < 0)
{
die bad wsrep_apply_window: $wsrep_apply_window_new2;
}
if ($wsrep_commit_window_new2 < 0)
{
die bad wsrep_commit_window: $wsrep_commit_window_new2;
}
--connection node_1
# Let's check the presence of new tables without field
# values when wsrep=off:
SET GLOBAL wsrep_on=OFF;
select * from galera_group_members;
select * from galera_group_member_stats;
SET GLOBAL wsrep_on=ON;
# Whenever a node fails to apply an event on a slave node, the database server creates a
# special binary log file of the event in the data directory. The naming convention the
# node uses for the filename is GRA_*.log.
......@@ -55,4 +248,3 @@ CALL mtr.add_suppression("Slave SQL: Error 'Table 't2' already exists' on query"
use test;
drop table t1;
drop table t2;
......@@ -699,6 +699,39 @@ def performance_schema file_summary_by_instance SUM_TIMER_MISC 22 NULL NO bigint
def performance_schema file_summary_by_instance MIN_TIMER_MISC 23 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Minimum wait time of all miscellaneous operations that are timed. NEVER NULL
def performance_schema file_summary_by_instance AVG_TIMER_MISC 24 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Average wait time of all miscellaneous operations that are timed. NEVER NULL
def performance_schema file_summary_by_instance MAX_TIMER_MISC 25 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Maximum wait time of all miscellaneous operations that are timed. NEVER NULL
def performance_schema galera_group_members wsrep_node_id 1 NULL NO char 36 108 NULL NULL NULL utf8mb3 utf8mb3_general_ci char(36) select,insert,update,references Unique node ID (UUID) NEVER NULL NO NO
def performance_schema galera_group_members wsrep_local_index 2 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select,insert,update,references Index of this node in the Galera cluster nodes table NEVER NULL NO NO
def performance_schema galera_group_members wsrep_cluster_state_uuid 3 NULL NO char 36 108 NULL NULL NULL utf8mb3 utf8mb3_general_ci char(36) select,insert,update,references The UUID of the cluster NEVER NULL NO NO
def performance_schema galera_group_members wsrep_local_state_uuid 4 NULL NO char 36 108 NULL NULL NULL utf8mb3 utf8mb3_general_ci char(36) select,insert,update,references The UUID of the state stored on this node NEVER NULL NO NO
def performance_schema galera_group_members wsrep_last_applied 5 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Sequence number of the last applied transaction NEVER NULL NO NO
def performance_schema galera_group_members wsrep_last_committed 6 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Sequence number of the last committed transaction NEVER NULL NO NO
def performance_schema galera_group_members wsrep_replicated 7 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Total number of write-sets replicated NEVER NULL NO NO
def performance_schema galera_group_members wsrep_replicated_bytes 8 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Total size of write-sets replicated (in bytes) NEVER NULL NO NO
def performance_schema galera_group_members wsrep_received 9 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Total number of write-sets received NEVER NULL NO NO
def performance_schema galera_group_members wsrep_received_bytes 10 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Total size of write-sets received (in bytes) NEVER NULL NO NO
def performance_schema galera_group_members wsrep_local_bf_aborts 11 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Total number of local transactions that were aborted by slave transactions while in execution NEVER NULL NO NO
def performance_schema galera_group_members wsrep_local_commits 12 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Total number of local transactions committed NEVER NULL NO NO
def performance_schema galera_group_members wsrep_local_cert_failures 13 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Total number of local transactions that failed certification test NEVER NULL NO NO
def performance_schema galera_group_members wsrep_apply_window 14 NULL NO double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references Average distance between the highest and lowest concurrently applied seqno NEVER NULL NO NO
def performance_schema galera_group_members wsrep_commit_window 15 NULL NO double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references Average distance between the highest and lowest concurrently committed seqno NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_node_id 1 NULL NO char 36 108 NULL NULL NULL utf8mb3 utf8mb3_general_ci char(36) select,insert,update,references Unique node ID (UUID) NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_local_index 2 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select,insert,update,references Index of this node in the Galera cluster nodes table NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_repl_keys 3 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Total number of keys replicated NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_repl_keys_bytes 4 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Total size of keys replicated (in bytes) NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_repl_data_bytes 5 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Total size of data replicated (in bytes) NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_repl_other_bytes 6 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Total size of other bits replicated (in bytes) NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_local_replays 7 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Total number of transaction replays due to asymmetric lock granularity NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_local_send_queue 8 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Current (instantaneous) length of the send queue NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_local_send_queue_avg 9 NULL NO double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references Send queue length averaged over time since the last FLUSH STATUS command NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_local_recv_queue 10 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Current (instantaneous) length of the receive queue NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_local_recv_queue_avg 11 NULL NO double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references Receive queue length averaged over interval since the last FLUSH STATUS command NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_flow_control_paused 12 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references The fraction of time (out of 1.0) since the last SHOW GLOBAL STATUS that flow control is effective NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_flow_control_sent 13 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references The number of flow control messages sent by the local node to the cluster NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_flow_control_recv 14 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references The number of flow control messages the node has received, including those the node has sent NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_flow_control_status 15 NULL NO varchar 32 96 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(32) select,insert,update,references Status shows whether a node has flow control enabled for normal traffic NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_cert_deps_distance 16 NULL NO double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references Average distance between the highest and lowest seqno value that can be possibly applied in parallel NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_open_transactions 17 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references The number of locally running transactions which have been registered inside the wsrep provider NEVER NULL NO NO
def performance_schema galera_group_member_stats wsrep_evs_repl_latency 18 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references This status variable provides figures for the replication latency on group communication NEVER NULL NO NO
def performance_schema global_status VARIABLE_NAME 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) select,insert,update,references The global status variable name. NEVER NULL
def performance_schema global_status VARIABLE_VALUE 2 NULL YES varchar 1024 3072 NULL NULL NULL utf8 utf8_general_ci varchar(1024) select,insert,update,references The global status variable value. NEVER NULL
def performance_schema hosts HOST 1 NULL YES char 60 180 NULL NULL NULL utf8 utf8_bin char(60) select,insert,update,references Host name used by the client to connect, NULL for internal threads or user sessions that failed to authenticate. NEVER NULL
......@@ -1189,8 +1222,8 @@ where table_schema="performance_schema" and data_type="bigint"
select (@count_object_columns - @count_object_unsigned) = 0;
(@count_object_columns - @count_object_unsigned) = 0
1
select count(*) from information_schema.columns
select count(*) `expect 0` from information_schema.columns
where table_schema="performance_schema"
and (column_comment is null or column_comment = '');
count(*)
expect 0
0
......@@ -56,7 +56,6 @@ select count(*) into @count_object_unsigned from information_schema.columns
select (@count_object_columns - @count_object_unsigned) = 0;
# Confirm that all columns have comments
#
select count(*) from information_schema.columns
select count(*) `expect 0` from information_schema.columns
where table_schema="performance_schema"
and (column_comment is null or column_comment = '');
#ifndef WSREP_PS_H
#define WSREP_PS_H
#include <stdint.h>
#include <stdbool.h>
#include "wsrep_api.h"
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
/* Current API version: */
#define WSREP_PS_API_VERSION 0x200
/* Minimum supported API version on the calling server side: */
#define WSREP_PS_MIN_API_VERSION 0x200
/*!
* Structures for communicating information that will be exposed
* through Performance Schema tables:
*/
#define WSREP_HOSTNAME_LENGTH 64
#define WSREP_STATUS_LENGTH 32
/* Information about the current state of all nodes in the cluster: */
typedef struct {
/* Version number for this data structure: */
int wsrep_version;
/* Local node index: */
uint32_t wsrep_local_index;
/* Unique node ID (UUID): */
char wsrep_node_id[WSREP_UUID_STR_LEN + 1];
/* User-assigned host name: */
char wsrep_host_name[WSREP_HOSTNAME_LENGTH + 1];
/* The UUID of the cluster: */
char wsrep_cluster_state_uuid[WSREP_UUID_STR_LEN + 1];
/* The UUID of the state stored on this node: */
char wsrep_local_state_uuid[WSREP_UUID_STR_LEN + 1];
/* Status PRIMARY/NON_PRIMARY: */
char wsrep_status[WSREP_STATUS_LENGTH + 1];
/* Segment of the node: */
uint32_t wsrep_segment;
/* Sequence number of the last applied transaction: */
uint64_t wsrep_last_applied;
/* Sequence number of the last committed transaction: */
uint64_t wsrep_last_committed;
/* Total number of write-sets replicated: */
uint64_t wsrep_replicated;
/* Total size of write-sets replicated: */
uint64_t wsrep_replicated_bytes;
/* Total number of write-sets received: */
uint64_t wsrep_received;
/* Total size of write-sets received: */
uint64_t wsrep_received_bytes;
/* Total number of local transactions that were aborted by slave
transactions while in execution: */
uint64_t wsrep_local_bf_aborts;
/* Total number of local transactions committed: */
uint64_t wsrep_local_commits;
/* Total number of local transactions that failed certification test: */
uint64_t wsrep_local_cert_failures;
/* Average distance between the highest and lowest concurrently
applied seqno: */
double wsrep_apply_window;
/* Average distance between the highest and lowest concurrently
committed seqno: */
double wsrep_commit_window;
} wsrep_node_info_t;
/*! Data structure with statistics of the current node: */
typedef struct {
/* Version number for this data structure: */
int wsrep_version;
/* Local node index: */
int wsrep_local_index;
/* Unique node ID (UUID): */
char wsrep_node_id[WSREP_UUID_STR_LEN + 1];
/* Total number of keys replicated: */
uint64_t wsrep_repl_keys;
/* Total size of keys replicated: */
uint64_t wsrep_repl_keys_bytes;
/* Total size of data replicated: */
uint64_t wsrep_repl_data_bytes;
/* Total size of other bits replicated: */
uint64_t wsrep_repl_other_bytes;
/* Total number of transaction replays due to asymmetric lock
granularity: */
uint64_t wsrep_local_replays;
/* Current (instantaneous) length of the send queue: */
uint64_t wsrep_local_send_queue;
/* Send queue length averaged over time since the last
FLUSH STATUS command: */
double wsrep_local_send_queue_avg;
/* Current (instantaneous) length of the recv queue: */
uint64_t wsrep_local_recv_queue;
/* Recv queue length averaged over interval since the last
FLUSH STATUS command: */
double wsrep_local_recv_queue_avg;
/* The fraction of time (out of 1.0) since the last
SHOW GLOBAL STATUS that flow control is effective: */
uint64_t wsrep_flow_control_paused;
/* The number of flow control messages sent by the local node
to the cluster: */
uint64_t wsrep_flow_control_sent;
/* The number of flow control messages the node has received,
including those the node has sent: */
uint64_t wsrep_flow_control_recv;
/* This variable shows whether a node has flow control
enabled for normal traffic: */
char wsrep_flow_control_status[WSREP_STATUS_LENGTH + 1];
/* Average distance between the highest and lowest seqno
value that can be possibly applied in parallel: */
double wsrep_cert_deps_distance;
/* The number of locally running transactions which have been
registered inside the wsrep provider: */
uint64_t wsrep_open_transactions;
/* This status variable provides figures for the replication
latency on group communication: */
uint64_t wsrep_evs_repl_latency;
} wsrep_node_stat_t;
/*!
* @brief Get general cluster information to expose through
* Performance Schema.
*
* @param wsrep wsrep provider handle.
* @param nodes array of data structures with the information
* about the cluster members.
* @param size size of the nodes array.
* @param my_index index of the current node.
* @param max_version the maximum version number of the data
* structure that is supported by the server
* calling this function.
*/
typedef wsrep_status_t
(*wsrep_ps_fetch_cluster_info_t) (wsrep_t* wsrep,
wsrep_node_info_t** nodes,
uint32_t* size,
int32_t* my_index,
uint32_t max_version);
#define WSREP_PS_FETCH_CLUSTER_INFO_FUNC "wsrep_ps_fetch_cluster_info_v2"
/*!
* @brief Freeing memory occupied by cluster information.
*
* @param wsrep wsrep provider handle.
* @param nodes array of data structures with the information
* about the cluster members.
*/
typedef void
(*wsrep_ps_free_cluster_info_t) (wsrep_t* wsrep,
wsrep_node_info_t* nodes);
#define WSREP_PS_FREE_CLUSTER_INFO_FUNC "wsrep_ps_free_cluster_info"
/*!
* @brief Get the statistical information to expose through
* Performance Schema.
*
* @param wsrep wsrep provider handle.
* @param nodes array of data structures with the statistical
* information about the cluster nodes. Currently
* only one item is returned.
* @param size size of the nodes array (currently = 1).
* @param my_index index of the current node.
* @param max_version the maximum version number of the data
* structure that is supported by the server
* calling this function.
*/
typedef wsrep_status_t
(*wsrep_ps_fetch_node_stat_t) (wsrep_t* wsrep,
wsrep_node_stat_t** nodes,
uint32_t* size,
int32_t* my_index,
uint32_t max_version);
#define WSREP_PS_FETCH_NODE_STAT_FUNC "wsrep_ps_fetch_node_stat_v2"
/*!
* @brief Freeing memory occupied by statistical information.
*
* @param wsrep wsrep provider handle.
* @param nodes array of data structures with the statistical
* information about the cluster nodes.
*/
typedef void
(*wsrep_ps_free_node_stat_t) (wsrep_t* wsrep,
wsrep_node_stat_t* nodes);
#define WSREP_PS_FREE_NODE_STAT_FUNC "wsrep_ps_free_node_stat"
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* WSREP_PS_H */
......@@ -281,6 +281,14 @@ table_replication_applier_status_by_coordinator.cc
#table_replication_group_member_stats.cc
)
IF(WITH_WSREP)
SET(PERFSCHEMA_WSREP_SOURCES
table_galera_group_members.h
table_galera_group_member_stats.h
table_galera_group_members.cc
table_galera_group_member_stats.cc)
ENDIF()
# Check for pthread_threadid_np()
CHECK_C_SOURCE_COMPILES("
#include <pthread.h>
......@@ -342,7 +350,8 @@ FAIL_REGEX "warning: incompatible pointer to integer conversion"
CONFIGURE_FILE(pfs_config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/pfs_config.h)
MYSQL_ADD_PLUGIN(perfschema ${PERFSCHEMA_SOURCES} STORAGE_ENGINE DEFAULT
MYSQL_ADD_PLUGIN(perfschema ${PERFSCHEMA_SOURCES}
${PERFSCHEMA_WSREP_SOURCES} STORAGE_ENGINE DEFAULT
STATIC_ONLY RECOMPILE_FOR_EMBEDDED DEPENDS GenServerSource)
IF (TARGET perfschema)
IF(WITH_UNIT_TESTS)
......
......@@ -105,6 +105,11 @@
#include "table_replication_applier_status_by_worker.h"
#include "table_replication_group_member_stats.h"
#ifdef WITH_WSREP
#include "table_galera_group_members.h"
#include "table_galera_group_member_stats.h"
#endif
#include "table_prepared_stmt_instances.h"
#include "table_md_locks.h"
......@@ -320,6 +325,11 @@ static PFS_engine_table_share *all_shares[]=
//&table_replication_group_member_stats::m_share,
#endif
#ifdef WITH_WSREP
&table_galera_group_members::m_share,
&table_galera_group_member_stats::m_share,
#endif
&table_prepared_stmt_instances::m_share,
&table_uvar_by_thread::m_share,
......
This diff is collapsed.
/* Copyright (c) 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#pragma once
/**
@file storage/perfschema/table_galera_group_member_stats.h
Table galera_group_member_stats (declarations).
*/
#include "pfs_column_types.h"
#include "pfs_engine_table.h"
#include "mysql_com.h"
#include "wsrep_ps.h"
#include "wsrep_mysqld.h"
#include "wsrep_server_state.h"
/**
@addtogroup Performance_schema_tables
@{
*/
/** Table PERFORMANCE_SCHEMA.galera_group_member_stats. */
class table_galera_group_member_stats final : public PFS_engine_table
{
public:
static PFS_engine_table_share_state m_share_state;
/** Table share */
static PFS_engine_table_share m_share;
/** Table builder */
static PFS_engine_table* create();
private:
void make_row(uint index);
/** Table share lock. */
static THR_LOCK m_table_lock;
/** Fields definition. */
static TABLE_FIELD_DEF m_field_def;
/** True if the current row exists. */
bool m_row_exists= false;
/** Current row. */
wsrep_node_stat_t m_row;
/** Rows array. */
wsrep_node_stat_t* m_entries= nullptr;
/** Number of rows. */
uint32_t m_rows= 0;
/** Current position. */
PFS_simple_index m_pos= 0;
/** Next position. */
PFS_simple_index m_next_pos= 0;
protected:
/**
Read the current row values.
@param table Table handle
@param buf row buffer
@param fields Table fields
@param read_all true if all columns are read.
*/
int read_row_values(TABLE *table, unsigned char *buf,
Field **fields, bool read_all) override;
table_galera_group_member_stats();
public:
~table_galera_group_member_stats();
static ha_rows get_row_count();
int rnd_init(bool) override;
int rnd_next() override;
int rnd_pos(const void *pos) override;
void reset_position() override;
};
/** @} */
/* Copyright (c) 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/**
@file storage/perfschema/table_galera_group_members.cc
Table galera_group_members (implementation).
*/
#include "my_global.h"
#include "table_galera_group_members.h"
#include "pfs_instr_class.h"
#include "pfs_instr.h"
#include "log.h"
#include <atomic>
THR_LOCK table_galera_group_members::m_table_lock;
PFS_engine_table_share_state
table_galera_group_members::m_share_state = {
false /* m_checked */
};
#define STRINGIFY2(X) #X
#define STRINGIFY(X) STRINGIFY2(X)
PFS_engine_table_share
table_galera_group_members::m_share=
{
{ C_STRING_WITH_LEN("galera_group_members") },
&pfs_readonly_acl,
&table_galera_group_members::create,
NULL, /* write_row */
NULL, /* delete_all_rows */
table_galera_group_members::get_row_count,
sizeof(PFS_simple_index), /* ref length */
&m_table_lock,
{ C_STRING_WITH_LEN("CREATE TABLE galera_group_members("
"wsrep_node_id char(" STRINGIFY(WSREP_UUID_STR_LEN) ") not null comment 'Unique node ID (UUID)',"
"wsrep_local_index INTEGER UNSIGNED not null comment 'Index of this node in the Galera cluster nodes table',"
"wsrep_cluster_state_uuid char(" STRINGIFY(WSREP_UUID_STR_LEN) ") not null comment 'The UUID of the cluster',"
"wsrep_local_state_uuid char(" STRINGIFY(WSREP_UUID_STR_LEN) ") not null comment 'The UUID of the state stored on this node',"
"wsrep_last_applied BIGINT UNSIGNED not null comment 'Sequence number of the last applied transaction',"
"wsrep_last_committed BIGINT UNSIGNED not null comment 'Sequence number of the last committed transaction',"
"wsrep_replicated BIGINT UNSIGNED not null comment 'Total number of write-sets replicated',"
"wsrep_replicated_bytes BIGINT UNSIGNED not null comment 'Total size of write-sets replicated (in bytes)',"
"wsrep_received BIGINT UNSIGNED not null comment 'Total number of write-sets received',"
"wsrep_received_bytes BIGINT UNSIGNED not null comment 'Total size of write-sets received (in bytes)',"
"wsrep_local_bf_aborts BIGINT UNSIGNED not null comment 'Total number of local transactions that were aborted by slave transactions while in execution',"
"wsrep_local_commits BIGINT UNSIGNED not null comment 'Total number of local transactions committed',"
"wsrep_local_cert_failures BIGINT UNSIGNED not null comment 'Total number of local transactions that failed certification test',"
"wsrep_apply_window DOUBLE PRECISION not null comment 'Average distance between the highest and lowest concurrently applied seqno',"
"wsrep_commit_window DOUBLE PRECISION not null comment 'Average distance between the highest and lowest concurrently committed seqno')") },
false, /* m_perpetual */
false, /* m_optional */
&m_share_state
};
PFS_engine_table* table_galera_group_members::create()
{
return new table_galera_group_members();
}
static std::atomic<wsrep_ps_fetch_cluster_info_t> fetch_cluster_info;
static std::atomic<wsrep_ps_free_cluster_info_t> free_cluster_info;
static wsrep_ps_fetch_cluster_info_t init_once()
{
if (auto f= fetch_cluster_info.load(std::memory_order_acquire))
return f;
auto dlh= static_cast<wsrep_t*>
(Wsrep_server_state::instance().get_provider().native())->dlh;
union
{
void* sym;
wsrep_ps_fetch_cluster_info_t func;
} obj;
obj.sym= dlsym(dlh, WSREP_PS_FETCH_CLUSTER_INFO_FUNC);
union
{
void* sym;
wsrep_ps_free_cluster_info_t func;
} obj2;
obj2.sym= obj.func ? dlsym(dlh, WSREP_PS_FREE_CLUSTER_INFO_FUNC) : nullptr;
if (!obj.sym || !obj2.sym)
{
WSREP_WARN("Performance Schema for Galera: incompatible or "
"old version of the Galera library");
return nullptr;
}
DBUG_PRINT("info", ("Initialized galera PS fetch cluster info: %p %p",
dlh, obj.sym));
free_cluster_info.store(obj2.func, std::memory_order_relaxed);
fetch_cluster_info.store(obj.func, std::memory_order_release);
return obj.func;
}
table_galera_group_members::table_galera_group_members()
: PFS_engine_table(&m_share, &m_pos)
{
}
static void free_rows(wsrep_node_info_t* entries)
{
if (entries)
{
auto free_func= free_cluster_info.load(std::memory_order_relaxed);
free_func(static_cast<wsrep_t*>
(Wsrep_server_state::instance().get_provider().native()),
entries);
}
}
table_galera_group_members::~table_galera_group_members()
{
free_rows(m_entries);
}
void table_galera_group_members::reset_position()
{
m_pos.m_index= 0;
m_next_pos.m_index= 0;
}
ha_rows table_galera_group_members::get_row_count()
{
return WSREP_ON && init_once() ? wsrep_cluster_size : 0;
}
int table_galera_group_members::rnd_init(bool)
{
if (!WSREP_ON)
return 0;
if (auto fetch= init_once())
{
free_rows(m_entries);
m_entries= nullptr;
m_rows= 0;
uint32_t size;
int32_t my_index;
wsrep_node_info_t* entries;
wsrep_status_t ret=
fetch(static_cast<wsrep_t*>
(Wsrep_server_state::instance().get_provider().native()),
&entries, &size, &my_index, WSREP_PS_API_VERSION);
if (ret == WSREP_OK && size &&
entries[0].wsrep_version <= WSREP_PS_API_VERSION)
{
m_entries= entries;
m_rows= size;
}
}
return 0;
}
int table_galera_group_members::rnd_next()
{
if (!WSREP_ON)
return HA_ERR_END_OF_FILE;
for (m_pos.set_at(&m_next_pos);
m_pos.m_index < m_rows;
m_pos.next())
{
make_row(m_pos.m_index);
m_next_pos.set_after(&m_pos);
return 0;
}
return HA_ERR_END_OF_FILE;
}
int table_galera_group_members::rnd_pos(const void *pos)
{
if (!WSREP_ON)
return HA_ERR_END_OF_FILE;
set_position(pos);
DBUG_ASSERT(m_pos.m_index < m_rows);
make_row(m_pos.m_index);
return 0;
}
void table_galera_group_members::make_row(uint index)
{
DBUG_ENTER("table_galera_group_members::make_row");
// Set default values.
m_row_exists= false;
if (index >= m_rows) {
DBUG_ASSERT(false);
}
// Query plugin and let callbacks do their job.
if (WSREP_ON)
{
m_row_exists= true;
m_row= m_entries[index];
}
else
{
DBUG_PRINT("info", ("Galera stats not available!"));
}
DBUG_VOID_RETURN;
}
int table_galera_group_members::read_row_values(TABLE *table,
unsigned char *buf,
Field **fields,
bool read_all)
{
Field *f;
if (unlikely(! m_row_exists))
return HA_ERR_RECORD_DELETED;
DBUG_ASSERT(table->s->null_bytes == 1);
buf[0]= 0;
for (; (f= *fields) ; fields++)
{
if (read_all || bitmap_is_set(table->read_set, f->field_index))
{
switch(f->field_index)
{
case 0: /** wsrep_node_id */
set_field_char_utf8(f, m_row.wsrep_node_id,
WSREP_UUID_STR_LEN);
break;
case 1: /** wsrep_local_index */
set_field_ulong(f, m_row.wsrep_local_index);
break;
case 2: /** wsrep_cluster_state_uuid */
set_field_char_utf8(f, m_row.wsrep_cluster_state_uuid,
WSREP_UUID_STR_LEN);
break;
case 3: /** wsrep_local_state_uuid */
set_field_char_utf8(f, m_row.wsrep_local_state_uuid,
WSREP_UUID_STR_LEN);
break;
case 4: /** wsrep_last_applied */
set_field_ulonglong(f, m_row.wsrep_last_applied);
break;
case 5: /** wsrep_last_committed */
set_field_ulonglong(f, m_row.wsrep_last_committed);
break;
case 6: /** wsrep_replicated */
set_field_ulonglong(f, m_row.wsrep_replicated);
break;
case 7: /** wsrep_replicated_bytes */
set_field_ulonglong(f, m_row.wsrep_replicated_bytes);
break;
case 8: /** wsrep_received */
set_field_ulonglong(f, m_row.wsrep_received);
break;
case 9: /** wsrep_received_bytes */
set_field_ulonglong(f, m_row.wsrep_received_bytes);
break;
case 10: /** wsrep_local_bf_aborts */
set_field_ulonglong(f, m_row.wsrep_local_bf_aborts);
break;
case 11: /** wsrep_local_commits */
set_field_ulonglong(f, m_row.wsrep_local_commits);
break;
case 12: /** wsrep_local_cert_failures */
set_field_ulonglong(f, m_row.wsrep_local_cert_failures);
break;
case 13: /** wsrep_apply_window */
set_field_double(f, m_row.wsrep_apply_window);
break;
case 14: /** wsrep_commit_window */
set_field_double(f, m_row.wsrep_commit_window);
break;
default:
DBUG_ASSERT(false);
}
}
}
return 0;
}
/* Copyright (c) 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#pragma once
/**
@file storage/perfschema/table_galera_group_members.h
Table galera_group_members (declarations).
*/
#include "pfs_column_types.h"
#include "pfs_engine_table.h"
#include "mysql_com.h"
#include "wsrep_ps.h"
#include "wsrep_mysqld.h"
#include "wsrep_server_state.h"
/**
@addtogroup Performance_schema_tables
@{
*/
/** Table PERFORMANCE_SCHEMA.galera_group_members. */
class table_galera_group_members final : public PFS_engine_table
{
public:
static PFS_engine_table_share_state m_share_state;
/** Table share */
static PFS_engine_table_share m_share;
/** Table builder */
static PFS_engine_table* create();
private:
void make_row(uint index);
/** Table share lock. */
static THR_LOCK m_table_lock;
/** Fields definition. */
static TABLE_FIELD_DEF m_field_def;
/** True if the current row exists. */
bool m_row_exists= false;
/** Current row. */
wsrep_node_info_t m_row;
/** Rows array. */
wsrep_node_info_t* m_entries= nullptr;
/** Number of rows. */
uint32_t m_rows= 0;
/** Current position. */
PFS_simple_index m_pos= 0;
/** Next position. */
PFS_simple_index m_next_pos= 0;
protected:
/**
Read the current row values.
@param table Table handle
@param buf row buffer
@param fields Table fields
@param read_all true if all columns are read.
*/
int read_row_values(TABLE *table, unsigned char *buf,
Field **fields, bool read_all) override;
table_galera_group_members();
public:
~table_galera_group_members();
static ha_rows get_row_count();
int rnd_init(bool) override;
int rnd_next() override;
int rnd_pos(const void *pos) override;
void reset_position() override;
};
/** @} */
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