Skip to content

Commit 64d7c2e

Browse files
introduces Enhanced Host Monitoring v.2 plugin (#513)
performance tests fixes and docs Co-authored-by: sergiyv-bitquill <[email protected]>
1 parent 970e177 commit 64d7c2e

15 files changed

+1698
-12
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,26 @@ You can include additional monitoring configurations by adding the prefix `monit
529529
>
530530
> It is suggested to turn off Enhanced Failure Monitoring plugin, or to avoid using RDS Proxy endpoints when the plugin is active.
531531
532+
## **Experimental** Enhanced Failure Monitoring Plugin v2
533+
534+
> [!WARNING]
535+
> This plugin is experimental and users should test the plugin before using it in production environment.
536+
537+
Enhanced Failure Monitoring Plugin v2 is an alternative implementation of enhanced failure monitoring, and it is functionally equal to the Enhanced Failure Monitoring Plugin described above. Both plugins share the same set of [configuration parameters](#enhanced-failure-monitoring-parameters). Enhanced Failure Monitoring Plugin v2 plugin is designed to be a drop-in replacement for the Enhanced Failure Monitoring Plugin.
538+
539+
> [!NOTE]
540+
> Since these two plugins are separate plugins, users may decide to use them together with a single connection. While this should not have any negative side effects, it is not recommended. It is recommended to use either the Enhanced Failure Monitoring Plugin, or the Enhanced Failure Monitoring Plugin v2 where it's needed.
541+
542+
In order to use Enhanced Failure Monitoring Plugin v2, users should add `software.aws.rds.jdbc.mysql.shading.com.mysql.cj.jdbc.ha.plugins.efm2.NodeMonitoringConnectionPluginFactory` to `connectionPluginFactories`.
543+
544+
Enhanced Failure Monitoring Plugin v2 is designed to address [some of the issues](https://github.com/awslabs/aws-mysql-jdbc/issues/412) that have been reported by multiple users. The following changes have been made:
545+
- Used weak pointers to ease garbage collection
546+
- Split monitoring logic into two separate threads to increase overall monitoring stability
547+
- Reviewed locks for monitoring context
548+
- Reviewed and redesigned stopping of idle monitoring threads
549+
- Reviewed and simplified monitoring logic
550+
551+
532552
## AWS Secrets Manager Plugin
533553
534554
The AWS JDBC Driver for MySQL supports usage of database credentials stored in the [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/) through the AWS Secrets Manager Plugin. This plugin is optional and can be enabled with the `connectionPluginFactories` parameter as seen in the [connection plugin manager parameters table](#connection-plugin-manager-parameters). When a user creates a new connection with this plugin enabled, the plugin will retrieve the secret and the connection will be created using those credentials.

build.gradle.kts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ tasks.shadowJar {
136136
exclude("instrumentation/**")
137137
exclude("demo/**")
138138
exclude("documentation/**")
139-
exclude("customplugins/**");
139+
exclude("customplugins/**")
140140

141141
includeEmptyDirs = false
142142
}
@@ -447,7 +447,10 @@ tasks.register<Test>("in-container-aurora") {
447447
}
448448

449449
tasks.register<Test>("in-container-aurora-performance") {
450-
filter.includeTestsMatching("testsuite.integration.container.AuroraMysqlPerformanceIntegrationTest")
450+
filter.includeTestsMatching(
451+
"testsuite.integration.container.AuroraMysqlPerformanceIntegrationTest")
452+
filter.includeTestsMatching(
453+
"testsuite.integration.container.AuroraMysqlPerformanceForEfm2IntegrationTest")
451454
}
452455

453456
// Run all tests excluding integration tests

src/main/core-api/java/com/mysql/cj/conf/PropertyDefinitions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ public enum DatabaseTerm {
716716
Messages.getString("ConnectionProperties.failureDetectionCount"), "0.4.0", CATEGORY_HA, Integer.MAX_VALUE, 0,
717717
Integer.MAX_VALUE),
718718

719-
new IntegerPropertyDefinition(PropertyKey.monitorDisposalTime, 60_000, RUNTIME_MODIFIABLE,
719+
new IntegerPropertyDefinition(PropertyKey.monitorDisposalTime, 900_000, RUNTIME_MODIFIABLE, // 15 min
720720
Messages.getString("ConnectionProperties.monitorDisposalTime"), "0.4.0", CATEGORY_HA, Integer.MAX_VALUE, 0,
721721
Integer.MAX_VALUE),
722722

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License, version 2.0
6+
* (GPLv2), as published by the Free Software Foundation, with the
7+
* following additional permissions:
8+
*
9+
* This program is distributed with certain software that is licensed
10+
* under separate terms, as designated in a particular file or component
11+
* or in the license documentation. Without limiting your rights under
12+
* the GPLv2, the authors of this program hereby grant you an additional
13+
* permission to link the program and your derivative works with the
14+
* separately licensed software that they have included with the program.
15+
*
16+
* Without limiting the foregoing grant of rights under the GPLv2 and
17+
* additional permission as to separately licensed software, this
18+
* program is also subject to the Universal FOSS Exception, version 1.0,
19+
* a copy of which can be found along with its FAQ at
20+
* http://oss.oracle.com/licenses/universal-foss-exception.
21+
*
22+
* This program is distributed in the hope that it will be useful, but
23+
* WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25+
* See the GNU General Public License, version 2.0, for more details.
26+
*
27+
* You should have received a copy of the GNU General Public License
28+
* along with this program. If not, see
29+
* http://www.gnu.org/licenses/gpl-2.0.html.
30+
*/
31+
32+
package com.mysql.cj.jdbc.ha.plugins.efm2;
33+
34+
import com.mysql.cj.conf.HostInfo;
35+
import com.mysql.cj.conf.PropertyKey;
36+
import com.mysql.cj.conf.PropertySet;
37+
import com.mysql.cj.jdbc.JdbcConnection;
38+
import com.mysql.cj.jdbc.ha.plugins.BasicConnectionProvider;
39+
import com.mysql.cj.jdbc.ha.util.SlidingExpirationCacheWithCleanupThread;
40+
import com.mysql.cj.log.Log;
41+
42+
import java.sql.Connection;
43+
import java.sql.SQLException;
44+
import java.util.concurrent.Executor;
45+
import java.util.concurrent.Executors;
46+
import java.util.concurrent.TimeUnit;
47+
import org.checkerframework.checker.nullness.qual.NonNull;
48+
49+
/**
50+
* This class handles the creation and clean up of monitoring threads to servers with one
51+
* or more active connections.
52+
*/
53+
public class DefaultMonitorService implements IMonitorService {
54+
protected static final long CACHE_CLEANUP_NANO = TimeUnit.MINUTES.toNanos(1);
55+
56+
protected static final Executor ABORT_EXECUTOR = Executors.newSingleThreadExecutor();
57+
58+
protected static final SlidingExpirationCacheWithCleanupThread<String, IMonitor> monitors =
59+
new SlidingExpirationCacheWithCleanupThread<>(
60+
IMonitor::canDispose,
61+
(monitor) -> {
62+
try {
63+
monitor.close();
64+
} catch (Exception ex) {
65+
// ignore
66+
}
67+
},
68+
CACHE_CLEANUP_NANO);
69+
70+
protected final Log logger;
71+
protected final IMonitorInitializer monitorInitializer;
72+
73+
public DefaultMonitorService(Log logger) {
74+
this(
75+
(hostInfo,
76+
propertySet,
77+
failureDetectionTimeMillis,
78+
failureDetectionIntervalMillis,
79+
failureDetectionCount) ->
80+
new Monitor(
81+
new BasicConnectionProvider(),
82+
hostInfo,
83+
propertySet,
84+
failureDetectionTimeMillis,
85+
failureDetectionIntervalMillis,
86+
failureDetectionCount,
87+
logger),
88+
logger
89+
);
90+
}
91+
92+
DefaultMonitorService(IMonitorInitializer monitorInitializer, Log logger) {
93+
this.monitorInitializer = monitorInitializer;
94+
this.logger = logger;
95+
}
96+
97+
@Override
98+
public MonitorConnectionContext startMonitoring(
99+
JdbcConnection connectionToAbort,
100+
HostInfo hostInfo,
101+
PropertySet propertySet,
102+
int failureDetectionTimeMillis,
103+
int failureDetectionIntervalMillis,
104+
int failureDetectionCount) {
105+
106+
final IMonitor monitor = this.getMonitor(
107+
hostInfo,
108+
propertySet,
109+
failureDetectionTimeMillis,
110+
failureDetectionIntervalMillis,
111+
failureDetectionCount);
112+
113+
final MonitorConnectionContext context = new MonitorConnectionContext(connectionToAbort);
114+
monitor.startMonitoring(context);
115+
116+
return context;
117+
}
118+
119+
@Override
120+
public void stopMonitoring(
121+
@NonNull final MonitorConnectionContext context,
122+
@NonNull Connection connectionToAbort) {
123+
124+
if (context.shouldAbort()) {
125+
context.setInactive();
126+
try {
127+
connectionToAbort.abort(ABORT_EXECUTOR);
128+
connectionToAbort.close();
129+
} catch (final SQLException sqlEx) {
130+
// ignore
131+
if (logger.isTraceEnabled()) {
132+
logger.logTrace(
133+
String.format(
134+
"[efm2.DefaultMonitorService.stopMonitoring]: Exception during aborting connection: %s",
135+
sqlEx.getMessage()));
136+
}
137+
}
138+
} else {
139+
context.setInactive();
140+
}
141+
}
142+
143+
@Override
144+
public void releaseResources() {
145+
// do nothing
146+
}
147+
148+
protected IMonitor getMonitor(
149+
HostInfo hostInfo,
150+
PropertySet propertySet,
151+
final int failureDetectionTimeMillis,
152+
final int failureDetectionIntervalMillis,
153+
final int failureDetectionCount) {
154+
155+
final String monitorKey = String.format("%d:%d:%d:%s",
156+
failureDetectionTimeMillis,
157+
failureDetectionIntervalMillis,
158+
failureDetectionCount,
159+
hostInfo.getHostPortPair());
160+
161+
final long cacheExpirationNano = TimeUnit.MILLISECONDS.toNanos(
162+
propertySet.getIntegerProperty(PropertyKey.monitorDisposalTime).getValue());
163+
164+
return monitors.computeIfAbsent(
165+
monitorKey,
166+
(key) -> monitorInitializer.createMonitor(
167+
hostInfo,
168+
propertySet,
169+
failureDetectionTimeMillis,
170+
failureDetectionIntervalMillis,
171+
failureDetectionCount),
172+
cacheExpirationNano);
173+
}
174+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License, version 2.0
6+
* (GPLv2), as published by the Free Software Foundation, with the
7+
* following additional permissions:
8+
*
9+
* This program is distributed with certain software that is licensed
10+
* under separate terms, as designated in a particular file or component
11+
* or in the license documentation. Without limiting your rights under
12+
* the GPLv2, the authors of this program hereby grant you an additional
13+
* permission to link the program and your derivative works with the
14+
* separately licensed software that they have included with the program.
15+
*
16+
* Without limiting the foregoing grant of rights under the GPLv2 and
17+
* additional permission as to separately licensed software, this
18+
* program is also subject to the Universal FOSS Exception, version 1.0,
19+
* a copy of which can be found along with its FAQ at
20+
* http://oss.oracle.com/licenses/universal-foss-exception.
21+
*
22+
* This program is distributed in the hope that it will be useful, but
23+
* WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25+
* See the GNU General Public License, version 2.0, for more details.
26+
*
27+
* You should have received a copy of the GNU General Public License
28+
* along with this program. If not, see
29+
* http://www.gnu.org/licenses/gpl-2.0.html.
30+
*/
31+
32+
package com.mysql.cj.jdbc.ha.plugins.efm2;
33+
34+
/**
35+
* Interface for monitors. This class uses background threads to monitor servers with one
36+
* or more connections for more efficient failure detection during method execution.
37+
*/
38+
public interface IMonitor extends AutoCloseable, Runnable {
39+
void startMonitoring(MonitorConnectionContext context);
40+
41+
boolean canDispose();
42+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License, version 2.0
6+
* (GPLv2), as published by the Free Software Foundation, with the
7+
* following additional permissions:
8+
*
9+
* This program is distributed with certain software that is licensed
10+
* under separate terms, as designated in a particular file or component
11+
* or in the license documentation. Without limiting your rights under
12+
* the GPLv2, the authors of this program hereby grant you an additional
13+
* permission to link the program and your derivative works with the
14+
* separately licensed software that they have included with the program.
15+
*
16+
* Without limiting the foregoing grant of rights under the GPLv2 and
17+
* additional permission as to separately licensed software, this
18+
* program is also subject to the Universal FOSS Exception, version 1.0,
19+
* a copy of which can be found along with its FAQ at
20+
* http://oss.oracle.com/licenses/universal-foss-exception.
21+
*
22+
* This program is distributed in the hope that it will be useful, but
23+
* WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25+
* See the GNU General Public License, version 2.0, for more details.
26+
*
27+
* You should have received a copy of the GNU General Public License
28+
* along with this program. If not, see
29+
* http://www.gnu.org/licenses/gpl-2.0.html.
30+
*/
31+
32+
package com.mysql.cj.jdbc.ha.plugins.efm2;
33+
34+
import com.mysql.cj.conf.HostInfo;
35+
import com.mysql.cj.conf.PropertySet;
36+
import com.mysql.cj.log.Log;
37+
38+
/**
39+
* Interface for initialize a new {@link Monitor}.
40+
*/
41+
@FunctionalInterface
42+
public interface IMonitorInitializer {
43+
IMonitor createMonitor(
44+
HostInfo hostInfo,
45+
PropertySet propertySet,
46+
final int failureDetectionTimeMillis,
47+
final int failureDetectionIntervalMillis,
48+
final int failureDetectionCount);
49+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License, version 2.0
6+
* (GPLv2), as published by the Free Software Foundation, with the
7+
* following additional permissions:
8+
*
9+
* This program is distributed with certain software that is licensed
10+
* under separate terms, as designated in a particular file or component
11+
* or in the license documentation. Without limiting your rights under
12+
* the GPLv2, the authors of this program hereby grant you an additional
13+
* permission to link the program and your derivative works with the
14+
* separately licensed software that they have included with the program.
15+
*
16+
* Without limiting the foregoing grant of rights under the GPLv2 and
17+
* additional permission as to separately licensed software, this
18+
* program is also subject to the Universal FOSS Exception, version 1.0,
19+
* a copy of which can be found along with its FAQ at
20+
* http://oss.oracle.com/licenses/universal-foss-exception.
21+
*
22+
* This program is distributed in the hope that it will be useful, but
23+
* WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25+
* See the GNU General Public License, version 2.0, for more details.
26+
*
27+
* You should have received a copy of the GNU General Public License
28+
* along with this program. If not, see
29+
* http://www.gnu.org/licenses/gpl-2.0.html.
30+
*/
31+
32+
package com.mysql.cj.jdbc.ha.plugins.efm2;
33+
34+
import com.mysql.cj.conf.HostInfo;
35+
import com.mysql.cj.conf.PropertySet;
36+
import com.mysql.cj.jdbc.JdbcConnection;
37+
38+
import java.sql.Connection;
39+
40+
/**
41+
* Interface for monitor services. This class implements ways to start and stop monitoring
42+
* servers when connections are created.
43+
*/
44+
public interface IMonitorService {
45+
MonitorConnectionContext startMonitoring(
46+
JdbcConnection connectionToAbort,
47+
HostInfo hostInfo,
48+
PropertySet propertySet,
49+
int failureDetectionTimeMillis,
50+
int failureDetectionIntervalMillis,
51+
int failureDetectionCount);
52+
53+
/**
54+
* Stop monitoring for a connection represented by the given {@link MonitorConnectionContext}.
55+
* Removes the context from the {@link IMonitor}.
56+
*
57+
* @param context The {@link MonitorConnectionContext} representing a connection.
58+
*/
59+
void stopMonitoring(MonitorConnectionContext context, Connection connectionToAbort);
60+
61+
void releaseResources();
62+
}

0 commit comments

Comments
 (0)