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 @@ -35,12 +35,13 @@
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -98,7 +99,7 @@ public class AuroraHostListProvider implements HostListProvider, DynamicHostList
private final int refreshRateInMilliseconds;
private List<HostSpec> hostList = new ArrayList<>();

static final ExpiringCache<String, ClusterTopologyInfo> topologyCache =
protected static final ExpiringCache<String, ClusterTopologyInfo> topologyCache =
new ExpiringCache<>(DEFAULT_CACHE_EXPIRE_MS);
private static final Object cacheLock = new Object();

Expand Down Expand Up @@ -224,7 +225,7 @@ protected ClusterTopologyInfo queryForTopology(final Connection conn) throws SQL
// ignore
}

return new ClusterTopologyInfo(hosts, new HashSet<>(), Instant.now(), false);
return new ClusterTopologyInfo(hosts, ConcurrentHashMap.newKeySet(), Instant.now(), false);
}

/**
Expand Down Expand Up @@ -362,7 +363,7 @@ public Set<String> getDownHosts() {
ClusterTopologyInfo clusterTopologyInfo = topologyCache.get(this.clusterId);
return clusterTopologyInfo != null && clusterTopologyInfo.downHosts != null
? clusterTopologyInfo.downHosts
: new HashSet<>();
: ConcurrentHashMap.newKeySet();
}
}

Expand All @@ -379,10 +380,10 @@ public void addToDownHostList(HostSpec downHost) {
ClusterTopologyInfo clusterTopologyInfo = topologyCache.get(this.clusterId);
if (clusterTopologyInfo == null) {
clusterTopologyInfo =
new ClusterTopologyInfo(new ArrayList<>(), new HashSet<>(), Instant.now(), false);
new ClusterTopologyInfo(new ArrayList<>(), ConcurrentHashMap.newKeySet(), Instant.now(), false);
topologyCache.put(this.clusterId, clusterTopologyInfo);
} else if (clusterTopologyInfo.downHosts == null) {
clusterTopologyInfo.downHosts = new HashSet<>();
clusterTopologyInfo.downHosts = ConcurrentHashMap.newKeySet();
}
clusterTopologyInfo.downHosts.add(downHost.getUrl());
this.pluginService.setAvailability(downHost.getAliases(), HostAvailability.NOT_AVAILABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
Expand Down Expand Up @@ -430,5 +431,10 @@ public HostSpec getHost() {
public int getIndex() {
return index;
}

@Override
public String toString() {
return String.format("host: %s, index: %d", host, index);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ private boolean refreshTopologyAndConnectToNewWriter() throws InterruptedExcepti
if (!topology.isEmpty()) {
this.currentTopology = topology;
HostSpec writerCandidate = this.currentTopology.get(WRITER_CONNECTION_INDEX);
logTopology();

if (!isSame(writerCandidate, this.originalWriterHost)) {
// new writer is available and it's different from the previous writer
logTopology();
if (connectToWriter(writerCandidate)) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions wrapper/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Failover.parameterValue={0}={1}
Failover.unableToConnectToWriter=Unable to establish SQL connection to the writer instance
Failover.unableToConnectToReader=Unable to establish SQL connection to the reader instance.
Failover.detectedException=Detected an exception while executing a command: {0}.
Failover.failoverDisabled=Cluster-aware failover is disabled.
Failover.failoverEnabled=Cluster-aware failover is enabled.
Failover.failoverDisabled=Cluster-aware failover is disabled
Failover.failoverEnabled=Cluster-aware failover is enabled
Failover.establishedConnection=Connected to: {0}
Failover.startWriterFailover=Starting writer failover procedure.
Failover.startReaderFailover=Starting reader failover procedure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public void setUpEach() throws InterruptedException, SQLException {
clusterSize >= 2); // many tests assume that cluster contains at least a writer and a reader
assertTrue(isDBInstanceWriter(instanceIDs[0]));
makeSureInstancesUp(instanceIDs);
TestAuroraHostListProvider.clearCache();
}

protected Properties initDefaultPropsNoTimeouts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ public void test_failFromReaderToReaderWithSomeReadersAreDown()
* revive previously down reader instance.
*/
@Test
@Disabled
public void test_failoverBackToThePreviouslyDownReader() throws Exception {

assertTrue(clusterSize >= 5, "Minimal cluster configuration: 1 writer + 4 readers");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package integration.container.aurora.postgres;

import com.amazon.awslabs.jdbc.PluginService;
import com.amazon.awslabs.jdbc.hostlistprovider.AuroraHostListProvider;
import java.util.Properties;

public class TestAuroraHostListProvider extends AuroraHostListProvider {

public TestAuroraHostListProvider(String driverProtocol, PluginService pluginService,
Properties properties, String originalUrl) {
super(driverProtocol, pluginService, properties, originalUrl);
}

public static void clearCache() {
AuroraHostListProvider.topologyCache.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.postgresql.util.PSQLException;

Expand Down