Skip to content

[WIP] Implement refactoring changes #1286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 57 commits into
base: refactoring-wip
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
6ec4c3d
First implementation of CacheService and MonitorService complete
aaron-congo Feb 5, 2025
184b68a
wip
aaron-congo Feb 5, 2025
2ddebce
Merge branch 'refactoring-wip' into refactoring
aaron-congo Feb 5, 2025
053dd75
Merge branch 'refactoring-wip' into refactoring
aaron-congo Feb 7, 2025
4437581
Merge branch 'refactoring' into refactoring-wip
aaron-congo Feb 7, 2025
a12410f
wip
aaron-congo Feb 7, 2025
3e17520
PR comments
aaron-congo Feb 7, 2025
e35d740
Merge branch 'refactoring-wip' into refactoring
aaron-congo Feb 7, 2025
07b36fc
Implemented ExpirationCache and StorageServiceImpl
aaron-congo Feb 11, 2025
8bfbd4f
Replaced topologyCache with StorageService
aaron-congo Feb 12, 2025
f7ef88f
Error when passing Topology.class as the itemClass
aaron-congo Feb 12, 2025
53a1429
Added itemClass parameter to get() method
aaron-congo Feb 13, 2025
5d3f698
Failover integration test passing
aaron-congo Feb 13, 2025
8b3e30e
Remove MonitorGroup and MonitorServiceImpl
aaron-congo Feb 13, 2025
a9041ae
Instantiate StorageService in Driver class
aaron-congo Feb 14, 2025
afd7a56
cleanup
aaron-congo Feb 14, 2025
98d6dff
ExpiringCache fixes
aaron-congo Feb 14, 2025
bc83286
Merge branch 'refactoring-wip' into storage-service
aaron-congo Feb 14, 2025
e0af969
Fix build errors
aaron-congo Feb 15, 2025
472c793
cleanup
aaron-congo Feb 18, 2025
a516492
cleanup
aaron-congo Feb 18, 2025
2107add
PR comments
aaron-congo Feb 18, 2025
55e3eec
Cleanup, gradle check passing
aaron-congo Feb 19, 2025
b12c200
Lazily auto-register default caches
aaron-congo Feb 19, 2025
34aaadb
Move cleanup thread to StorageServiceImpl
aaron-congo Feb 21, 2025
5e03973
Minor fixes, cleanup
aaron-congo Feb 21, 2025
4cd7117
Add log to cleanup thread
aaron-congo Feb 21, 2025
da8e939
Adjust default cleanup time
aaron-congo Feb 21, 2025
a1794ec
Replace custom endpoint storage
aaron-congo Feb 24, 2025
dcad5c3
Implement ServiceContainer
aaron-congo Feb 26, 2025
bd92538
Cleanup
aaron-congo Feb 26, 2025
0c2b548
MonitorServiceImpl wip
aaron-congo Feb 27, 2025
e7f0ae2
Make CacheItem protected
aaron-congo Feb 28, 2025
1ece19d
Remove cleanupInterval from ExpirationCache
aaron-congo Feb 28, 2025
f4390ca
MonitorServiceImpl with MonitorItem
aaron-congo Feb 28, 2025
e06375a
MonitorServiceImpl wip
aaron-congo Mar 3, 2025
e8a8820
Implemented inactive timeout, AbstractMonitor
aaron-congo Mar 4, 2025
bef3657
Implement default registration
aaron-congo Mar 4, 2025
b05c6f4
replace commented out default suppliers with TODO
aaron-congo Mar 5, 2025
f647219
Auto-register default monitor types if missing
aaron-congo Mar 5, 2025
01014b4
PR comments, fix missing monitor error processing
aaron-congo Mar 5, 2025
2cd5869
Added CacheContainer
aaron-congo Mar 6, 2025
497b648
Implement ExternallyManagedCache
aaron-congo Mar 6, 2025
c99243d
Add removeIf() method
aaron-congo Mar 7, 2025
7d6b0f0
Cleanup MonitorServiceImpl and fix minor issues
aaron-congo Mar 7, 2025
eb8f45d
Remove monitor if expired
aaron-congo Mar 7, 2025
7261a6b
Add MonitorService to ServiceContainer, adapt CustomEndpointMonitor t…
aaron-congo Mar 10, 2025
bd04054
Use defaultSuppliers
aaron-congo Mar 11, 2025
381d9c6
MonitorService starts the monitor
aaron-congo Mar 11, 2025
a56acce
Implement data access messages
aaron-congo Mar 11, 2025
0d7e117
Remove ItemCategory argument in StorageService
aaron-congo Mar 12, 2025
1f36aec
Small fixes, cleanup, update docs
aaron-congo Mar 12, 2025
eb48888
Remove isRenewableExpiration option for ExternallyManagedCache, cleanup
aaron-congo Mar 14, 2025
77139f5
Adapt topology monitors to monitor service
aaron-congo Apr 15, 2025
d943913
Undo changes to integration test files
aaron-congo Apr 16, 2025
7edb822
Fix checkstyle error
aaron-congo Apr 16, 2025
a984864
Merge branch 'refactoring-wip' into storage-service
aaron-congo Apr 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
import software.amazon.jdbc.dialect.Dialect;
import software.amazon.jdbc.hostavailability.SimpleHostAvailabilityStrategy;
import software.amazon.jdbc.targetdriverdialect.TargetDriverDialect;
import software.amazon.jdbc.util.storage.StorageService;
import software.amazon.jdbc.util.storage.StorageServiceImpl;
import software.amazon.jdbc.util.telemetry.GaugeCallable;
import software.amazon.jdbc.util.telemetry.TelemetryContext;
import software.amazon.jdbc.util.telemetry.TelemetryCounter;
Expand All @@ -85,6 +87,7 @@ public class PluginBenchmarks {
"jdbc:aws-wrapper:postgresql://instance-0.XYZ.us-east-2.rds.amazonaws.com";
private static final String TEST_HOST = "instance-0";
private static final int TEST_PORT = 5432;
private static final StorageService storageService = new StorageServiceImpl();
private final HostSpec writerHostSpec = new HostSpecBuilder(new SimpleHostAvailabilityStrategy())
.host(TEST_HOST).port(TEST_PORT).build();

Expand Down Expand Up @@ -164,7 +167,8 @@ public ConnectionWrapper initAndReleaseWithExecutionTimePlugin() throws SQLExcep
mockTelemetryFactory,
mockPluginService,
mockHostListProviderService,
mockPluginManagerService)) {
mockPluginManagerService,
storageService)) {
wrapper.releaseResources();
return wrapper;
}
Expand All @@ -179,7 +183,8 @@ public ConnectionWrapper initAndReleaseWithAuroraHostListPlugin() throws SQLExce
mockTelemetryFactory,
mockPluginService,
mockHostListProviderService,
mockPluginManagerService)) {
mockPluginManagerService,
storageService)) {
wrapper.releaseResources();
return wrapper;
}
Expand All @@ -194,7 +199,8 @@ public ConnectionWrapper initAndReleaseWithExecutionTimeAndAuroraHostListPlugins
mockTelemetryFactory,
mockPluginService,
mockHostListProviderService,
mockPluginManagerService)) {
mockPluginManagerService,
storageService)) {
wrapper.releaseResources();
return wrapper;
}
Expand All @@ -209,7 +215,8 @@ public ConnectionWrapper initAndReleaseWithReadWriteSplittingPlugin() throws SQL
mockTelemetryFactory,
mockPluginService,
mockHostListProviderService,
mockPluginManagerService)) {
mockPluginManagerService,
storageService)) {
wrapper.releaseResources();
return wrapper;
}
Expand All @@ -225,7 +232,8 @@ public ConnectionWrapper initAndReleaseWithAuroraHostListAndReadWriteSplittingPl
mockTelemetryFactory,
mockPluginService,
mockHostListProviderService,
mockPluginManagerService)) {
mockPluginManagerService,
storageService)) {
wrapper.releaseResources();
return wrapper;
}
Expand All @@ -243,7 +251,8 @@ public ConnectionWrapper initAndReleaseWithReadWriteSplittingPlugin_internalConn
mockTelemetryFactory,
mockPluginService,
mockHostListProviderService,
mockPluginManagerService)) {
mockPluginManagerService,
storageService)) {
wrapper.releaseResources();
ConnectionProviderManager.releaseResources();
Driver.resetCustomConnectionProvider();
Expand All @@ -264,7 +273,8 @@ public ConnectionWrapper initAndReleaseWithAuroraHostListAndReadWriteSplittingPl
mockTelemetryFactory,
mockPluginService,
mockHostListProviderService,
mockPluginManagerService)) {
mockPluginManagerService,
storageService)) {
wrapper.releaseResources();
ConnectionProviderManager.releaseResources();
Driver.resetCustomConnectionProvider();
Expand All @@ -281,7 +291,8 @@ public Statement executeStatementBaseline() throws SQLException {
mockTelemetryFactory,
mockPluginService,
mockHostListProviderService,
mockPluginManagerService);
mockPluginManagerService,
storageService);
Statement statement = wrapper.createStatement()) {
return statement;
}
Expand All @@ -297,7 +308,8 @@ public ResultSet executeStatementWithExecutionTimePlugin() throws SQLException {
mockTelemetryFactory,
mockPluginService,
mockHostListProviderService,
mockPluginManagerService);
mockPluginManagerService,
storageService);
Statement statement = wrapper.createStatement();
ResultSet resultSet = statement.executeQuery("some sql")) {
return resultSet;
Expand All @@ -314,7 +326,8 @@ public ResultSet executeStatementWithTelemetryDisabled() throws SQLException {
mockTelemetryFactory,
mockPluginService,
mockHostListProviderService,
mockPluginManagerService);
mockPluginManagerService,
storageService);
Statement statement = wrapper.createStatement();
ResultSet resultSet = statement.executeQuery("some sql")) {
return resultSet;
Expand All @@ -331,7 +344,8 @@ public ResultSet executeStatementWithTelemetry() throws SQLException {
mockTelemetryFactory,
mockPluginService,
mockHostListProviderService,
mockPluginManagerService);
mockPluginManagerService,
storageService);
Statement statement = wrapper.createStatement();
ResultSet resultSet = statement.executeQuery("some sql")) {
return resultSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import software.amazon.jdbc.HostListProviderService;
import software.amazon.jdbc.PluginManagerService;
import software.amazon.jdbc.PluginService;
import software.amazon.jdbc.util.storage.StorageService;
import software.amazon.jdbc.util.telemetry.TelemetryFactory;
import software.amazon.jdbc.wrapper.ConnectionWrapper;

Expand All @@ -35,9 +36,10 @@ public TestConnectionWrapper(@NonNull Properties props,
@NonNull final TelemetryFactory telemetryFactory,
@NonNull PluginService pluginService,
@NonNull HostListProviderService hostListProviderService,
@NonNull PluginManagerService pluginManagerService)
@NonNull PluginManagerService pluginManagerService,
@NonNull StorageService storageService)
throws SQLException {
super(props, url, connectionPluginManager, telemetryFactory, pluginService, hostListProviderService,
pluginManagerService);
pluginManagerService, storageService);
}
}
17 changes: 17 additions & 0 deletions wrapper/src/main/java/software/amazon/jdbc/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.logging.ConsoleHandler;
Expand Down Expand Up @@ -64,6 +65,10 @@
import software.amazon.jdbc.util.PropertyUtils;
import software.amazon.jdbc.util.RdsUtils;
import software.amazon.jdbc.util.StringUtils;
import software.amazon.jdbc.util.storage.ItemCategory;
import software.amazon.jdbc.util.storage.StorageService;
import software.amazon.jdbc.util.storage.StorageServiceImpl;
import software.amazon.jdbc.util.storage.Topology;
import software.amazon.jdbc.util.telemetry.DefaultTelemetryFactory;
import software.amazon.jdbc.util.telemetry.TelemetryContext;
import software.amazon.jdbc.util.telemetry.TelemetryFactory;
Expand All @@ -77,6 +82,8 @@ public class Driver implements java.sql.Driver {
private static final Logger LOGGER = Logger.getLogger("software.amazon.jdbc.Driver");
private static @Nullable Driver registeredDriver;

private static final StorageService storageService = new StorageServiceImpl();

private static final AtomicReference<ResetSessionStateOnCloseCallable> resetSessionStateOnCloseCallable =
new AtomicReference<>(null);
private static final AtomicReference<TransferSessionStateOnSwitchCallable> transferSessionStateOnSwitchCallable =
Expand Down Expand Up @@ -113,6 +120,15 @@ public static void register() throws SQLException {
final Driver driver = new Driver();
DriverManager.registerDriver(driver);
registeredDriver = driver;

storageService.registerItemCategoryIfAbsent(
ItemCategory.TOPOLOGY,
Topology.class,
false,
TimeUnit.MINUTES.toNanos(10),
TimeUnit.MINUTES.toNanos(5),
null,
null);
}

public static void deregister() throws SQLException {
Expand Down Expand Up @@ -388,6 +404,7 @@ public static void resetConnectionInitFunc() {
}

public static void clearCaches() {
storageService.clearAll();
RdsUtils.clearCache();
RdsHostListProvider.clearAll();
PluginServiceImpl.clearCache();
Expand Down
13 changes: 11 additions & 2 deletions wrapper/src/main/java/software/amazon/jdbc/PluginServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import software.amazon.jdbc.util.CacheMap;
import software.amazon.jdbc.util.Messages;
import software.amazon.jdbc.util.Utils;
import software.amazon.jdbc.util.storage.StorageService;
import software.amazon.jdbc.util.telemetry.TelemetryFactory;

public class PluginServiceImpl implements PluginService, CanReleaseResources,
Expand All @@ -64,6 +65,7 @@ public class PluginServiceImpl implements PluginService, CanReleaseResources,

protected static final CacheMap<String, HostAvailability> hostAvailabilityExpiringCache = new CacheMap<>();
protected final ConnectionPluginManager pluginManager;
protected final StorageService storageService;
private final Properties props;
private final String originalUrl;
private final String driverProtocol;
Expand Down Expand Up @@ -91,7 +93,8 @@ public PluginServiceImpl(
@NonNull final Properties props,
@NonNull final String originalUrl,
@NonNull final String targetDriverProtocol,
@NonNull final TargetDriverDialect targetDriverDialect)
@NonNull final TargetDriverDialect targetDriverDialect,
@NonNull final StorageService storageService)
throws SQLException {

this(pluginManager,
Expand All @@ -101,6 +104,7 @@ public PluginServiceImpl(
targetDriverProtocol,
null,
targetDriverDialect,
storageService,
null,
null);
}
Expand All @@ -111,6 +115,7 @@ public PluginServiceImpl(
@NonNull final String originalUrl,
@NonNull final String targetDriverProtocol,
@NonNull final TargetDriverDialect targetDriverDialect,
@NonNull final StorageService storageService,
@Nullable final ConfigurationProfile configurationProfile) throws SQLException {
this(pluginManager,
new ExceptionManager(),
Expand All @@ -119,6 +124,7 @@ public PluginServiceImpl(
targetDriverProtocol,
null,
targetDriverDialect,
storageService,
configurationProfile,
null);
}
Expand All @@ -131,6 +137,7 @@ public PluginServiceImpl(
@NonNull final String targetDriverProtocol,
@Nullable final DialectProvider dialectProvider,
@NonNull final TargetDriverDialect targetDriverDialect,
@NonNull final StorageService storageService,
@Nullable final ConfigurationProfile configurationProfile,
@Nullable final SessionStateService sessionStateService) throws SQLException {
this.pluginManager = pluginManager;
Expand All @@ -141,6 +148,7 @@ public PluginServiceImpl(
this.exceptionManager = exceptionManager;
this.dialectProvider = dialectProvider != null ? dialectProvider : new DialectManager(this);
this.targetDriverDialect = targetDriverDialect;
this.storageService = storageService;
this.connectionProviderManager = new ConnectionProviderManager(
this.pluginManager.getDefaultConnProvider(),
this.pluginManager.getEffectiveConnProvider());
Expand Down Expand Up @@ -705,7 +713,8 @@ public void updateDialect(final @NonNull Connection connection) throws SQLExcept
}

final HostListProviderSupplier supplier = this.dialect.getHostListProvider();
this.setHostListProvider(supplier.getProvider(props, this.originalUrl, this, this));
this.setHostListProvider(supplier.getProvider(
this.props, this.originalUrl, this, this, this.storageService));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public boolean isDialect(final Connection connection) {

@Override
public HostListProviderSupplier getHostListProvider() {
return (properties, initialUrl, hostListProviderService, pluginService) -> {
return (properties, initialUrl, hostListProviderService, pluginService, storageService) -> {

final FailoverConnectionPlugin failover2Plugin = pluginService.getPlugin(FailoverConnectionPlugin.class);

Expand All @@ -90,6 +90,7 @@ public HostListProviderSupplier getHostListProvider() {
properties,
initialUrl,
hostListProviderService,
storageService,
TOPOLOGY_QUERY,
NODE_ID_QUERY,
IS_READER_QUERY,
Expand All @@ -100,6 +101,7 @@ public HostListProviderSupplier getHostListProvider() {
properties,
initialUrl,
hostListProviderService,
storageService,
TOPOLOGY_QUERY,
NODE_ID_QUERY,
IS_READER_QUERY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean isDialect(final Connection connection) {

@Override
public HostListProviderSupplier getHostListProvider() {
return (properties, initialUrl, hostListProviderService, pluginService) -> {
return (properties, initialUrl, hostListProviderService, pluginService, storageService) -> {

final FailoverConnectionPlugin failover2Plugin = pluginService.getPlugin(FailoverConnectionPlugin.class);

Expand All @@ -136,6 +136,7 @@ public HostListProviderSupplier getHostListProvider() {
properties,
initialUrl,
hostListProviderService,
storageService,
TOPOLOGY_QUERY,
NODE_ID_QUERY,
IS_READER_QUERY,
Expand All @@ -146,6 +147,7 @@ public HostListProviderSupplier getHostListProvider() {
properties,
initialUrl,
hostListProviderService,
storageService,
TOPOLOGY_QUERY,
NODE_ID_QUERY,
IS_READER_QUERY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
import software.amazon.jdbc.HostListProvider;
import software.amazon.jdbc.HostListProviderService;
import software.amazon.jdbc.PluginService;
import software.amazon.jdbc.util.storage.StorageService;

@FunctionalInterface
public interface HostListProviderSupplier {
@NonNull HostListProvider getProvider(
final @NonNull Properties properties,
final String initialUrl,
final @NonNull HostListProviderService hostListProviderService,
final @NonNull PluginService pluginService);
final @NonNull PluginService pluginService,
final @NonNull StorageService storageService);
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public List<String> getDialectUpdateCandidates() {
}

public HostListProviderSupplier getHostListProvider() {
return (properties, initialUrl, hostListProviderService, pluginService) ->
return (properties, initialUrl, hostListProviderService, pluginService, storageService) ->
new ConnectionStringHostListProvider(properties, initialUrl, hostListProviderService);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public List<String> getDialectUpdateCandidates() {
}

public HostListProviderSupplier getHostListProvider() {
return (properties, initialUrl, hostListProviderService, pluginService) ->
return (properties, initialUrl, hostListProviderService, pluginService, storageService) ->
new ConnectionStringHostListProvider(properties, initialUrl, hostListProviderService);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public List<String> getDialectUpdateCandidates() {

@Override
public HostListProviderSupplier getHostListProvider() {
return (properties, initialUrl, hostListProviderService, pluginService) ->
return (properties, initialUrl, hostListProviderService, pluginService, storageService) ->
new ConnectionStringHostListProvider(properties, initialUrl, hostListProviderService);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public boolean isDialect(final Connection connection) {

@Override
public HostListProviderSupplier getHostListProvider() {
return (properties, initialUrl, hostListProviderService, pluginService) -> {
return (properties, initialUrl, hostListProviderService, pluginService, storageService) -> {

final FailoverConnectionPlugin failover2Plugin = pluginService.getPlugin(FailoverConnectionPlugin.class);

Expand All @@ -105,6 +105,7 @@ public HostListProviderSupplier getHostListProvider() {
properties,
initialUrl,
hostListProviderService,
storageService,
TOPOLOGY_QUERY,
NODE_ID_QUERY,
IS_READER_QUERY,
Expand All @@ -117,6 +118,7 @@ public HostListProviderSupplier getHostListProvider() {
properties,
initialUrl,
hostListProviderService,
storageService,
TOPOLOGY_QUERY,
NODE_ID_QUERY,
IS_READER_QUERY,
Expand Down
Loading
Loading