Package com.mysql.cj.jdbc.ha.ca
Class ClusterAwareReaderFailoverHandler
java.lang.Object
com.mysql.cj.jdbc.ha.ca.ClusterAwareReaderFailoverHandler
- All Implemented Interfaces:
ReaderFailoverHandler
public class ClusterAwareReaderFailoverHandler extends java.lang.Object implements ReaderFailoverHandler
An implementation of ReaderFailoverHandler.
Reader Failover Process goal is to connect to any available reader. In order to connect faster, this implementation tries to connect to two readers at the same time. The first successfully connected reader is returned as the process result. If both readers are unavailable (i.e. could not be connected to), the process picks up another pair of readers and repeat. If no reader has been connected to, the process may consider a writer host, and other hosts marked down, to connect to.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classClusterAwareReaderFailoverHandler.HostTupleHostTuple class. -
Field Summary
Fields Modifier and Type Field Description protected ConnectionProviderconnProviderprotected static intDEFAULT_FAILOVER_TIMEOUTprotected static intDEFAULT_READER_CONNECT_TIMEOUTprotected java.util.Map<java.lang.String,java.lang.String>initialConnectionPropsprotected LoglogThe logger we're going to use.protected intmaxFailoverTimeoutMsprotected static LogNULL_LOGGERNull logger shared by all connections at startup.protected inttimeoutMsprotected TopologyServicetopologyService -
Constructor Summary
Constructors Constructor Description ClusterAwareReaderFailoverHandler(TopologyService topologyService, ConnectionProvider connProvider, java.util.Map<java.lang.String,java.lang.String> initialConnectionProps, int failoverTimeoutMs, int timeoutMs, Log log)ClusterAwareReaderFailoverHandler constructor.ClusterAwareReaderFailoverHandler(TopologyService topologyService, ConnectionProvider connProvider, java.util.Map<java.lang.String,java.lang.String> initialConnectionProps, Log log) -
Method Summary
Modifier and Type Method Description ReaderFailoverResultfailover(java.util.List<HostInfo> hosts, HostInfo currentHost)Called to start Reader Failover Process.protected ReaderFailoverResultfailoverInternal(java.util.List<HostInfo> hosts, HostInfo currentHost)ReaderFailoverResultgetReaderConnection(java.util.List<HostInfo> hostList)Called to get any available reader connection.protected voidsetTimeoutMs(int timeoutMs)Set process timeout in millis.
-
Field Details
-
DEFAULT_FAILOVER_TIMEOUT
protected static final int DEFAULT_FAILOVER_TIMEOUT- See Also:
- Constant Field Values
-
DEFAULT_READER_CONNECT_TIMEOUT
protected static final int DEFAULT_READER_CONNECT_TIMEOUT- See Also:
- Constant Field Values
-
NULL_LOGGER
Null logger shared by all connections at startup. -
log
The logger we're going to use. -
initialConnectionProps
protected java.util.Map<java.lang.String,java.lang.String> initialConnectionProps -
maxFailoverTimeoutMs
protected int maxFailoverTimeoutMs -
timeoutMs
protected int timeoutMs -
connProvider
-
topologyService
-
-
Constructor Details
-
ClusterAwareReaderFailoverHandler
public ClusterAwareReaderFailoverHandler(TopologyService topologyService, ConnectionProvider connProvider, java.util.Map<java.lang.String,java.lang.String> initialConnectionProps, Log log) -
ClusterAwareReaderFailoverHandler
public ClusterAwareReaderFailoverHandler(TopologyService topologyService, ConnectionProvider connProvider, java.util.Map<java.lang.String,java.lang.String> initialConnectionProps, int failoverTimeoutMs, int timeoutMs, Log log)ClusterAwareReaderFailoverHandler constructor.
-
-
Method Details
-
setTimeoutMs
protected void setTimeoutMs(int timeoutMs)Set process timeout in millis. Entire process of connecting to a reader will be limited by this time duration.- Parameters:
timeoutMs- Process timeout in millis
-
failover
public ReaderFailoverResult failover(java.util.List<HostInfo> hosts, HostInfo currentHost) throws java.sql.SQLExceptionCalled to start Reader Failover Process. This process tries to connect to any reader. If no reader is available then driver may also try to connect to a writer host, down hosts, and the current reader host.- Specified by:
failoverin interfaceReaderFailoverHandler- Parameters:
hosts- Cluster current topologycurrentHost- The currently connected host that has failed.- Returns:
ReaderFailoverResultThe results of this process.- Throws:
java.sql.SQLException
-
failoverInternal
protected ReaderFailoverResult failoverInternal(java.util.List<HostInfo> hosts, HostInfo currentHost) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
getReaderConnection
public ReaderFailoverResult getReaderConnection(java.util.List<HostInfo> hostList) throws java.sql.SQLExceptionCalled to get any available reader connection. If no reader is available then result of process is unsuccessful. This process will not attempt to connect to the writer.- Specified by:
getReaderConnectionin interfaceReaderFailoverHandler- Parameters:
hostList- Cluster current topology- Returns:
ReaderFailoverResultThe results of this process.- Throws:
java.sql.SQLException
-