Skip to content

Commit

Permalink
WL#9090 Reimplement SHOW PROCESSLIST
Browse files Browse the repository at this point in the history
Alternative SHOW PROCESSLIST implemented as a view of performance_schema.threads.

Approved by: Shivashankar Nagaraj <shiva.y.shankar@oracle.com>
Approved by: Marc Alff <marc.alff@oracle.com>
  • Loading branch information
Christopher Powers committed Jul 2, 2020
1 parent 0f4234b commit 4095e08
Show file tree
Hide file tree
Showing 107 changed files with 4,407 additions and 871 deletions.
6 changes: 3 additions & 3 deletions include/mysql/components/services/psi_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
#include <mysql/components/component_implementation.h>
#include <mysql/components/services/psi_thread_service.h>

#define REQUIRES_PSI_THREAD_SERVICE REQUIRES_SERVICE(psi_thread_v3)
#define REQUIRES_PSI_THREAD_SERVICE REQUIRES_SERVICE(psi_thread_v4)
#define REQUIRES_PSI_THREAD_SERVICE_PLACEHOLDER \
REQUIRES_SERVICE_PLACEHOLDER(psi_thread_v3)
REQUIRES_SERVICE_PLACEHOLDER(psi_thread_v4)

extern REQUIRES_PSI_THREAD_SERVICE_PLACEHOLDER;

#define PSI_THREAD_CALL(M) mysql_service_psi_thread_v3->M
#define PSI_THREAD_CALL(M) mysql_service_psi_thread_v4->M

#endif /* COMPONENTS_SERVICES_PSI_THREAD_H */
12 changes: 11 additions & 1 deletion include/mysql/components/services/psi_thread_bits.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2008, 2020, Oracle and/or its affiliates.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -88,6 +88,7 @@ struct PSI_thread_info_v1 {
The flags of the thread to register.
@sa PSI_FLAG_SINGLETON
@sa PSI_FLAG_USER
@sa PSI_FLAG_THREAD_SYSTEM
*/
unsigned int m_flags;
/** Volatility index. */
Expand Down Expand Up @@ -276,6 +277,15 @@ typedef int (*set_thread_resource_group_by_id_v1_t)(
*/
typedef void (*set_thread_v1_t)(struct PSI_thread *thread);

/**
Assign the remote (peer) port to the instrumented thread.

@param thread pointer to the thread instrumentation
@param port the remote port
*/
typedef void (*set_thread_peer_port_v4_t)(PSI_thread *thread,
unsigned int port);

/** Aggregate the thread status variables. */
typedef void (*aggregate_thread_status_v2_t)(struct PSI_thread *thread);

Expand Down
20 changes: 15 additions & 5 deletions include/mysql/components/services/psi_thread_service.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.

/* Copyright (c) 2017, 2020, Oracle and/or its affiliates.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -31,23 +32,30 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
Introduced in MySQL 8.0.3
Deprecated in MySQL 8.0.15
Abandoned in MySQL 8.0.17
Status: Removed, use version 3 instead.
Status: Removed, use version 4 instead.
*/

/*
Version 2.
Introduced in MySQL 8.0.15
Abandoned in MySQL 8.0.17
Status: Removed, use version 3 instead.
Status: Removed, use version 4 instead.
*/

/*
Version 3.
Introduced in MySQL 8.0.17
Abandoned in MySQL 8.0.22
Status: Removed, use version 4 instead.
*/

/*
Version 4.
Introduced in MySQL 8.0.22
Status: active
*/

BEGIN_SERVICE_DEFINITION(psi_thread_v3)
BEGIN_SERVICE_DEFINITION(psi_thread_v4)
/** @sa register_thread_v1_t. */
register_thread_v1_t register_thread;
/** @sa spawn_thread_v1_t. */
Expand Down Expand Up @@ -84,6 +92,8 @@ set_thread_start_time_v1_t set_thread_start_time;
set_thread_info_v1_t set_thread_info;
/** @sa set_thread_v1_t. */
set_thread_v1_t set_thread;
/** @sa set_thread_peer_port_v4_t. */
set_thread_peer_port_v4_t set_thread_peer_port;
/** @sa aggregate_thread_status_v1_t. */
aggregate_thread_status_v2_t aggregate_thread_status;
/** @sa delete_current_thread_v1_t. */
Expand All @@ -110,6 +120,6 @@ notify_session_connect_v1_t notify_session_connect;
notify_session_disconnect_v1_t notify_session_disconnect;
/** @sa notify_session_change_user_v1_t. */
notify_session_change_user_v1_t notify_session_change_user;
END_SERVICE_DEFINITION(psi_thread_v3)
END_SERVICE_DEFINITION(psi_thread_v4)

#endif /* COMPONENTS_SERVICES_PSI_THREAD_SERVICE_H */
8 changes: 4 additions & 4 deletions include/mysql/psi/mysql_socket.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2010, 2020, Oracle and/or its affiliates.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -82,7 +82,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Set socket descriptor and address.
@param socket instrumented socket
@param addr unformatted socket address
@param addr_len length of socket addres
@param addr_len length of socket address
*/

static inline void mysql_socket_set_address(
Expand All @@ -96,13 +96,13 @@ static inline void mysql_socket_set_address(
) {
#ifdef HAVE_PSI_SOCKET_INTERFACE
if (socket.m_psi != nullptr) {
PSI_SOCKET_CALL(set_socket_info)(socket.m_psi, nullptr, addr, addr_len);
PSI_SOCKET_CALL(set_socket_info)(socket.m_psi, &socket.fd, addr, addr_len);
}
#endif
}

/**
Set socket descriptor and address.
Assign the current thread instrumentation to the socket.
@param socket instrumented socket
*/
static inline void mysql_socket_set_thread_owner(
Expand Down
20 changes: 19 additions & 1 deletion include/mysql/psi/mysql_thread.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2008, 2020, Oracle and/or its affiliates.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -156,6 +156,24 @@ static inline void inline_mysql_thread_set_psi_THD(THD *thd) {

#endif

/**
@def mysql_thread_set_peer_port()
Set the remote (peer) port for the thread instrumentation.
@param socket instrumented socket
*/
static inline void mysql_thread_set_peer_port(
#ifdef HAVE_PSI_THREAD_INTERFACE
uint port
#else
uint port MY_ATTRIBUTE((unused))
#endif
) {
#ifdef HAVE_PSI_THREAD_INTERFACE
struct PSI_thread *psi = PSI_THREAD_CALL(get_thread)();
PSI_THREAD_CALL(set_thread_peer_port)(psi, port);
#endif
}

/** @} (end of group psi_api_thread) */

#endif
7 changes: 5 additions & 2 deletions include/mysql/psi/psi_abi_thread_v1.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
PSI_thread *thread, unsigned long long thread_id, const char *group_name,
int group_name_len, void *user_data);
typedef void (*set_thread_v1_t)(struct PSI_thread *thread);
typedef void (*set_thread_peer_port_v4_t)(PSI_thread *thread,
unsigned int port);
typedef void (*aggregate_thread_status_v2_t)(struct PSI_thread *thread);
typedef void (*delete_current_thread_v1_t)(void);
typedef void (*delete_thread_v1_t)(struct PSI_thread *thread);
Expand Down Expand Up @@ -134,7 +136,7 @@
void *(*get_interface)(int version);
};
typedef struct PSI_thread_bootstrap PSI_thread_bootstrap;
struct PSI_thread_service_v3 {
struct PSI_thread_service_v4 {
register_thread_v1_t register_thread;
spawn_thread_v1_t spawn_thread;
new_thread_v1_t new_thread;
Expand All @@ -155,6 +157,7 @@
set_thread_resource_group_v1_t set_thread_resource_group;
set_thread_resource_group_by_id_v1_t set_thread_resource_group_by_id;
set_thread_v1_t set_thread;
set_thread_peer_port_v4_t set_thread_peer_port;
aggregate_thread_status_v2_t aggregate_thread_status;
delete_current_thread_v1_t delete_current_thread;
delete_thread_v1_t delete_thread;
Expand All @@ -169,5 +172,5 @@
notify_session_disconnect_v1_t notify_session_disconnect;
notify_session_change_user_v1_t notify_session_change_user;
};
typedef struct PSI_thread_service_v3 PSI_thread_service_t;
typedef struct PSI_thread_service_v4 PSI_thread_service_t;
extern PSI_thread_service_t *psi_thread_service;
6 changes: 6 additions & 0 deletions include/mysql/psi/psi_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ static constexpr unsigned PSI_NOT_INSTRUMENTED = 0;
*/
#define PSI_FLAG_RWLOCK_PR (1 << 8)

/**
System thread flag.
Indicates that the instrumented object exists on a system thread.
*/
#define PSI_FLAG_THREAD_SYSTEM (1 << 9)

#define PSI_VOLATILITY_UNKNOWN 0
#define PSI_VOLATILITY_PERMANENT 1
#define PSI_VOLATILITY_PROVISIONING 2
Expand Down
24 changes: 17 additions & 7 deletions include/mysql/psi/psi_thread.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2008, 2020, Oracle and/or its affiliates.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -55,16 +55,23 @@
/**
@def PSI_THREAD_VERSION_3
Performance Schema Thread Interface number for version 3.
This version is supported.
This version is obsolete.
*/
#define PSI_THREAD_VERSION_3 3

/**
@def PSI_THREAD_VERSION_4
Performance Schema Thread Interface number for version 4.
This version is supported.
*/
#define PSI_THREAD_VERSION_4 4

/**
@def PSI_CURRENT_THREAD_VERSION
Performance Schema Thread Interface number for the most recent version.
The most current version is @c PSI_THREAD_VERSION_3
*/
#define PSI_CURRENT_THREAD_VERSION 3
#define PSI_CURRENT_THREAD_VERSION 4

/** Entry point for the performance schema interface. */
struct PSI_thread_bootstrap {
Expand All @@ -75,6 +82,7 @@ struct PSI_thread_bootstrap {
@sa PSI_THREAD_VERSION_1
@sa PSI_THREAD_VERSION_2
@sa PSI_THREAD_VERSION_3
@sa PSI_THREAD_VERSION_4
@sa PSI_CURRENT_THREAD_VERSION
*/
void *(*get_interface)(int version);
Expand All @@ -84,10 +92,10 @@ typedef struct PSI_thread_bootstrap PSI_thread_bootstrap;
#ifdef HAVE_PSI_THREAD_INTERFACE

/**
Performance Schema Thread Interface, version 3.
@since PSI_THREAD_VERSION_3
Performance Schema Thread Interface, version 4.
@since PSI_THREAD_VERSION_4
*/
struct PSI_thread_service_v3 {
struct PSI_thread_service_v4 {
/** @sa register_thread_v1_t. */
register_thread_v1_t register_thread;
/** @sa spawn_thread_v1_t. */
Expand Down Expand Up @@ -128,6 +136,8 @@ struct PSI_thread_service_v3 {
set_thread_resource_group_by_id_v1_t set_thread_resource_group_by_id;
/** @sa set_thread_v1_t. */
set_thread_v1_t set_thread;
/** @sa set_thread_peer_port_vc_t. */
set_thread_peer_port_v4_t set_thread_peer_port;
/** @sa aggregate_thread_status_v1_t. */
aggregate_thread_status_v2_t aggregate_thread_status;
/** @sa delete_current_thread_v1_t. */
Expand Down Expand Up @@ -156,7 +166,7 @@ struct PSI_thread_service_v3 {
notify_session_change_user_v1_t notify_session_change_user;
};

typedef struct PSI_thread_service_v3 PSI_thread_service_t;
typedef struct PSI_thread_service_v4 PSI_thread_service_t;

extern MYSQL_PLUGIN_IMPORT PSI_thread_service_t *psi_thread_service;

Expand Down
4 changes: 3 additions & 1 deletion include/pfs_thread_provider.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2012, 2020, Oracle and/or its affiliates.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -101,6 +101,8 @@ int pfs_set_thread_resource_group_by_id_vc(PSI_thread *thread,

void pfs_set_thread_vc(PSI_thread *thread);

void pfs_set_thread_peer_port_vc(PSI_thread *thread, uint port);

void pfs_aggregate_thread_status_vc(PSI_thread *thread);

void pfs_delete_current_thread_vc(void);
Expand Down
8 changes: 4 additions & 4 deletions mysql-test/r/all_persisted_variables.result
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ include/assert.inc [Expect 500+ variables in the table. Due to open Bugs, we are

# Test SET PERSIST

include/assert.inc [Expect 408 persisted variables in the table.]
include/assert.inc [Expect 409 persisted variables in the table.]

************************************************************
* 3. Restart server, it must preserve the persisted variable
* settings. Verify persisted configuration.
************************************************************
# restart

include/assert.inc [Expect 408 persisted variables in persisted_variables table.]
include/assert.inc [Expect 408 persisted variables shown as PERSISTED in variables_info table.]
include/assert.inc [Expect 408 persisted variables with matching peristed and global values.]
include/assert.inc [Expect 409 persisted variables in persisted_variables table.]
include/assert.inc [Expect 409 persisted variables shown as PERSISTED in variables_info table.]
include/assert.inc [Expect 409 persisted variables with matching peristed and global values.]

************************************************************
* 4. Test RESET PERSIST IF EXISTS. Verify persisted variable
Expand Down
4 changes: 4 additions & 0 deletions mysql-test/r/mysqld--help-notwin.result
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,9 @@ The following options may be given as the first argument:
--performance-schema-setup-objects-size=#
Maximum number of rows in SETUP_OBJECTS. Use 0 to
disable, -1 for automated scaling.
--performance-schema-show-processlist
Default startup value to enable SHOW PROCESSLIST in the
performance schema.
--performance-schema-users-size=#
Maximum number of instrumented users. Use 0 to disable,
-1 for automated scaling.
Expand Down Expand Up @@ -1705,6 +1708,7 @@ performance-schema-max-thread-instances -1
performance-schema-session-connect-attrs-size -1
performance-schema-setup-actors-size -1
performance-schema-setup-objects-size -1
performance-schema-show-processlist FALSE
performance-schema-users-size -1
persist-only-admin-x509-subject
persisted-globals-load TRUE
Expand Down
4 changes: 4 additions & 0 deletions mysql-test/r/mysqld--help-win.result
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,9 @@ The following options may be given as the first argument:
--performance-schema-setup-objects-size=#
Maximum number of rows in SETUP_OBJECTS. Use 0 to
disable, -1 for automated scaling.
--performance-schema-show-processlist
Default startup value to enable SHOW PROCESSLIST in the
performance schema.
--performance-schema-users-size=#
Maximum number of instrumented users. Use 0 to disable,
-1 for automated scaling.
Expand Down Expand Up @@ -1717,6 +1720,7 @@ performance-schema-max-thread-instances -1
performance-schema-session-connect-attrs-size -1
performance-schema-setup-actors-size -1
performance-schema-setup-objects-size -1
performance-schema-show-processlist FALSE
performance-schema-users-size -1
persist-only-admin-x509-subject
persisted-globals-load TRUE
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/funcs_1/r/is_key_column_usage.result
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def performance_schema PRIMARY def performance_schema metadata_locks OBJECT_INST
def performance_schema PRIMARY def performance_schema mutex_instances OBJECT_INSTANCE_BEGIN
def performance_schema PRIMARY def performance_schema persisted_variables VARIABLE_NAME
def performance_schema PRIMARY def performance_schema prepared_statements_instances OBJECT_INSTANCE_BEGIN
def performance_schema PRIMARY def performance_schema processlist ID
def performance_schema PRIMARY def performance_schema replication_applier_configuration CHANNEL_NAME
def performance_schema PRIMARY def performance_schema replication_applier_status CHANNEL_NAME
def performance_schema PRIMARY def performance_schema replication_applier_status_by_coordinator CHANNEL_NAME
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/funcs_1/r/is_key_column_usage_ci.result
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def performance_schema PRIMARY def performance_schema metadata_locks OBJECT_INST
def performance_schema PRIMARY def performance_schema mutex_instances OBJECT_INSTANCE_BEGIN
def performance_schema PRIMARY def performance_schema persisted_variables VARIABLE_NAME
def performance_schema PRIMARY def performance_schema prepared_statements_instances OBJECT_INSTANCE_BEGIN
def performance_schema PRIMARY def performance_schema processlist ID
def performance_schema PRIMARY def performance_schema replication_applier_configuration CHANNEL_NAME
def performance_schema PRIMARY def performance_schema replication_applier_status CHANNEL_NAME
def performance_schema PRIMARY def performance_schema replication_applier_status_by_coordinator CHANNEL_NAME
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/funcs_1/r/is_statistics_ci.result
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def performance_schema prepared_statements_instances performance_schema OWNER_TH
def performance_schema prepared_statements_instances performance_schema PRIMARY
def performance_schema prepared_statements_instances performance_schema STATEMENT_ID
def performance_schema prepared_statements_instances performance_schema STATEMENT_NAME
def performance_schema processlist performance_schema PRIMARY
def performance_schema replication_applier_configuration performance_schema PRIMARY
def performance_schema replication_applier_status performance_schema PRIMARY
def performance_schema replication_applier_status_by_coordinator performance_schema PRIMARY
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/funcs_1/r/is_statistics_cs.result
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def performance_schema prepared_statements_instances performance_schema OWNER_TH
def performance_schema prepared_statements_instances performance_schema PRIMARY
def performance_schema prepared_statements_instances performance_schema STATEMENT_ID
def performance_schema prepared_statements_instances performance_schema STATEMENT_NAME
def performance_schema processlist performance_schema PRIMARY
def performance_schema replication_applier_configuration performance_schema PRIMARY
def performance_schema replication_applier_status performance_schema PRIMARY
def performance_schema replication_applier_status_by_coordinator performance_schema PRIMARY
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/funcs_1/r/is_table_constraints.result
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def performance_schema OBJECT performance_schema objects_summary_global_by_type
def performance_schema PRIMARY performance_schema persisted_variables
def performance_schema OWNER_THREAD_ID performance_schema prepared_statements_instances
def performance_schema PRIMARY performance_schema prepared_statements_instances
def performance_schema PRIMARY performance_schema processlist
def performance_schema PRIMARY performance_schema replication_applier_configuration
def performance_schema PRIMARY performance_schema replication_applier_status
def performance_schema PRIMARY performance_schema replication_applier_status_by_coordinator
Expand Down
Loading

0 comments on commit 4095e08

Please sign in to comment.