Skip to content

Commit

Permalink
[CONJ-1118] Aurora Single Write Cluster Endpoint doesn't connect replica
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Oct 27, 2023
1 parent 32df385 commit 0a10408
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public void reconnectFailedConnection(SearchFilter initialSearchFilter) throws S
|| (urlParser.getOptions().allowMasterDownConnection && secondaryProtocol != null)));
}

// When reconnecting, search if replicas list has change since first initialisation
// When reconnecting, search if replicas list has changed since first initialisation
if (getCurrentProtocol() != null && !getCurrentProtocol().isClosed()) {
retrieveAllEndpointsAndSet(getCurrentProtocol());
}
Expand All @@ -239,14 +239,16 @@ public void reconnectFailedConnection(SearchFilter initialSearchFilter) throws S
* instance identifiers and sets urlParser accordingly.
*
* @param protocol current protocol connected to
* @return host address list
* @throws SQLException if connection error occur
*/
public void retrieveAllEndpointsAndSet(Protocol protocol) throws SQLException {
public List<HostAddress> retrieveAllEndpointsAndSet(Protocol protocol) throws SQLException {
// For a given cluster, same port for all endpoints and same end host address
if (clusterDnsSuffix != null) {
List<String> endpoints = getCurrentEndpointIdentifiers(protocol);
setUrlParserFromEndpoints(endpoints, protocol.getPort());
}
return hostAddresses;
}

/**
Expand Down Expand Up @@ -304,8 +306,9 @@ private List<String> getCurrentEndpointIdentifiers(Protocol protocol) throws SQL
*
* @param endpoints instance identifiers
* @param port port that is common to all endpoints
* @return list of host addresses
*/
private void setUrlParserFromEndpoints(List<String> endpoints, int port) {
private List<HostAddress> setUrlParserFromEndpoints(List<String> endpoints, int port) {
List<HostAddress> addresses = new ArrayList<>();
for (String endpoint : endpoints) {
if (endpoint != null) {
Expand All @@ -316,6 +319,7 @@ private void setUrlParserFromEndpoints(List<String> endpoints, int port) {
addresses.addAll(urlParser.getHostAddresses());
}
hostAddresses = addresses;
return hostAddresses;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ public static void loop(
if (searchFilter.isFineIfFoundOnlyMaster()
&& listener.getUrlParser().getHostAddresses().size() <= 1
&& protocol.getHostAddress().equals(listener.getClusterHostAddress())) {
listener.retrieveAllEndpointsAndSet(protocol);
List<HostAddress> hostAddresses = listener.retrieveAllEndpointsAndSet(protocol);

if (listener.getUrlParser().getHostAddresses().size() > 1) {
if (hostAddresses.size() > 1) {
// add newly discovered end-point to loop
loopAddresses.addAll(listener.getUrlParser().getHostAddresses());
loopAddresses.addAll(hostAddresses);
// since there is more than one end point, reactivate connection to a read-only host
searchFilter = new SearchFilter(false);
}
Expand All @@ -200,11 +200,11 @@ public static void loop(
// in case cluster DNS is currently pointing to a replica host
if (listener.getUrlParser().getHostAddresses().size() <= 1
&& protocol.getHostAddress().equals(listener.getClusterHostAddress())) {
listener.retrieveAllEndpointsAndSet(protocol);
List<HostAddress> hostAddresses = listener.retrieveAllEndpointsAndSet(protocol);

if (listener.getUrlParser().getHostAddresses().size() > 1) {
if (hostAddresses.size() > 1) {
// add newly discovered end-point to loop
loopAddresses.addAll(listener.getUrlParser().getHostAddresses());
loopAddresses.addAll(hostAddresses);
// since there is more than one end point, reactivate connection to a read-only host
searchFilter = new SearchFilter(false);
}
Expand Down

0 comments on commit 0a10408

Please sign in to comment.