Package com.mysql.cj.jdbc.ha.ca
Interface TopologyService
- All Known Implementing Classes:
AuroraTopologyService
public interface TopologyService
It's a generic interface for all topology services. It's expected that every implementation of
topology service covers different cluster types or cluster deployment.
It's expected that each instance of ClusterAwareConnectionProxy uses it's own instance of topology service.
-
Method Summary
Modifier and Type Method Description voidaddToDownHostList(HostInfo downHost)Mark host as down.voidclear()Clear topology service for the current cluster.voidclearAll()Clear topology service 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.HostInfogetHostByName(JdbcConnection conn)Return theHostInfoobject that is associated with a provided connection from the topology host list.HostInfogetLastUsedReaderHost()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.booleanisMultiWriterCluster()Check if topology belongs to multi-writer cluster.voidremoveFromDownHostList(HostInfo host)Unmark host as down.voidsetClusterId(java.lang.String clusterId)Set unique cluster identifier for topology service instance.voidsetClusterInstanceTemplate(HostInfo clusterInstanceTemplate)Sets host details common to each instance in the cluster, including the host dns pattern.voidsetLastUsedReaderHost(HostInfo reader)Set details about the most recent reader that the driver has connected to.voidsetRefreshRate(int refreshRate)Set new topology refresh rate.
-
Method Details
-
setClusterId
void setClusterId(java.lang.String clusterId)Set unique cluster identifier for topology service instance.Cluster could be accessed through different connection strings like IP address, cluster dns endpoint, instance dns endpoint, custom domain alias (CNAME), etc. Cluster Id can be any string that unique identify a cluster despite the way it's been accessed.
- Parameters:
clusterId- Cluster unique identifier.
-
setClusterInstanceTemplate
Sets host details common to each instance in the cluster, including the host dns pattern. "?" (question mark) in a host dns pattern will be replaced with a host instance name to form a fully qualified dns host endpoint.Examples: "?.mydomain.com", "db-instance.?.mydomain.com"
- Parameters:
clusterInstanceTemplate- Cluster instance details including host dns pattern.
-
getTopology
Get cluster topology. A writer host is always at position 0.- Parameters:
conn- 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.- Returns:
- A list of hosts that describes cluster topology. A writer is always at position 0. Returns an empty list if topology isn't available or is invalid (doesn't contain a writer).
-
getCachedTopology
java.util.List<HostInfo> getCachedTopology()Get cached topology.- Returns:
- List of hosts that represents topology. If there's no topology in cache, it returns null.
-
getLastUsedReaderHost
HostInfo getLastUsedReaderHost()Get details about the most recent reader that the driver has successfully connected to.- Returns:
- The host details of the most recent reader connection.
-
setLastUsedReaderHost
Set details about the most recent reader that the driver has connected to.- Parameters:
reader- A reader host.
-
getHostByName
Return theHostInfoobject that is associated with a provided connection from the topology host list.- Parameters:
conn- A connection to database.- Returns:
- The HostInfo object from the topology host list. Returns null if the connection host is not found in the latest topology.
-
getDownHosts
java.util.Set<java.lang.String> getDownHosts()Get a set of instance names that were marked down.- Returns:
- A set of instance dns names with port. For example: "instance-1.my-domain.com:3306".
-
addToDownHostList
Mark host as down. Host stays marked down until next topology refresh.- Parameters:
downHost- TheHostInfoobject representing the host to mark as down
-
removeFromDownHostList
Unmark host as down. The host is removed from the list of down hosts- Parameters:
host- TheHostInfoobject representing the host to remove from the list of down hosts
-
isMultiWriterCluster
boolean isMultiWriterCluster()Check if topology belongs to multi-writer cluster.- Returns:
- True, if it's multi-writer cluster.
-
setRefreshRate
void setRefreshRate(int refreshRate)Set new topology refresh rate. Topology is considered valid (up to date) within provided duration of time.- Parameters:
refreshRate- Topology refresh rate in millis.
-
clearAll
void clearAll()Clear topology service for all clusters. -
clear
void clear()Clear topology service for the current cluster.
-