Skip to content

Commit 8880b0b

Browse files
Implement refactoring improvements and adapt topology and custom endpoint caches and monitors (#1371)
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent e8a99df commit 8880b0b

File tree

144 files changed

+5173
-2581
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+5173
-2581
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
304304
### :magic_wand: Added
305305
- Developer plugin to help test various scenarios including events like network outages and database cluster failover. This plugin is NOT intended to be used in production environments and is only for testing ([PR #531](https://github.com/awslabs/aws-advanced-jdbc-wrapper/pull/531)).
306306
- Documentation:
307-
- Developer plugin. See [UsingTheJdbcDriver](https://github.com/awslabs/aws-advanced-jdbc-wrapper/blob/main/docs/using-the-jdbc-driver/UsingTheJdbcDriver.md#list-of-available-plugins) and [UsingTheDeveloperPlugin](https://github.com/awslabs/aws-advanced-jdbc-wrapper/blob/main/docs/using-the-jdbc-driver/using-plugins/UsingTheDeveloperPlugin.md).
307+
- Developer plugin. See [UsingTheJdbcDriver](https://github.com/aws/aws-advanced-jdbc-wrapper/blob/main/docs/using-the-jdbc-driver/UsingTheJdbcDriver.md#list-of-available-plugins) and [UsingTheDeveloperPlugin](https://github.com/awslabs/aws-advanced-jdbc-wrapper/blob/main/docs/using-the-jdbc-driver/using-plugins/UsingTheDeveloperPlugin.md).
308308
- MySQL code samples ([PR #532](https://github.com/awslabs/aws-advanced-jdbc-wrapper/pull/532)).
309309
- Add a Table of Contents section for the sample codes on README.md. See [README.md](https://github.com/awslabs/aws-advanced-jdbc-wrapper/blob/main/README.md#examples).
310310
- Sample tutorial and code example for Vert.x. See the [tutorial](https://github.com/awslabs/aws-advanced-jdbc-wrapper/blob/main/examples/VertxExample/README.md) and [code example](https://github.com/awslabs/aws-advanced-jdbc-wrapper/blob/main/examples/VertxExample/src/main/java/com/example/starter/MainVerticle.java).

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ You can find our driver by searching in The Central Repository with GroupId and
8686
| `failureDetectionEnabled` | `HostMonitoringConnectionPlugin.FAILURE_DETECTION_ENABLED` | [HostMonitoringPlugin](./docs/using-the-jdbc-driver/using-plugins/UsingTheHostMonitoringPlugin.md) |
8787
| `failureDetectionInterval` | `HostMonitoringConnectionPlugin.FAILURE_DETECTION_INTERVAL` | [HostMonitoringPlugin](./docs/using-the-jdbc-driver/using-plugins/UsingTheHostMonitoringPlugin.md) |
8888
| `failureDetectionTime` | `HostMonitoringConnectionPlugin.FAILURE_DETECTION_TIME` | [HostMonitoringPlugin](./docs/using-the-jdbc-driver/using-plugins/UsingTheHostMonitoringPlugin.md) |
89-
| `monitorDisposalTime` | `MonitorServiceImpl.MONITOR_DISPOSAL_TIME_MS` | [HostMonitoringPlugin](./docs/using-the-jdbc-driver/using-plugins/UsingTheHostMonitoringPlugin.md) |
89+
| `monitorDisposalTime` | `HostMonitorServiceImpl.MONITOR_DISPOSAL_TIME_MS` | [HostMonitoringPlugin](./docs/using-the-jdbc-driver/using-plugins/UsingTheHostMonitoringPlugin.md) |
9090
| `iamDefaultPort` | `IamAuthConnectionPlugin.IAM_DEFAULT_PORT` | [IamAuthenticationPlugin](./docs/using-the-jdbc-driver/using-plugins/UsingTheIamAuthenticationPlugin.md) |
9191
| `iamHost` | `IamAuthConnectionPlugin.IAM_HOST` | [IamAuthenticationPlugin](./docs/using-the-jdbc-driver/using-plugins/UsingTheIamAuthenticationPlugin.md) |
9292
| `iamRegion` | `IamAuthConnectionPlugin.IAM_REGION` | [IamAuthenticationPlugin](./docs/using-the-jdbc-driver/using-plugins/UsingTheIamAuthenticationPlugin.md) |

benchmarks/src/jmh/java/software/amazon/jdbc/benchmarks/ConnectionPluginManagerBenchmarks.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,16 @@
6565
import software.amazon.jdbc.benchmarks.testplugin.BenchmarkPluginFactory;
6666
import software.amazon.jdbc.dialect.Dialect;
6767
import software.amazon.jdbc.hostavailability.SimpleHostAvailabilityStrategy;
68+
import software.amazon.jdbc.profile.ConfigurationProfile;
69+
import software.amazon.jdbc.profile.ConfigurationProfileBuilder;
70+
import software.amazon.jdbc.targetdriverdialect.TargetDriverDialect;
71+
import software.amazon.jdbc.util.FullServicesContainer;
6872
import software.amazon.jdbc.util.telemetry.DefaultTelemetryFactory;
6973
import software.amazon.jdbc.util.telemetry.GaugeCallable;
7074
import software.amazon.jdbc.util.telemetry.TelemetryContext;
7175
import software.amazon.jdbc.util.telemetry.TelemetryCounter;
7276
import software.amazon.jdbc.util.telemetry.TelemetryFactory;
7377
import software.amazon.jdbc.util.telemetry.TelemetryGauge;
74-
import software.amazon.jdbc.profile.ConfigurationProfile;
75-
import software.amazon.jdbc.profile.ConfigurationProfileBuilder;
76-
import software.amazon.jdbc.targetdriverdialect.TargetDriverDialect;
7778
import software.amazon.jdbc.wrapper.ConnectionWrapper;
7879

7980
@State(Scope.Benchmark)
@@ -94,6 +95,7 @@ public class ConnectionPluginManagerBenchmarks {
9495

9596
@Mock ConnectionProvider mockConnectionProvider;
9697
@Mock ConnectionWrapper mockConnectionWrapper;
98+
@Mock FullServicesContainer mockServicesContainer;
9799
@Mock PluginService mockPluginService;
98100
@Mock PluginManagerService mockPluginManagerService;
99101
@Mock TelemetryFactory mockTelemetryFactory;
@@ -138,6 +140,7 @@ public void setUpIteration() throws Exception {
138140
when(mockResultSet.getString(eq(FIELD_SESSION_ID))).thenReturn(WRITER_SESSION_ID);
139141
when(mockResultSet.getString(eq(FIELD_SERVER_ID)))
140142
.thenReturn("myInstance1.domain.com", "myInstance2.domain.com", "myInstance3.domain.com");
143+
when(mockServicesContainer.getPluginService()).thenReturn(mockPluginService);
141144
when(mockPluginService.getCurrentConnection()).thenReturn(mockConnection);
142145
when(mockPluginService.getTelemetryFactory()).thenReturn(mockTelemetryFactory);
143146

@@ -163,11 +166,11 @@ public void setUpIteration() throws Exception {
163166
null,
164167
mockConnectionWrapper,
165168
telemetryFactory);
166-
pluginManager.init(mockPluginService, propertiesWithPlugins, mockPluginManagerService, configurationProfile);
169+
pluginManager.init(mockServicesContainer, propertiesWithPlugins, mockPluginManagerService, configurationProfile);
167170

168171
pluginManagerWithNoPlugins = new ConnectionPluginManager(mockConnectionProvider, null,
169172
mockConnectionWrapper, telemetryFactory);
170-
pluginManagerWithNoPlugins.init(mockPluginService, propertiesWithoutPlugins, mockPluginManagerService, null);
173+
pluginManagerWithNoPlugins.init(mockServicesContainer, propertiesWithoutPlugins, mockPluginManagerService, null);
171174
}
172175

173176
@TearDown(Level.Iteration)
@@ -179,15 +182,15 @@ public void tearDownIteration() throws Exception {
179182
public ConnectionPluginManager initConnectionPluginManagerWithNoPlugins() throws SQLException {
180183
final ConnectionPluginManager manager = new ConnectionPluginManager(mockConnectionProvider, null,
181184
mockConnectionWrapper, mockTelemetryFactory);
182-
manager.init(mockPluginService, propertiesWithoutPlugins, mockPluginManagerService, configurationProfile);
185+
manager.init(mockServicesContainer, propertiesWithoutPlugins, mockPluginManagerService, configurationProfile);
183186
return manager;
184187
}
185188

186189
@Benchmark
187190
public ConnectionPluginManager initConnectionPluginManagerWithPlugins() throws SQLException {
188191
final ConnectionPluginManager manager = new ConnectionPluginManager(mockConnectionProvider, null,
189192
mockConnectionWrapper, mockTelemetryFactory);
190-
manager.init(mockPluginService, propertiesWithPlugins, mockPluginManagerService, configurationProfile);
193+
manager.init(mockServicesContainer, propertiesWithPlugins, mockPluginManagerService, configurationProfile);
191194
return manager;
192195
}
193196

benchmarks/src/jmh/java/software/amazon/jdbc/benchmarks/PluginBenchmarks.java

Lines changed: 35 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
import software.amazon.jdbc.dialect.Dialect;
6464
import software.amazon.jdbc.hostavailability.SimpleHostAvailabilityStrategy;
6565
import software.amazon.jdbc.targetdriverdialect.TargetDriverDialect;
66+
import software.amazon.jdbc.util.connection.ConnectionService;
67+
import software.amazon.jdbc.util.monitoring.MonitorService;
68+
import software.amazon.jdbc.util.storage.StorageService;
6669
import software.amazon.jdbc.util.telemetry.GaugeCallable;
6770
import software.amazon.jdbc.util.telemetry.TelemetryContext;
6871
import software.amazon.jdbc.util.telemetry.TelemetryCounter;
@@ -89,7 +92,11 @@ public class PluginBenchmarks {
8992
private final HostSpec writerHostSpec = new HostSpecBuilder(new SimpleHostAvailabilityStrategy())
9093
.host(TEST_HOST).port(TEST_PORT).build();
9194

95+
@Mock private StorageService mockStorageService;
96+
@Mock private MonitorService mockMonitorService;
97+
@Mock private ConnectionService mockConnectionService;
9298
@Mock private PluginService mockPluginService;
99+
@Mock private TargetDriverDialect mockTargetDriverDialect;
93100
@Mock private Dialect mockDialect;
94101
@Mock private ConnectionPluginManager mockConnectionPluginManager;
95102
@Mock private TelemetryFactory mockTelemetryFactory;
@@ -158,59 +165,48 @@ public void initAndReleaseBaseLine() {
158165

159166
@Benchmark
160167
public ConnectionWrapper initAndReleaseWithExecutionTimePlugin() throws SQLException {
161-
try (ConnectionWrapper wrapper = new TestConnectionWrapper(
162-
useExecutionTimePlugin(),
163-
CONNECTION_STRING,
164-
mockConnectionPluginManager,
165-
mockTelemetryFactory,
166-
mockPluginService,
167-
mockHostListProviderService,
168-
mockPluginManagerService)) {
168+
try (ConnectionWrapper wrapper = getConnectionWrapper(useExecutionTimePlugin(), CONNECTION_STRING)) {
169169
wrapper.releaseResources();
170170
return wrapper;
171171
}
172172
}
173173

174-
@Benchmark
175-
public ConnectionWrapper initAndReleaseWithAuroraHostListPlugin() throws SQLException {
176-
try (ConnectionWrapper wrapper = new TestConnectionWrapper(
177-
useAuroraHostListPlugin(),
178-
CONNECTION_STRING,
174+
private ConnectionWrapper getConnectionWrapper(Properties props, String connString) throws SQLException {
175+
return new TestConnectionWrapper(
176+
props,
177+
connString,
178+
mockConnectionProvider,
179+
mockTargetDriverDialect,
179180
mockConnectionPluginManager,
180181
mockTelemetryFactory,
181182
mockPluginService,
182183
mockHostListProviderService,
183-
mockPluginManagerService)) {
184+
mockPluginManagerService,
185+
mockStorageService,
186+
mockMonitorService,
187+
mockConnectionService);
188+
}
189+
190+
@Benchmark
191+
public ConnectionWrapper initAndReleaseWithAuroraHostListPlugin() throws SQLException {
192+
try (ConnectionWrapper wrapper = getConnectionWrapper(useAuroraHostListPlugin(), CONNECTION_STRING)) {
184193
wrapper.releaseResources();
185194
return wrapper;
186195
}
187196
}
188197

189198
@Benchmark
190199
public ConnectionWrapper initAndReleaseWithExecutionTimeAndAuroraHostListPlugins() throws SQLException {
191-
try (ConnectionWrapper wrapper = new TestConnectionWrapper(
192-
useExecutionTimeAndAuroraHostListPlugins(),
193-
CONNECTION_STRING,
194-
mockConnectionPluginManager,
195-
mockTelemetryFactory,
196-
mockPluginService,
197-
mockHostListProviderService,
198-
mockPluginManagerService)) {
200+
try (ConnectionWrapper wrapper =
201+
getConnectionWrapper(useExecutionTimeAndAuroraHostListPlugins(), CONNECTION_STRING)) {
199202
wrapper.releaseResources();
200203
return wrapper;
201204
}
202205
}
203206

204207
@Benchmark
205208
public ConnectionWrapper initAndReleaseWithReadWriteSplittingPlugin() throws SQLException {
206-
try (ConnectionWrapper wrapper = new TestConnectionWrapper(
207-
useReadWriteSplittingPlugin(),
208-
CONNECTION_STRING,
209-
mockConnectionPluginManager,
210-
mockTelemetryFactory,
211-
mockPluginService,
212-
mockHostListProviderService,
213-
mockPluginManagerService)) {
209+
try (ConnectionWrapper wrapper = getConnectionWrapper(useReadWriteSplittingPlugin(), CONNECTION_STRING)) {
214210
wrapper.releaseResources();
215211
return wrapper;
216212
}
@@ -219,14 +215,8 @@ public ConnectionWrapper initAndReleaseWithReadWriteSplittingPlugin() throws SQL
219215
@Benchmark
220216
public ConnectionWrapper initAndReleaseWithAuroraHostListAndReadWriteSplittingPlugin()
221217
throws SQLException {
222-
try (ConnectionWrapper wrapper = new TestConnectionWrapper(
223-
useAuroraHostListAndReadWriteSplittingPlugin(),
224-
PG_CONNECTION_STRING,
225-
mockConnectionPluginManager,
226-
mockTelemetryFactory,
227-
mockPluginService,
228-
mockHostListProviderService,
229-
mockPluginManagerService)) {
218+
try (ConnectionWrapper wrapper =
219+
getConnectionWrapper(useAuroraHostListAndReadWriteSplittingPlugin(), PG_CONNECTION_STRING)) {
230220
wrapper.releaseResources();
231221
return wrapper;
232222
}
@@ -237,14 +227,7 @@ public ConnectionWrapper initAndReleaseWithReadWriteSplittingPlugin_internalConn
237227
HikariPooledConnectionProvider provider =
238228
new HikariPooledConnectionProvider((hostSpec, props) -> new HikariConfig());
239229
Driver.setCustomConnectionProvider(provider);
240-
try (ConnectionWrapper wrapper = new TestConnectionWrapper(
241-
useReadWriteSplittingPlugin(),
242-
CONNECTION_STRING,
243-
mockConnectionPluginManager,
244-
mockTelemetryFactory,
245-
mockPluginService,
246-
mockHostListProviderService,
247-
mockPluginManagerService)) {
230+
try (ConnectionWrapper wrapper = getConnectionWrapper(useReadWriteSplittingPlugin(), CONNECTION_STRING)) {
248231
wrapper.releaseResources();
249232
ConnectionProviderManager.releaseResources();
250233
Driver.resetCustomConnectionProvider();
@@ -258,14 +241,8 @@ public ConnectionWrapper initAndReleaseWithAuroraHostListAndReadWriteSplittingPl
258241
HikariPooledConnectionProvider provider =
259242
new HikariPooledConnectionProvider((hostSpec, props) -> new HikariConfig());
260243
Driver.setCustomConnectionProvider(provider);
261-
try (ConnectionWrapper wrapper = new TestConnectionWrapper(
262-
useAuroraHostListAndReadWriteSplittingPlugin(),
263-
PG_CONNECTION_STRING,
264-
mockConnectionPluginManager,
265-
mockTelemetryFactory,
266-
mockPluginService,
267-
mockHostListProviderService,
268-
mockPluginManagerService)) {
244+
try (ConnectionWrapper wrapper = getConnectionWrapper(
245+
useAuroraHostListAndReadWriteSplittingPlugin(), PG_CONNECTION_STRING)) {
269246
wrapper.releaseResources();
270247
ConnectionProviderManager.releaseResources();
271248
Driver.resetCustomConnectionProvider();
@@ -275,14 +252,7 @@ public ConnectionWrapper initAndReleaseWithAuroraHostListAndReadWriteSplittingPl
275252

276253
@Benchmark
277254
public Statement executeStatementBaseline() throws SQLException {
278-
try (ConnectionWrapper wrapper = new TestConnectionWrapper(
279-
useExecutionTimePlugin(),
280-
CONNECTION_STRING,
281-
mockConnectionPluginManager,
282-
mockTelemetryFactory,
283-
mockPluginService,
284-
mockHostListProviderService,
285-
mockPluginManagerService);
255+
try (ConnectionWrapper wrapper = getConnectionWrapper(useExecutionTimePlugin(), CONNECTION_STRING);
286256
Statement statement = wrapper.createStatement()) {
287257
return statement;
288258
}
@@ -291,14 +261,7 @@ public Statement executeStatementBaseline() throws SQLException {
291261
@Benchmark
292262
public ResultSet executeStatementWithExecutionTimePlugin() throws SQLException {
293263
try (
294-
ConnectionWrapper wrapper = new TestConnectionWrapper(
295-
useExecutionTimePlugin(),
296-
CONNECTION_STRING,
297-
mockConnectionPluginManager,
298-
mockTelemetryFactory,
299-
mockPluginService,
300-
mockHostListProviderService,
301-
mockPluginManagerService);
264+
ConnectionWrapper wrapper = getConnectionWrapper(useExecutionTimePlugin(), CONNECTION_STRING);
302265
Statement statement = wrapper.createStatement();
303266
ResultSet resultSet = statement.executeQuery("some sql")) {
304267
return resultSet;
@@ -308,14 +271,7 @@ public ResultSet executeStatementWithExecutionTimePlugin() throws SQLException {
308271
@Benchmark
309272
public ResultSet executeStatementWithTelemetryDisabled() throws SQLException {
310273
try (
311-
ConnectionWrapper wrapper = new TestConnectionWrapper(
312-
disabledTelemetry(),
313-
CONNECTION_STRING,
314-
mockConnectionPluginManager,
315-
mockTelemetryFactory,
316-
mockPluginService,
317-
mockHostListProviderService,
318-
mockPluginManagerService);
274+
ConnectionWrapper wrapper = getConnectionWrapper(disabledTelemetry(), CONNECTION_STRING);
319275
Statement statement = wrapper.createStatement();
320276
ResultSet resultSet = statement.executeQuery("some sql")) {
321277
return resultSet;
@@ -325,14 +281,7 @@ public ResultSet executeStatementWithTelemetryDisabled() throws SQLException {
325281
@Benchmark
326282
public ResultSet executeStatementWithTelemetry() throws SQLException {
327283
try (
328-
ConnectionWrapper wrapper = new TestConnectionWrapper(
329-
useTelemetry(),
330-
CONNECTION_STRING,
331-
mockConnectionPluginManager,
332-
mockTelemetryFactory,
333-
mockPluginService,
334-
mockHostListProviderService,
335-
mockPluginManagerService);
284+
ConnectionWrapper wrapper = getConnectionWrapper(useTelemetry(), CONNECTION_STRING);
336285
Statement statement = wrapper.createStatement();
337286
ResultSet resultSet = statement.executeQuery("some sql")) {
338287
return resultSet;

benchmarks/src/jmh/java/software/amazon/jdbc/benchmarks/testplugin/TestConnectionWrapper.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,44 @@
2020
import java.util.Properties;
2121
import org.checkerframework.checker.nullness.qual.NonNull;
2222
import software.amazon.jdbc.ConnectionPluginManager;
23+
import software.amazon.jdbc.ConnectionProvider;
2324
import software.amazon.jdbc.HostListProviderService;
2425
import software.amazon.jdbc.PluginManagerService;
2526
import software.amazon.jdbc.PluginService;
27+
import software.amazon.jdbc.targetdriverdialect.TargetDriverDialect;
28+
import software.amazon.jdbc.util.connection.ConnectionService;
29+
import software.amazon.jdbc.util.monitoring.MonitorService;
30+
import software.amazon.jdbc.util.storage.StorageService;
2631
import software.amazon.jdbc.util.telemetry.TelemetryFactory;
2732
import software.amazon.jdbc.wrapper.ConnectionWrapper;
2833

2934
// Test class allowing for mocks to be used with ConnectionWrapper logic
3035
public class TestConnectionWrapper extends ConnectionWrapper {
3136

32-
public TestConnectionWrapper(@NonNull Properties props,
33-
@NonNull String url,
34-
@NonNull ConnectionPluginManager connectionPluginManager,
37+
public TestConnectionWrapper(
38+
@NonNull final Properties props,
39+
@NonNull final String url,
40+
@NonNull final ConnectionProvider defaultConnectionProvider,
41+
@NonNull final TargetDriverDialect driverDialect,
42+
@NonNull final ConnectionPluginManager connectionPluginManager,
3543
@NonNull final TelemetryFactory telemetryFactory,
36-
@NonNull PluginService pluginService,
37-
@NonNull HostListProviderService hostListProviderService,
38-
@NonNull PluginManagerService pluginManagerService)
44+
@NonNull final PluginService pluginService,
45+
@NonNull final HostListProviderService hostListProviderService,
46+
@NonNull final PluginManagerService pluginManagerService,
47+
@NonNull final StorageService storageService,
48+
@NonNull final MonitorService monitorService,
49+
@NonNull final ConnectionService connectionService)
3950
throws SQLException {
40-
super(props, url, connectionPluginManager, telemetryFactory, pluginService, hostListProviderService,
41-
pluginManagerService);
51+
super(
52+
props,
53+
url,
54+
defaultConnectionProvider,
55+
driverDialect,
56+
connectionPluginManager,
57+
telemetryFactory,
58+
pluginService,
59+
hostListProviderService,
60+
pluginManagerService,
61+
storageService, monitorService, connectionService);
4262
}
4363
}

0 commit comments

Comments
 (0)