Skip to content

Commit 7fd2454

Browse files
committed
Merge branch 'mysql-8.0' into mysql-trunk
2 parents 786ae1b + 1310357 commit 7fd2454

File tree

5 files changed

+75
-23
lines changed

5 files changed

+75
-23
lines changed

mysql-test/suite/connection_control/r/connection_delay_info_schema_view.result

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
# Install connection_control plugin
77
INSTALL PLUGIN connection_control SONAME 'CONNECTION_CONTROL_LIB';
88
INSTALL PLUGIN connection_control_failed_login_attempts SONAME 'CONNECTION_CONTROL_LIB';
9+
# Performance schema
10+
# Verify the instrumentation provided
11+
SELECT * FROM performance_schema.setup_instruments
12+
WHERE NAME LIKE "%/conn_delay/%"
13+
ORDER BY NAME;
14+
NAME ENABLED TIMED PROPERTIES VOLATILITY DOCUMENTATION
15+
stage/conn_delay/Waiting in connection_control plugin YES YES 0 NULL
16+
wait/synch/cond/conn_delay/connection_delay_wait_condition YES YES 0 NULL
17+
wait/synch/mutex/conn_delay/connection_delay_mutex YES YES 0 NULL
18+
wait/synch/rwlock/conn_delay/connection_event_delay_lock YES YES singleton 0 NULL
919
# Create user accounts for testing
1020
CREATE USER u1@localhost IDENTIFIED BY 'abcd';
1121
CREATE USER u2@localhost IDENTIFIED BY 'abcd';

mysql-test/suite/connection_control/t/connection_delay_info_schema_view.test

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
--echo # Install connection_control plugin
1616
--source ../inc/install_connection_control_plugin.inc
1717

18+
--echo # Performance schema
19+
--echo # Verify the instrumentation provided
20+
21+
SELECT * FROM performance_schema.setup_instruments
22+
WHERE NAME LIKE "%/conn_delay/%"
23+
ORDER BY NAME;
24+
1825
--echo # Create user accounts for testing
1926
CREATE USER u1@localhost IDENTIFIED BY 'abcd';
2027
CREATE USER u2@localhost IDENTIFIED BY 'abcd';

plugin/connection_control/connection_control.cc

+49
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,49 @@ Connection_control_variables g_variables;
6363
Connection_event_coordinator *g_connection_event_coordinator = nullptr;
6464
MYSQL_PLUGIN connection_control_plugin_info = nullptr;
6565

66+
/* Performance Schema instrumentation */
67+
68+
PSI_mutex_key key_connection_delay_mutex = PSI_NOT_INSTRUMENTED;
69+
70+
static PSI_mutex_info all_connection_delay_mutex_info[] = {
71+
{&key_connection_delay_mutex, "connection_delay_mutex", 0, 0,
72+
PSI_DOCUMENT_ME}};
73+
74+
PSI_rwlock_key key_connection_event_delay_lock;
75+
76+
static PSI_rwlock_info all_connection_delay_rwlock_info[] = {
77+
{&key_connection_event_delay_lock, "connection_event_delay_lock",
78+
PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME}};
79+
80+
PSI_cond_key key_connection_delay_wait = PSI_NOT_INSTRUMENTED;
81+
82+
static PSI_cond_info all_connection_delay_cond_info[] = {
83+
{&key_connection_delay_wait, "connection_delay_wait_condition", 0, 0,
84+
PSI_DOCUMENT_ME}};
85+
86+
PSI_stage_info stage_waiting_in_connection_control_plugin = {
87+
0, "Waiting in connection_control plugin", 0, PSI_DOCUMENT_ME};
88+
89+
static PSI_stage_info *all_connection_delay_stage_info[] = {
90+
&stage_waiting_in_connection_control_plugin};
91+
92+
static void init_performance_schema() {
93+
const char *category = "conn_delay";
94+
95+
int count_mutex = array_elements(all_connection_delay_mutex_info);
96+
mysql_mutex_register(category, all_connection_delay_mutex_info, count_mutex);
97+
98+
int count_rwlock = array_elements(all_connection_delay_rwlock_info);
99+
mysql_rwlock_register(category, all_connection_delay_rwlock_info,
100+
count_rwlock);
101+
102+
int count_cond = array_elements(all_connection_delay_cond_info);
103+
mysql_cond_register(category, all_connection_delay_cond_info, count_cond);
104+
105+
int count_stage = array_elements(all_connection_delay_stage_info);
106+
mysql_stage_register(category, all_connection_delay_stage_info, count_stage);
107+
}
108+
66109
/**
67110
event_notify() implementation for connection_control
68111
@@ -106,6 +149,12 @@ static int connection_control_notify(MYSQL_THD thd,
106149
*/
107150

108151
static int connection_control_init(MYSQL_PLUGIN plugin_info) {
152+
/*
153+
Declare all performance schema instrumentation up front,
154+
so it is discoverable.
155+
*/
156+
init_performance_schema();
157+
109158
// Initialize error logging service.
110159
if (init_logging_service_for_plugin(&reg_srv, &log_bi, &log_bs)) return 1;
111160

plugin/connection_control/connection_control.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -23,11 +23,19 @@
2323
#ifndef CONNECTION_CONTROL_H
2424
#define CONNECTION_CONTROL_H
2525

26+
#include <mysql/psi/mysql_cond.h>
27+
#include <mysql/psi/mysql_mutex.h>
2628
#include <mysql/psi/mysql_rwlock.h>
29+
#include <mysql/psi/mysql_stage.h>
2730
#include <mysql/psi/mysql_thread.h> /* mysql_rwlock_t */
2831

2932
#include "plugin/connection_control/connection_control_data.h"
3033

34+
extern PSI_mutex_key key_connection_delay_mutex;
35+
extern PSI_rwlock_key key_connection_event_delay_lock;
36+
extern PSI_cond_key key_connection_delay_wait;
37+
extern PSI_stage_info stage_waiting_in_connection_control_plugin;
38+
3139
namespace connection_control {
3240

3341
/** Helper class : Wrapper on READ lock */

plugin/connection_control/connection_delay.cc

-22
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ int64 MAX_DELAY = INT_MAX32;
7474

7575
/** variables used by connection_delay.cc */
7676
static mysql_rwlock_t connection_event_delay_lock;
77-
static PSI_rwlock_key key_connection_event_delay_lock;
78-
static PSI_rwlock_info all_rwlocks[] = {{&key_connection_event_delay_lock,
79-
"connection_event_delay_lock", 0, 0,
80-
PSI_DOCUMENT_ME}};
8177

8278
static opt_connection_control opt_enums[] = {OPT_FAILED_CONNECTIONS_THRESHOLD,
8379
OPT_MIN_CONNECTION_DELAY,
@@ -461,29 +457,14 @@ void Connection_delay_action::conditional_wait(MYSQL_THD thd,
461457

462458
/** PSI_stage_info for thd_enter_cond/thd_exit_cond */
463459
PSI_stage_info old_stage;
464-
PSI_stage_info stage_waiting_in_connection_control_plugin = {
465-
0, "Waiting in connection_control plugin", 0, PSI_DOCUMENT_ME};
466460

467461
/** Initialize mutex required for mysql_cond_timedwait */
468462
mysql_mutex_t connection_delay_mutex;
469-
const char *category = "conn_delay";
470-
PSI_mutex_key key_connection_delay_mutex;
471-
PSI_mutex_info connection_delay_mutex_info[] = {
472-
{&key_connection_delay_mutex, "connection_delay_mutex",
473-
PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME}};
474-
int count_mutex = array_elements(connection_delay_mutex_info);
475-
mysql_mutex_register(category, connection_delay_mutex_info, count_mutex);
476463
mysql_mutex_init(key_connection_delay_mutex, &connection_delay_mutex,
477464
MY_MUTEX_INIT_FAST);
478465

479466
/* Initialize condition to wait for */
480467
mysql_cond_t connection_delay_wait_condition;
481-
PSI_cond_key key_connection_delay_wait;
482-
PSI_cond_info connection_delay_wait_info[] = {
483-
{&key_connection_delay_wait, "connection_delay_wait_condition", 0, 0,
484-
PSI_DOCUMENT_ME}};
485-
int count_cond = array_elements(connection_delay_wait_info);
486-
mysql_cond_register(category, connection_delay_wait_info, count_cond);
487468
mysql_cond_init(key_connection_delay_wait, &connection_delay_wait_condition);
488469

489470
/** Register wait condition with THD */
@@ -791,9 +772,6 @@ bool init_connection_delay_event(
791772
/*
792773
1. Initialize lock(s)
793774
*/
794-
const char *category = "conn_control";
795-
int count = array_elements(all_rwlocks);
796-
mysql_rwlock_register(category, all_rwlocks, count);
797775
mysql_rwlock_init(key_connection_event_delay_lock,
798776
&connection_event_delay_lock);
799777
g_max_failed_connection_handler = new Connection_delay_action(

0 commit comments

Comments
 (0)