public class FailoverConnectionPlugin extends java.lang.Object implements IConnectionPlugin
IConnectionPlugin implementation that provides cluster-aware failover
features. Connection switching occurs on communications related exceptions and/or
cluster topology changes.| Constructor and Description |
|---|
FailoverConnectionPlugin(ICurrentConnectionProvider currentConnectionProvider,
PropertySet propertySet,
IConnectionPlugin nextPlugin,
Log logger) |
| Modifier and Type | Method and Description |
|---|---|
protected ConnectionImpl |
createConnectionForHost(HostInfo baseHostInfo)
Creates a new physical connection for the given
HostInfo. |
protected void |
dealWithIllegalStateException(java.lang.IllegalStateException e) |
java.lang.Object |
execute(java.lang.Class<?> methodInvokeOn,
java.lang.String methodName,
java.util.concurrent.Callable<?> executeSqlFunc,
java.lang.Object[] args) |
protected void |
failover(int failedHostIdx)
Initiates the failover procedure.
|
protected void |
failoverReader(int failedHostIdx) |
protected void |
failoverWriter() |
protected void |
initializeTopology() |
protected void |
invalidateCurrentConnection() |
protected boolean |
isCurrentConnectionWriter() |
boolean |
isFailoverEnabled() |
boolean |
isRds()
Checks if the proxy is connected to an RDS-hosted cluster.
|
boolean |
isRdsProxy()
Checks if the proxy is connected to a cluster using RDS proxy.
|
void |
openInitialConnection(ConnectionUrl connectionUrl) |
protected void |
pickNewConnection() |
void |
releaseResources() |
protected boolean |
shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t) |
protected void |
syncSessionState(JdbcConnection source,
JdbcConnection target,
boolean readOnly)
Synchronizes session state between two connections, allowing to override the read-only status.
|
void |
transactionBegun()
Called when the driver has been told by the server that a transaction is now in progress (when
one has not been currently in progress).
|
void |
transactionCompleted()
Called when the driver has been told by the server that a transaction has completed, and no
transaction is currently in progress.
|
protected void |
updateTopologyIfNeeded(boolean forceUpdate) |
public static final int NO_CONNECTION_INDEX
public static final int WRITER_CONNECTION_INDEX
protected final IConnectionProvider connectionProvider
protected final IClusterAwareMetricsContainer metricsContainer
protected IWriterFailoverHandler writerFailoverHandler
protected IReaderFailoverHandler readerFailoverHandler
protected int currentHostIndex
protected java.util.Map<java.lang.String,java.lang.String> initialConnectionProps
protected java.lang.Boolean explicitlyReadOnly
protected boolean inTransaction
protected boolean explicitlyAutoCommit
protected boolean isClusterTopologyAvailable
protected boolean isMultiWriterCluster
protected boolean isRdsProxy
protected boolean isRds
protected ITopologyService topologyService
protected java.util.List<HostInfo> hosts
protected boolean enableFailoverSetting
protected boolean enableFailoverStrictReaderSetting
protected int clusterTopologyRefreshRateMsSetting
protected int failoverTimeoutMsSetting
protected int failoverClusterTopologyRefreshRateMsSetting
protected int failoverWriterReconnectIntervalMsSetting
protected int failoverReaderConnectTimeoutMsSetting
protected java.lang.String clusterIdSetting
protected java.lang.String clusterInstanceHostPatternSetting
protected int failoverConnectTimeoutMs
protected int failoverSocketTimeoutMs
protected boolean isClosed
protected boolean closedExplicitly
protected java.lang.String closedReason
protected java.lang.Throwable lastExceptionDealtWith
protected boolean autoReconnect
public FailoverConnectionPlugin(ICurrentConnectionProvider currentConnectionProvider, PropertySet propertySet, IConnectionPlugin nextPlugin, Log logger) throws java.sql.SQLException
java.sql.SQLExceptionpublic void openInitialConnection(ConnectionUrl connectionUrl) throws java.sql.SQLException
openInitialConnection in interface IConnectionPluginjava.sql.SQLExceptionpublic java.lang.Object execute(java.lang.Class<?> methodInvokeOn,
java.lang.String methodName,
java.util.concurrent.Callable<?> executeSqlFunc,
java.lang.Object[] args)
throws java.lang.Exception
execute in interface IConnectionPluginjava.lang.Exceptionpublic void transactionBegun()
ITransactionContextHandlertransactionBegun in interface ITransactionContextHandlerpublic void transactionCompleted()
ITransactionContextHandlertransactionCompleted in interface ITransactionContextHandlerpublic void releaseResources()
releaseResources in interface IConnectionPluginpublic boolean isFailoverEnabled()
public boolean isRds()
public boolean isRdsProxy()
protected void initializeTopology()
throws java.sql.SQLException
java.sql.SQLExceptionprotected ConnectionImpl createConnectionForHost(HostInfo baseHostInfo) throws java.sql.SQLException
HostInfo.baseHostInfo - The host info instance to base the connection off of.java.sql.SQLException - if an error occursprotected void dealWithIllegalStateException(java.lang.IllegalStateException e)
throws java.lang.Exception
java.lang.Exceptionprotected void failover(int failedHostIdx)
throws java.sql.SQLException
failedHostIdx - The index of the host that failedjava.sql.SQLException - if an error occursprotected void failoverReader(int failedHostIdx)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void failoverWriter()
throws java.sql.SQLException
java.sql.SQLExceptionprotected void invalidateCurrentConnection()
protected void pickNewConnection()
throws java.sql.SQLException
java.sql.SQLExceptionprotected boolean shouldExceptionTriggerConnectionSwitch(java.lang.Throwable t)
protected void syncSessionState(JdbcConnection source, JdbcConnection target, boolean readOnly) throws java.sql.SQLException
source - The connection where to get state from.target - The connection where to set state.readOnly - The new read-only status.java.sql.SQLException - if an error occursprotected void updateTopologyIfNeeded(boolean forceUpdate)
throws java.sql.SQLException
java.sql.SQLExceptionprotected boolean isCurrentConnectionWriter()