public class AuroraTopologyService extends java.lang.Object implements ITopologyService
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
clusterId |
protected HostInfo |
clusterInstanceTemplate |
static CacheMap<java.lang.String,java.util.Set<java.lang.String>> |
downHostCache |
static CacheMap<java.lang.String,HostInfo> |
lastUsedReaderCache |
protected Log |
log
The logger we're going to use.
|
protected IClusterAwareMetricsContainer |
metricsContainer |
static CacheMap<java.lang.String,java.lang.Boolean> |
multiWriterClusterCache |
protected static Log |
NULL_LOGGER
Null logger shared by all connections at startup.
|
static CacheMap<java.lang.String,java.util.List<HostInfo>> |
topologyCache |
| Constructor and Description |
|---|
AuroraTopologyService(int refreshRateInMilliseconds,
Log log,
java.util.function.Supplier<IClusterAwareMetricsContainer> metricsContainerSupplier)
Initializes a service with provided topology refresh rate.
|
AuroraTopologyService(Log log)
Initializes a service with topology default refresh rate.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addToDownHostList(HostInfo downHost)
Mark host as down.
|
void |
clear()
Clear topology cache for the current cluster.
|
void |
clearAll()
Clear topology cache for all clusters.
|
java.util.List<HostInfo> |
getCachedTopology()
Get cached topology.
|
java.lang.String |
getClusterId()
Returns the unique cluster identifier for topology service instance
|
java.util.Set<java.lang.String> |
getDownHosts()
Get a set of instance names that were marked down.
|
HostInfo |
getHostByName(JdbcConnection conn)
Return the
HostInfo object that is associated with a provided connection from the topology host list. |
HostInfo |
getLastUsedReaderHost()
Get details about the most recent reader that the driver has successfully connected to.
|
java.util.List<HostInfo> |
getTopology(JdbcConnection conn,
boolean forceUpdate)
Get cluster topology.
|
boolean |
isMultiWriterCluster()
Check if cached topology belongs to multi-writer cluster.
|
protected com.mysql.cj.jdbc.ha.plugins.failover.AuroraTopologyService.ClusterTopologyInfo |
queryForTopology(JdbcConnection conn)
Query the database for the cluster topology and use the results to record information about the topology.
|
void |
removeFromDownHostList(HostInfo host)
Unmark host as down.
|
void |
setClusterId(java.lang.String clusterId)
Sets cluster Id for a service instance.
|
void |
setClusterInstanceTemplate(HostInfo clusterInstanceTemplate)
Sets host details common to each instance in the cluster, including the host dns pattern.
|
void |
setLastUsedReaderHost(HostInfo reader)
Set details about the most recent reader that the driver has connected to.
|
void |
setRefreshRate(int refreshRateMillis)
Set new topology refresh rate.
|
public static final CacheMap<java.lang.String,java.util.Set<java.lang.String>> downHostCache
public static final CacheMap<java.lang.String,java.lang.Boolean> multiWriterClusterCache
protected java.lang.String clusterId
protected HostInfo clusterInstanceTemplate
protected IClusterAwareMetricsContainer metricsContainer
protected static final Log NULL_LOGGER
protected transient Log log
public AuroraTopologyService(Log log)
public AuroraTopologyService(int refreshRateInMilliseconds,
Log log,
java.util.function.Supplier<IClusterAwareMetricsContainer> metricsContainerSupplier)
refreshRateInMilliseconds - Topology refresh rate in millispublic void setClusterId(java.lang.String clusterId)
setClusterId in interface ITopologyServiceclusterId - Topology cluster Idpublic java.lang.String getClusterId()
getClusterId in interface ITopologyServicepublic void setClusterInstanceTemplate(HostInfo clusterInstanceTemplate)
Examples: "?.mydomain.com", "db-instance.?.mydomain.com"
setClusterInstanceTemplate in interface ITopologyServiceclusterInstanceTemplate - Cluster instance details including host dns pattern.public java.util.List<HostInfo> getTopology(JdbcConnection conn, boolean forceUpdate) throws java.sql.SQLException
refreshRateNanos).getTopology in interface ITopologyServiceconn - A connection to database to fetch the latest topology, if needed.forceUpdate - If true, it forces a service to ignore cached copy of topology and to fetch
a fresh one.java.sql.SQLExceptionprotected com.mysql.cj.jdbc.ha.plugins.failover.AuroraTopologyService.ClusterTopologyInfo queryForTopology(JdbcConnection conn) throws java.sql.SQLException
conn - A connection to database to fetch the latest topology.java.sql.SQLExceptionpublic java.util.List<HostInfo> getCachedTopology()
getCachedTopology in interface ITopologyServicepublic HostInfo getLastUsedReaderHost()
getLastUsedReaderHost in interface ITopologyServicepublic void setLastUsedReaderHost(HostInfo reader)
setLastUsedReaderHost in interface ITopologyServicereader - A reader host.public HostInfo getHostByName(JdbcConnection conn)
HostInfo object that is associated with a provided connection from the topology host list.getHostByName in interface ITopologyServiceconn - A connection to database.public java.util.Set<java.lang.String> getDownHosts()
getDownHosts in interface ITopologyServicepublic void addToDownHostList(HostInfo downHost)
addToDownHostList in interface ITopologyServicedownHost - The HostInfo object representing the host to mark as downpublic void removeFromDownHostList(HostInfo host)
removeFromDownHostList in interface ITopologyServicehost - The HostInfo object representing the host to remove from the list of down hostspublic boolean isMultiWriterCluster()
isMultiWriterCluster in interface ITopologyServicepublic void setRefreshRate(int refreshRateMillis)
setRefreshRate in interface ITopologyServicerefreshRateMillis - Topology refresh rate in millis.public void clearAll()
clearAll in interface ITopologyServicepublic void clear()
clear in interface ITopologyService