Skip to content

Commit e5af82c

Browse files
authored
fix outdated topology during B/G switchover caused wrong connection failover (#1599)
1 parent 7ec7b8e commit e5af82c

File tree

42 files changed

+673
-279
lines changed

Some content is hidden

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

42 files changed

+673
-279
lines changed

docs/using-the-jdbc-driver/using-plugins/UsingTheBlueGreenPlugin.md

Lines changed: 35 additions & 32 deletions
Large diffs are not rendered by default.

wrapper/src/main/java/software/amazon/jdbc/Driver.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import software.amazon.jdbc.util.ServiceUtility;
6666
import software.amazon.jdbc.util.StringUtils;
6767
import software.amazon.jdbc.util.WrapperUtils;
68+
import software.amazon.jdbc.util.events.EventPublisher;
6869
import software.amazon.jdbc.util.monitoring.MonitorService;
6970
import software.amazon.jdbc.util.storage.StorageService;
7071
import software.amazon.jdbc.util.telemetry.DefaultTelemetryFactory;
@@ -110,6 +111,7 @@ public class Driver implements java.sql.Driver {
110111

111112
private final StorageService storageService;
112113
private final MonitorService monitorService;
114+
private final EventPublisher eventPublisher;
113115
private final ConnectionUrlParser urlParser = new ConnectionUrlParser();
114116

115117
public Driver() {
@@ -119,6 +121,7 @@ public Driver() {
119121
public Driver(CoreServicesContainer coreServicesContainer) {
120122
this.storageService = coreServicesContainer.getStorageService();
121123
this.monitorService = coreServicesContainer.getMonitorService();
124+
this.eventPublisher = coreServicesContainer.getEventPublisher();
122125
}
123126

124127
public static void register() throws SQLException {
@@ -242,8 +245,9 @@ public Connection connect(final String url, final Properties info) throws SQLExc
242245

243246
String targetDriverProtocol = urlParser.getProtocol(driverUrl);
244247
FullServicesContainer servicesContainer = ServiceUtility.getInstance().createStandardServiceContainer(
245-
storageService,
246-
monitorService,
248+
this.storageService,
249+
this.monitorService,
250+
this.eventPublisher,
247251
defaultConnectionProvider,
248252
effectiveConnectionProvider,
249253
telemetryFactory,

wrapper/src/main/java/software/amazon/jdbc/PartialPluginService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Set;
3131
import java.util.concurrent.TimeUnit;
3232
import java.util.concurrent.TimeoutException;
33+
import java.util.logging.Level;
3334
import java.util.logging.Logger;
3435
import java.util.stream.Collectors;
3536
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -57,10 +58,11 @@
5758
* by the {@link PluginService} interface. The methods that are not expected to be called will log a warning or throw an
5859
* {@link UnsupportedOperationException} when called.
5960
*/
61+
@SuppressWarnings("deprecation")
6062
public class PartialPluginService implements PluginService, CanReleaseResources, HostListProviderService,
6163
PluginManagerService {
6264

63-
private static final Logger LOGGER = Logger.getLogger(PluginServiceImpl.class.getName());
65+
private static final Logger LOGGER = Logger.getLogger(PartialPluginService.class.getName());
6466
protected static final long DEFAULT_HOST_AVAILABILITY_CACHE_EXPIRE_NANO = TimeUnit.MINUTES.toNanos(5);
6567

6668
protected static final CacheMap<String, HostAvailability> hostAvailabilityExpiringCache = new CacheMap<>();
@@ -623,7 +625,7 @@ public void fillAliases(Connection connection, HostSpec hostSpec) throws SQLExce
623625
}
624626
} catch (final SQLException sqlException) {
625627
// log and ignore
626-
LOGGER.finest(() -> Messages.get("PluginServiceImpl.failedToRetrieveHostPort"));
628+
LOGGER.log(Level.FINEST, sqlException, () -> Messages.get("PluginServiceImpl.failedToRetrieveHostPort"));
627629
}
628630

629631
// Add the instance endpoint if the current connection is associated with a topology aware database cluster.

wrapper/src/main/java/software/amazon/jdbc/PluginServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.concurrent.TimeUnit;
3434
import java.util.concurrent.TimeoutException;
3535
import java.util.concurrent.locks.ReentrantLock;
36+
import java.util.logging.Level;
3637
import java.util.logging.Logger;
3738
import java.util.stream.Collectors;
3839
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -759,7 +760,7 @@ public void fillAliases(Connection connection, HostSpec hostSpec) throws SQLExce
759760
}
760761
} catch (final SQLException sqlException) {
761762
// log and ignore
762-
LOGGER.finest(() -> Messages.get("PluginServiceImpl.failedToRetrieveHostPort"));
763+
LOGGER.log(Level.FINEST, sqlException, () -> Messages.get("PluginServiceImpl.failedToRetrieveHostPort"));
763764
}
764765

765766
// Add the instance endpoint if the current connection is associated with a topology aware database cluster.

wrapper/src/main/java/software/amazon/jdbc/ds/AwsWrapperDataSource.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import software.amazon.jdbc.util.SqlState;
5656
import software.amazon.jdbc.util.StringUtils;
5757
import software.amazon.jdbc.util.WrapperUtils;
58+
import software.amazon.jdbc.util.events.EventPublisher;
5859
import software.amazon.jdbc.util.monitoring.MonitorService;
5960
import software.amazon.jdbc.util.storage.StorageService;
6061
import software.amazon.jdbc.util.telemetry.DefaultTelemetryFactory;
@@ -75,6 +76,7 @@ public class AwsWrapperDataSource implements DataSource, Referenceable, Serializ
7576
private final ConnectionUrlParser urlParser = new ConnectionUrlParser();
7677
private final StorageService storageService;
7778
private final MonitorService monitorService;
79+
private final EventPublisher eventPublisher;
7880

7981
static {
8082
try {
@@ -105,6 +107,7 @@ public AwsWrapperDataSource() {
105107
public AwsWrapperDataSource(CoreServicesContainer coreServicesContainer) {
106108
this.storageService = coreServicesContainer.getStorageService();
107109
this.monitorService = coreServicesContainer.getMonitorService();
110+
this.eventPublisher = coreServicesContainer.getEventPublisher();
108111
}
109112

110113
@Override
@@ -284,8 +287,9 @@ ConnectionWrapper createConnectionWrapper(
284287
final TelemetryFactory telemetryFactory) throws SQLException {
285288
String targetProtocol = this.urlParser.getProtocol(url);
286289
FullServicesContainer servicesContainer = ServiceUtility.getInstance().createStandardServiceContainer(
287-
storageService,
288-
monitorService,
290+
this.storageService,
291+
this.monitorService,
292+
this.eventPublisher,
289293
defaultProvider,
290294
effectiveProvider,
291295
telemetryFactory,

wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/ClusterTopologyMonitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
import java.util.concurrent.TimeoutException;
2323
import org.checkerframework.checker.nullness.qual.Nullable;
2424
import software.amazon.jdbc.HostSpec;
25+
import software.amazon.jdbc.util.events.EventSubscriber;
2526
import software.amazon.jdbc.util.monitoring.Monitor;
2627

27-
public interface ClusterTopologyMonitor extends Monitor {
28+
public interface ClusterTopologyMonitor extends Monitor, EventSubscriber {
2829

2930
boolean canDispose();
3031

0 commit comments

Comments
 (0)