Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -227,7 +227,7 @@ Connection forceConnect(

void updateDialect(final @NonNull Connection connection) throws SQLException;

HostSpec identifyConnection(final Connection connection) throws SQLException;
@Nullable HostSpec identifyConnection(final Connection connection) throws SQLException;

void fillAliases(final Connection connection, final HostSpec hostSpec) throws SQLException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
package software.amazon.jdbc.hostlistprovider;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.logging.Logger;
import org.checkerframework.checker.nullness.qual.NonNull;
import software.amazon.jdbc.AwsWrapperProperty;
import software.amazon.jdbc.HostListProviderService;
Expand All @@ -35,6 +33,8 @@

public class ConnectionStringHostListProvider implements StaticHostListProvider {

private static final Logger LOGGER = Logger.getLogger(ConnectionStringHostListProvider.class.getName());

final List<HostSpec> hostList = new ArrayList<>();
Properties properties;
private boolean isInitialized = false;
Expand Down Expand Up @@ -115,8 +115,8 @@ public HostRole getHostRole(Connection connection) {

@Override
public HostSpec identifyConnection(Connection connection) throws SQLException {
throw new UnsupportedOperationException(
Messages.get("ConnectionStringHostListProvider.unsupportedIdentifyConnection"));
LOGGER.finest(Messages.get("ConnectionStringHostListProvider.unsupportedIdentifyConnection"));
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public Connection connect(final String driverProtocol, final HostSpec hostSpec,

if (conn != null) {
final RdsUrlType type = this.rdsHelper.identifyRdsType(hostSpec.getHost());
if (type.isRdsCluster() || type == RdsUrlType.OTHER) {
if (type.isRdsCluster() || type == RdsUrlType.OTHER || type == RdsUrlType.IP_ADDRESS) {
hostSpec.resetAliases();
this.pluginService.fillAliases(conn, hostSpec);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private Connection getVerifiedWriterConnection(
this.pluginService.forceRefreshHostList(writerCandidateConn);
writerCandidate = this.pluginService.identifyConnection(writerCandidateConn);

if (writerCandidate.getRole() != HostRole.WRITER) {
if (writerCandidate == null || writerCandidate.getRole() != HostRole.WRITER) {
// Shouldn't be here. But let's try again.
this.closeConnection(writerCandidateConn);
this.delay(retryDelayMs);
Expand Down Expand Up @@ -273,6 +273,12 @@ private Connection getVerifiedReaderConnection(
this.pluginService.forceRefreshHostList(readerCandidateConn);
readerCandidate = this.pluginService.identifyConnection(readerCandidateConn);

if (readerCandidate == null) {
this.closeConnection(readerCandidateConn);
this.delay(retryDelayMs);
continue;
}

if (readerCandidate.getRole() != HostRole.READER) {
if (this.hasNoReaders()) {
// It seems that cluster has no readers. Simulate Aurora reader cluster endpoint logic
Expand Down
Loading