public class ClusterAwareReaderFailoverHandler extends Object implements ReaderFailoverHandler
The goal of the reader failover process 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 repeats. If no reader connection has successfully been established, the process may consider connecting to a writer host, and other hosts marked as down.
Modifier and Type | Field and Description |
---|---|
protected Properties |
connectionProps |
protected ConnectionProvider |
connProvider |
protected static int |
DEFAULT_FAILOVER_TIMEOUT |
protected static int |
DEFAULT_READER_CONNECT_TIMEOUT |
protected int |
maxFailoverTimeoutMs |
protected int |
timeoutMs |
protected TopologyService |
topologyService |
protected static int |
WRITER_CONNECTION_INDEX |
Constructor and Description |
---|
ClusterAwareReaderFailoverHandler(TopologyService topologyService,
ConnectionProvider connProvider,
Properties connectionProps) |
ClusterAwareReaderFailoverHandler(TopologyService topologyService,
ConnectionProvider connProvider,
Properties connectionProps,
int failoverTimeoutMs,
int timeoutMs)
ClusterAwareReaderFailoverHandler constructor.
|
Modifier and Type | Method and Description |
---|---|
ReaderFailoverResult |
failover(List<HostInfo> hosts,
@Nullable HostInfo currentHost)
Called to start the reader failover process.
|
protected ReaderFailoverResult |
failoverInternal(List<HostInfo> hosts,
@Nullable HostInfo currentHost)
Helper method for
failover(List, HostInfo) . |
ReaderFailoverResult |
getReaderConnection(List<HostInfo> hostList)
Called to get any available reader connection.
|
protected void |
setTimeoutMs(int timeoutMs)
Set process timeout in millis.
|
protected static final int DEFAULT_FAILOVER_TIMEOUT
protected static final int DEFAULT_READER_CONNECT_TIMEOUT
protected static final int WRITER_CONNECTION_INDEX
protected int maxFailoverTimeoutMs
protected int timeoutMs
protected final ConnectionProvider connProvider
protected final TopologyService topologyService
protected Properties connectionProps
public ClusterAwareReaderFailoverHandler(TopologyService topologyService, ConnectionProvider connProvider, Properties connectionProps)
public ClusterAwareReaderFailoverHandler(TopologyService topologyService, ConnectionProvider connProvider, Properties connectionProps, int failoverTimeoutMs, int timeoutMs)
topologyService
- a topology serviceconnProvider
- a connection providerconnectionProps
- a set of properties for a new connectionsfailoverTimeoutMs
- timeout for the entire reader failover processtimeoutMs
- timeout for each individual connection attemptprotected void setTimeoutMs(int timeoutMs)
timeoutMs
- Process timeout in millispublic ReaderFailoverResult failover(List<HostInfo> hosts, @Nullable HostInfo currentHost) throws SQLException
failover
in interface ReaderFailoverHandler
hosts
- The latest cluster topology information that we had before connection failure.currentHost
- The currently connected host that has failed.ReaderFailoverResult
The results of this process.SQLException
- when a thread gets interrupted and failover failsprotected ReaderFailoverResult failoverInternal(List<HostInfo> hosts, @Nullable HostInfo currentHost) throws SQLException
failover(List, HostInfo)
.hosts
- List of hosts in the current topologycurrentHost
- The currently connected hostReaderFailoverResult
of the internal failover processSQLException
- when a thread gets interrupted and failover failspublic ReaderFailoverResult getReaderConnection(List<HostInfo> hostList) throws SQLException
getReaderConnection
in interface ReaderFailoverHandler
hostList
- Current topology for the cluster.ReaderFailoverResult
The results of this process.SQLException
- when a thread gets interrupted and failover failsCopyright © 1997-2021 PostgreSQL Global Development Group. All Rights Reserved.