Top Description Fields Constructors Methods
com.mysql.cj.jdbc.ha

public Class ReplicationConnectionProxy

extends MultiHostConnectionProxy
implements PingTarget
Class Inheritance
All Implemented Interfaces
com.mysql.cj.PingTarget
Static Imports
com.mysql.cj.util.StringUtils.isNullOrEmpty

Connection that opens two connections, one two a replication source, and another to one or more replicas, and decides to use source when the connection is not read-only, and use replica(s) when the connection is read-only.

Field Summary

Modifier and TypeField and Description
protected boolean
protected boolean
pack-priv ReplicationConnectionGroup
private long
protected boolean
protected boolean
protected boolean
protected boolean
private List<HostInfo>
protected LoadBalancedConnection
protected LoadBalancedConnection
private List<HostInfo>
private ReplicationConnection
Inherited from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy:
autoReconnectclosedExplicitlyclosedReasonconnectionUrlcurrentConnectionhostsListisClosedlastExceptionDealtWithparentProxyConnectionthisAsConnectiontopProxyConnection

Constructor Summary

AccessConstructor and Description
private
ReplicationConnectionProxy(ConnectionUrl
The connection URL containing the hosts in a replication setup.
connectionUrl
)

Creates a proxy for java.sql.Connection that routes requests to a load-balanced connection of source servers or a load-balanced connection of replica servers.

Method Summary

Modifier and TypeMethod and Description
public void
addReplicaHost(String hostPortPair)

private void
checkConnectionCapabilityForMethod(Method
method
method
)

Checks if this connection is in a state capable to invoke the provided method.

public static ReplicationConnection

Returns:

A ReplicationConnection proxy.
createProxyInstance
(ConnectionUrl
The connection URL containing the hosts in a replication setup.
connectionUrl
)

Static factory to create ReplicationConnection instances.

pack-priv void
doAbort(Executor
executor
executor
)

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.doAbort.

Executes a abort() invocation;

pack-priv void
doAbortInternal()

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.doAbortInternal.

Executes a abortInternal() invocation;

pack-priv void
doClose()

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.doClose.

Executes a close() invocation;

public void
doPing()

Implements com.mysql.cj.PingTarget.doPing.

Pings both l/b connections.

public long
private ReplicationConnectionUrl
public JdbcConnection
pack-priv JdbcConnection

Returns:

The connection object instance that wraps 'this'.
getNewWrapperForThisAsConnection
()

Overrides com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.getNewWrapperForThisAsConnection.

Wraps this object with a new replication Connection instance.

private HostInfo
getReplicaHost(String hostPortPair)

public JdbcConnection
public JdbcConnection
private HostInfo
getSourceHost(String hostPortPair)

private JdbcConnection
private JdbcConnection
pack-priv Object
invokeMore(Object
proxy object
proxy
,
Method
method to invoke
method
,
Object[]
method parameters
args
)

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.invokeMore.

Proxies method invocation on the java.sql.Connection interface.

public boolean
isHostReplica(String hostPortPair)

public boolean
isHostSource(String hostPortPair)

public boolean
public boolean

Returns:

true if current connection is the replicas l/b connection
isReplicasConnection
()

Checks if current connection is the replicas l/b connection.

public boolean
isSourceConnection()

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.isSourceConnection.

Checks if current connection is the sources l/b connection.

pack-priv void
pickNewConnection()

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.pickNewConnection.

Picks the "best" connection to use from now on.

public void
protected void
propagateProxyDown(JdbcConnection
The top level connection in the multi-host connections chain.
proxyConn
)

Overrides com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.propagateProxyDown.

Propagates the connection proxy down through all live connections.

public void
removeReplica(String hostPortPair)

public void
removeReplica(String hostPortPair, boolean closeGently)

public void
removeSourceHost(String hostPortPair)

public void
removeSourceHost(String hostPortPair, boolean waitUntilNotInUse)

public void
removeSourceHost(String hostPortPair, boolean waitUntilNotInUse, boolean isNowReplica)

private void
public void
setReadOnly(boolean readOnly)

pack-priv boolean
shouldExceptionTriggerConnectionSwitch(Throwable
The Exception instance to check.
t
)

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.shouldExceptionTriggerConnectionSwitch.

Has no use in replication connections.

private boolean
private boolean
private boolean
pack-priv void
syncSessionState(JdbcConnection
The connection where to get state from.
source
,
JdbcConnection
The connection where to set state.
target
,
boolean
The new read-only status.
readonly
)

Overrides com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.syncSessionState.

Synchronizes session state between two connections, allowing to override the read-only status.

Inherited from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy:
allowedOnClosedConnectioncreateConnectionForHostdealWithInvocationExceptiongetLockgetNewJdbcInterfaceProxygetParentProxygetProxyinitializeHostsSpecsinvalidateConnectioninvalidateCurrentConnectioninvokeproxyIfReturnTypeIsJdbcInterfacesetProxysyncSessionState

Field Detail

allowReplicaDownConnectionsback to summary
protected boolean allowReplicaDownConnections
allowSourceDownConnectionsback to summary
protected boolean allowSourceDownConnections
connectionGroupback to summary
pack-priv ReplicationConnectionGroup connectionGroup
connectionGroupIDback to summary
private long connectionGroupID
enableJMXback to summary
protected boolean enableJMX
readFromSourceWhenNoReplicasback to summary
protected boolean readFromSourceWhenNoReplicas
readFromSourceWhenNoReplicasOriginalback to summary
protected boolean readFromSourceWhenNoReplicasOriginal
readOnlyback to summary
protected boolean readOnly
replicaHostsback to summary
private List<HostInfo> replicaHosts
replicasConnectionback to summary
protected LoadBalancedConnection replicasConnection
sourceConnectionback to summary
protected LoadBalancedConnection sourceConnection
sourceHostsback to summary
private List<HostInfo> sourceHosts
thisAsReplicationConnectionback to summary
private ReplicationConnection thisAsReplicationConnection

Constructor Detail

ReplicationConnectionProxyback to summary
private ReplicationConnectionProxy(ConnectionUrl connectionUrl) throws SQLException

Creates a proxy for java.sql.Connection that routes requests to a load-balanced connection of source servers or a load-balanced connection of replica servers. Each sub-connection is created with its own set of independent properties.

Parameters
connectionUrl:ConnectionUrl

The connection URL containing the hosts in a replication setup.

Exceptions
SQLException:
if an error occurs

Method Detail

addReplicaHostback to summary
public void addReplicaHost(String hostPortPair) throws SQLException
checkConnectionCapabilityForMethodback to summary
private void checkConnectionCapabilityForMethod(Method method) throws Throwable

Checks if this connection is in a state capable to invoke the provided method. If the connection is in an inconsistent state, i.e. it has no hosts for both sub-connections, then throw an invalid transaction state exception. Nevertheless, the methods defined in the ReplicationConnection interface will be allowed as they are the only way to leave from an empty hosts lists situation.

Parameters
method:Method

method

Exceptions
Throwable:
if an error occurs
createProxyInstanceback to summary
public static ReplicationConnection createProxyInstance(ConnectionUrl connectionUrl) throws SQLException

Static factory to create ReplicationConnection instances.

Parameters
connectionUrl:ConnectionUrl

The connection URL containing the hosts in a replication setup.

Returns:ReplicationConnection

A ReplicationConnection proxy.

Exceptions
SQLException:
if an error occurs
doAbortback to summary
pack-priv void doAbort(Executor executor) throws SQLException

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.doAbort.

Doc from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.doAbort.

Executes a abort() invocation;

Parameters
executor:Executor

executor

Annotations
@Override
Exceptions
SQLException:
if an error occurs
doAbortInternalback to summary
pack-priv void doAbortInternal() throws SQLException

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.doAbortInternal.

Doc from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.doAbortInternal.

Executes a abortInternal() invocation;

Annotations
@Override
Exceptions
SQLException:
if an error occurs
doCloseback to summary
pack-priv void doClose() throws SQLException

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.doClose.

Doc from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.doClose.

Executes a close() invocation;

Annotations
@Override
Exceptions
SQLException:
if an error occurs
doPingback to summary
public void doPing() throws SQLException

Implements com.mysql.cj.PingTarget.doPing.

Pings both l/b connections. Switch to another connection in case of failure.

Annotations
@Override
getConnectionGroupIdback to summary
public long getConnectionGroupId()
getConnectionUrlback to summary
private ReplicationConnectionUrl getConnectionUrl()
getCurrentConnectionback to summary
public JdbcConnection getCurrentConnection()
getNewWrapperForThisAsConnectionback to summary
pack-priv JdbcConnection getNewWrapperForThisAsConnection() throws SQLException

Overrides com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.getNewWrapperForThisAsConnection.

Wraps this object with a new replication Connection instance.

Returns:JdbcConnection

The connection object instance that wraps 'this'.

Annotations
@Override
Exceptions
SQLException:

Doc from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.getNewWrapperForThisAsConnection.

if an error occurs

getReplicaHostback to summary
private HostInfo getReplicaHost(String hostPortPair)
getReplicasConnectionback to summary
public JdbcConnection getReplicasConnection()
getSourceConnectionback to summary
public JdbcConnection getSourceConnection()
getSourceHostback to summary
private HostInfo getSourceHost(String hostPortPair)
initializeReplicasConnectionback to summary
private JdbcConnection initializeReplicasConnection() throws SQLException
initializeSourceConnectionback to summary
private JdbcConnection initializeSourceConnection() throws SQLException
invokeMoreback to summary
pack-priv Object invokeMore(Object proxy, Method method, Object[] args) throws Throwable

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.invokeMore.

Proxies method invocation on the java.sql.Connection interface. This is the continuation of MultiHostConnectionProxy#invoke(Object, Method, Object[]).

Parameters
proxy:Object

Doc from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.invokeMore.

proxy object

method:Method

Doc from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.invokeMore.

method to invoke

args:Object[]

Doc from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.invokeMore.

method parameters

Returns:Object

Doc from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.invokeMore.

method result

Annotations
@Override
Exceptions
Throwable:

Doc from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.invokeMore.

if an error occurs

isHostReplicaback to summary
public boolean isHostReplica(String hostPortPair)
isHostSourceback to summary
public boolean isHostSource(String hostPortPair)
isReadOnlyback to summary
public boolean isReadOnly() throws SQLException
isReplicasConnectionback to summary
public boolean isReplicasConnection()

Checks if current connection is the replicas l/b connection.

Returns:boolean

true if current connection is the replicas l/b connection

isSourceConnectionback to summary
public boolean isSourceConnection()

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.isSourceConnection.

Checks if current connection is the sources l/b connection.

Returns:boolean

Doc from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.isSourceConnection.

true if current connection is to a source host

Annotations
@Override
pickNewConnectionback to summary
pack-priv void pickNewConnection() throws SQLException

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.pickNewConnection.

Doc from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.pickNewConnection.

Picks the "best" connection to use from now on. Each subclass needs to implement its connection switch strategy on it.

Annotations
@Override
Exceptions
SQLException:
if an error occurs
promoteReplicaToSourceback to summary
public void promoteReplicaToSource(String hostPortPair) throws SQLException
propagateProxyDownback to summary
protected void propagateProxyDown(JdbcConnection proxyConn)

Overrides com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.propagateProxyDown.

Propagates the connection proxy down through all live connections.

Parameters
proxyConn:JdbcConnection

The top level connection in the multi-host connections chain.

Annotations
@Override
removeReplicaback to summary
public void removeReplica(String hostPortPair) throws SQLException
removeReplicaback to summary
public void removeReplica(String hostPortPair, boolean closeGently) throws SQLException
removeSourceHostback to summary
public void removeSourceHost(String hostPortPair) throws SQLException
removeSourceHostback to summary
public void removeSourceHost(String hostPortPair, boolean waitUntilNotInUse) throws SQLException
removeSourceHostback to summary
public void removeSourceHost(String hostPortPair, boolean waitUntilNotInUse, boolean isNowReplica) throws SQLException
resetReadFromSourceWhenNoReplicasback to summary
private void resetReadFromSourceWhenNoReplicas()
setReadOnlyback to summary
public void setReadOnly(boolean readOnly) throws SQLException
shouldExceptionTriggerConnectionSwitchback to summary
pack-priv boolean shouldExceptionTriggerConnectionSwitch(Throwable t)

Implements abstract com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.shouldExceptionTriggerConnectionSwitch.

Has no use in replication connections. Always return false.

Parameters
t:Throwable

The Exception instance to check.

Returns:boolean

Doc from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.shouldExceptionTriggerConnectionSwitch.

true if the given throwable should trigger a connection switch

Annotations
@Override
switchToReplicasConnectionback to summary
private boolean switchToReplicasConnection() throws SQLException
switchToReplicasConnectionIfNecessaryback to summary
private boolean switchToReplicasConnectionIfNecessary() throws SQLException
switchToSourceConnectionback to summary
private boolean switchToSourceConnection() throws SQLException
syncSessionStateback to summary
pack-priv void syncSessionState(JdbcConnection source, JdbcConnection target, boolean readonly) throws SQLException

Overrides com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.syncSessionState.

Doc from com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.syncSessionState.

Synchronizes session state between two connections, allowing to override the read-only status.

Parameters
source:JdbcConnection

The connection where to get state from.

target:JdbcConnection

The connection where to set state.

readonly:boolean

The new read-only status.

Annotations
@Override
Exceptions
SQLException:
if an error occurs