public class AuroraTopologyService extends java.lang.Object implements TopologyService, CanCollectPerformanceMetrics
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
clusterId |
protected HostInfo |
clusterInstanceTemplate |
protected boolean |
gatherPerfMetrics |
protected Log |
log
The logger we're going to use.
|
protected static Log |
NULL_LOGGER
Null logger shared by all connections at startup.
|
protected ClusterAwareTimeMetricsHolder |
queryTopologyMetrics |
protected static ExpiringCache<java.lang.String,com.mysql.cj.jdbc.ha.ca.AuroraTopologyService.ClusterTopologyInfo> |
topologyCache |
| Constructor and Description |
|---|
AuroraTopologyService(int refreshRateInMilliseconds,
Log log)
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.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.ca.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 |
reportMetrics(Log log)
Report collected metrics to a provided logger.
|
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.
|
static void |
setExpireTime(int expireTimeMs)
Service instances with the same cluster Id share cluster topology.
|
void |
setLastUsedReaderHost(HostInfo reader)
Set details about the most recent reader that the driver has connected to.
|
void |
setPerformanceMetricsEnabled(boolean isEnabled)
This service implementation supports metrics.
|
void |
setRefreshRate(int refreshRate)
Set new topology refresh rate.
|
protected static final ExpiringCache<java.lang.String,com.mysql.cj.jdbc.ha.ca.AuroraTopologyService.ClusterTopologyInfo> topologyCache
protected java.lang.String clusterId
protected HostInfo clusterInstanceTemplate
protected ClusterAwareTimeMetricsHolder queryTopologyMetrics
protected boolean gatherPerfMetrics
protected static final Log NULL_LOGGER
protected transient Log log
public AuroraTopologyService(Log log)
public AuroraTopologyService(int refreshRateInMilliseconds,
Log log)
refreshRateInMilliseconds - Topology refresh rate in millispublic static void setExpireTime(int expireTimeMs)
expireTimeMs - Topology cache expiration time in millispublic void setClusterId(java.lang.String clusterId)
setClusterId in interface TopologyServiceclusterId - Topology cluster Idpublic void setClusterInstanceTemplate(HostInfo clusterInstanceTemplate)
Examples: "?.mydomain.com", "db-instance.?.mydomain.com"
setClusterInstanceTemplate in interface TopologyServiceclusterInstanceTemplate - Cluster instance details including host dns pattern.public java.util.List<HostInfo> getTopology(JdbcConnection conn, boolean forceUpdate)
refreshRateInMilliseconds).getTopology in interface TopologyServiceconn - 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.protected com.mysql.cj.jdbc.ha.ca.AuroraTopologyService.ClusterTopologyInfo queryForTopology(JdbcConnection conn)
conn - A connection to database to fetch the latest topology.public java.util.List<HostInfo> getCachedTopology()
getCachedTopology in interface TopologyServicepublic HostInfo getLastUsedReaderHost()
getLastUsedReaderHost in interface TopologyServicepublic void setLastUsedReaderHost(HostInfo reader)
setLastUsedReaderHost in interface TopologyServicereader - 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 TopologyServiceconn - A connection to database.public java.util.Set<java.lang.String> getDownHosts()
getDownHosts in interface TopologyServicepublic void addToDownHostList(HostInfo downHost)
addToDownHostList in interface TopologyServicedownHost - The HostInfo object representing the host to mark as downpublic void removeFromDownHostList(HostInfo host)
removeFromDownHostList in interface TopologyServicehost - The HostInfo object representing the host to remove from the list of down hostspublic boolean isMultiWriterCluster()
isMultiWriterCluster in interface TopologyServicepublic void setRefreshRate(int refreshRate)
setRefreshRate in interface TopologyServicerefreshRate - Topology refresh rate in millis.public void clearAll()
clearAll in interface TopologyServicepublic void clear()
clear in interface TopologyServicepublic void setPerformanceMetricsEnabled(boolean isEnabled)
setPerformanceMetricsEnabled in interface CanCollectPerformanceMetricsisEnabled - True to enable internal metrics.public void reportMetrics(Log log)
reportMetrics in interface CanCollectPerformanceMetricslog - Logger to report collected metrics to.