Class ReplicationConnectionProxy
java.lang.Object
com.mysql.jdbc.MultiHostConnectionProxy
com.mysql.jdbc.ReplicationConnectionProxy
- All Implemented Interfaces:
PingTarget, InvocationHandler
Connection that opens two connections, one two a replication master, and another to one or more slaves, and decides to use master when the connection is not
read-only, and use slave(s) when the connection is read-only.
-
Nested Class Summary
Nested classes/interfaces inherited from class MultiHostConnectionProxy
MultiHostConnectionProxy.JdbcInterfaceProxy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected boolean(package private) ReplicationConnectionGroupprotected booleanprotected LoadBalancedConnectionprotected booleanprotected booleanprotected booleanprotected LoadBalancedConnectionFields inherited from class MultiHostConnectionProxy
autoReconnect, closedExplicitly, closedReason, currentConnection, hostList, isClosed, lastExceptionDealtWith, localProps, proxyConnection, thisAsConnection -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSlaveHost(String hostPortPair) static ReplicationConnectioncreateProxyInstance(List<String> masterHostList, Properties masterProperties, List<String> slaveHostList, Properties slaveProperties) (package private) voidExecutes a abort() invocation;(package private) voidExecutes a abortInternal() invocation;(package private) voiddoClose()Executes a close() invocation;voiddoPing()Pings both l/b connections.long(package private) MySQLConnectionWraps this object with a new replication Connection instance.(package private) ObjectinvokeMore(Object proxy, Method method, Object[] args) Proxies method invocation on the java.sql.Connection interface.booleanisHostMaster(String hostPortPair) booleanisHostSlave(String hostPortPair) booleanChecks if current connection is the masters l/b connection.booleanbooleanChecks if current connection is the slaves l/b connection.(package private) voidPicks the "best" connection to use from now on.voidpromoteSlaveToMaster(String hostPortPair) protected voidpropagateProxyDown(MySQLConnection proxyConn) Propagates the connection proxy down through all live connections.voidremoveMasterHost(String hostPortPair) voidremoveMasterHost(String hostPortPair, boolean waitUntilNotInUse) voidremoveMasterHost(String hostPortPair, boolean waitUntilNotInUse, boolean isNowSlave) voidremoveSlave(String hostPortPair) voidremoveSlave(String hostPortPair, boolean closeGently) voidsetReadOnly(boolean readOnly) (package private) booleanHas no use in replication connections.(package private) voidsyncSessionState(Connection source, Connection target, boolean readOnlyStatus) Synchronizes session state between two connections, allowing to override the read-only status.Methods inherited from class MultiHostConnectionProxy
allowedOnClosedConnection, createConnectionForHost, dealWithInvocationException, getNewJdbcInterfaceProxy, getProxy, initializeHostsSpecs, invalidateConnection, invalidateCurrentConnection, invoke, proxyIfReturnTypeIsJdbcInterface, setProxy, syncSessionState
-
Field Details
-
enableJMX
protected boolean enableJMX -
allowMasterDownConnections
protected boolean allowMasterDownConnections -
allowSlaveDownConnections
protected boolean allowSlaveDownConnections -
readFromMasterWhenNoSlaves
protected boolean readFromMasterWhenNoSlaves -
readFromMasterWhenNoSlavesOriginal
protected boolean readFromMasterWhenNoSlavesOriginal -
readOnly
protected boolean readOnly -
connectionGroup
ReplicationConnectionGroup connectionGroup -
masterConnection
-
slavesConnection
-
-
Method Details
-
createProxyInstance
public static ReplicationConnection createProxyInstance(List<String> masterHostList, Properties masterProperties, List<String> slaveHostList, Properties slaveProperties) throws SQLException - Throws:
SQLException
-
getNewWrapperForThisAsConnection
Wraps this object with a new replication Connection instance.- Overrides:
getNewWrapperForThisAsConnectionin classMultiHostConnectionProxy- Returns:
- The connection object instance that wraps 'this'.
- Throws:
SQLException
-
propagateProxyDown
Propagates the connection proxy down through all live connections.- Overrides:
propagateProxyDownin classMultiHostConnectionProxy- Parameters:
proxyConn- The top level connection in the multi-host connections chain.
-
shouldExceptionTriggerConnectionSwitch
Has no use in replication connections. Always returnfalse.- Specified by:
shouldExceptionTriggerConnectionSwitchin classMultiHostConnectionProxy- Parameters:
t- The Throwable instance to analyze.ex- The Exception instance to check.
-
isMasterConnection
public boolean isMasterConnection()Checks if current connection is the masters l/b connection.- Specified by:
isMasterConnectionin classMultiHostConnectionProxy
-
isSlavesConnection
public boolean isSlavesConnection()Checks if current connection is the slaves l/b connection. -
pickNewConnection
Description copied from class:MultiHostConnectionProxyPicks the "best" connection to use from now on. Each subclass needs to implement its connection switch strategy on it.- Specified by:
pickNewConnectionin classMultiHostConnectionProxy- Throws:
SQLException
-
syncSessionState
void syncSessionState(Connection source, Connection target, boolean readOnlyStatus) throws SQLException Description copied from class:MultiHostConnectionProxySynchronizes session state between two connections, allowing to override the read-only status.- Overrides:
syncSessionStatein classMultiHostConnectionProxy- Parameters:
source- The connection where to get state from.target- The connection where to set state.readOnlyStatus- The new read-only status.- Throws:
SQLException
-
doClose
Description copied from class:MultiHostConnectionProxyExecutes a close() invocation;- Specified by:
doClosein classMultiHostConnectionProxy- Throws:
SQLException
-
doAbortInternal
Description copied from class:MultiHostConnectionProxyExecutes a abortInternal() invocation;- Specified by:
doAbortInternalin classMultiHostConnectionProxy- Throws:
SQLException
-
doAbort
Description copied from class:MultiHostConnectionProxyExecutes a abort() invocation;- Specified by:
doAbortin classMultiHostConnectionProxy- Throws:
SQLException
-
invokeMore
Proxies method invocation on the java.sql.Connection interface. This is the continuation of MultiHostConnectionProxy#invoke(Object, Method, Object[]).- Specified by:
invokeMorein classMultiHostConnectionProxy- Throws:
Throwable
-
doPing
Pings both l/b connections. Switch to another connection in case of failure.- Specified by:
doPingin interfacePingTarget- Throws:
SQLException
-
getCurrentConnection
-
getConnectionGroupId
public long getConnectionGroupId() -
getMasterConnection
-
promoteSlaveToMaster
- Throws:
SQLException
-
removeMasterHost
- Throws:
SQLException
-
removeMasterHost
- Throws:
SQLException
-
removeMasterHost
public void removeMasterHost(String hostPortPair, boolean waitUntilNotInUse, boolean isNowSlave) throws SQLException - Throws:
SQLException
-
isHostMaster
-
getSlavesConnection
-
addSlaveHost
- Throws:
SQLException
-
removeSlave
- Throws:
SQLException
-
removeSlave
- Throws:
SQLException
-
isHostSlave
-
setReadOnly
- Throws:
SQLException
-
isReadOnly
- Throws:
SQLException
-