Package com.mysql.cj.jdbc.ha
Class ReplicationConnectionGroup
java.lang.Object
com.mysql.cj.jdbc.ha.ReplicationConnectionGroup
public class ReplicationConnectionGroup
extends java.lang.Object
Group of connection objects which can be configured as a group. This is used for promotion/demotion of replicas and sources in a replication configuration,
and for exposing metrics around replication-aware connections.
-
Method Summary
Modifier and Type Method Description voidaddReplicaHost(java.lang.String hostPortPair)Adds a host to the replicas hosts list.voidaddSlaveHost(java.lang.String hostPortPair)Deprecated.longgetActiveConnectionCount()longgetConnectionCount()intgetConnectionCountWithHostAsMaster(java.lang.String hostPortPair)Deprecated.intgetConnectionCountWithHostAsReplica(java.lang.String hostPortPair)intgetConnectionCountWithHostAsSlave(java.lang.String hostPortPair)Deprecated.intgetConnectionCountWithHostAsSource(java.lang.String hostPortPair)java.lang.StringgetGroupName()java.util.Collection<java.lang.String>getMasterHosts()Deprecated.longgetNumberOfReplicaPromotions()longgetNumberOfReplicasAdded()longgetNumberOfReplicasRemoved()longgetNumberOfSlavePromotions()Deprecated.longgetNumberOfSlavesAdded()Deprecated.longgetNumberOfSlavesRemoved()Deprecated.java.util.Collection<java.lang.String>getReplicaHosts()java.util.Collection<java.lang.String>getSlaveHosts()Deprecated.java.util.Collection<java.lang.String>getSourceHosts()longgetTotalConnectionCount()voidhandleCloseConnection(ReplicationConnection conn)voidpromoteReplicaToSource(java.lang.String hostPortPair)Promotes a replica host to source.voidpromoteSlaveToMaster(java.lang.String hostPortPair)Deprecated.longregisterReplicationConnection(ReplicationConnection conn, java.util.List<java.lang.String> localSourceList, java.util.List<java.lang.String> localReplicaList)voidremoveMasterHost(java.lang.String hostPortPair)Deprecated.voidremoveMasterHost(java.lang.String hostPortPair, boolean closeGently)Deprecated.voidremoveReplicaHost(java.lang.String hostPortPair, boolean closeGently)Removes a host from the replicas hosts list.voidremoveSlaveHost(java.lang.String hostPortPair, boolean closeGently)Deprecated.voidremoveSourceHost(java.lang.String hostPortPair)Removes a host from the sources hosts list.voidremoveSourceHost(java.lang.String hostPortPair, boolean closeGently)Removes a host from the sources hosts list.java.lang.StringtoString()
-
Method Details
-
getConnectionCount
public long getConnectionCount() -
registerReplicationConnection
public long registerReplicationConnection(ReplicationConnection conn, java.util.List<java.lang.String> localSourceList, java.util.List<java.lang.String> localReplicaList) -
getGroupName
public java.lang.String getGroupName() -
getSourceHosts
public java.util.Collection<java.lang.String> getSourceHosts() -
getMasterHosts
@Deprecated public java.util.Collection<java.lang.String> getMasterHosts()Deprecated.UsegetSourceHosts()instead.- Returns:
- source hosts
-
getReplicaHosts
public java.util.Collection<java.lang.String> getReplicaHosts() -
getSlaveHosts
@Deprecated public java.util.Collection<java.lang.String> getSlaveHosts()Deprecated.UsegetReplicaHosts()instead.- Returns:
- replica hosts
-
addReplicaHost
public void addReplicaHost(java.lang.String hostPortPair) throws java.sql.SQLExceptionAdds a host to the replicas hosts list. We can safely assume that if this host was added to the replicas list, then it must be added to each one of the replication connections from this group as well. Unnecessary calls toReplicationConnection.addReplicaHost(String)could result in undesirable locking issues, assuming that this method is synchronized by nature. This is a no-op if the group already has this host in a replica role.- Parameters:
hostPortPair- "host:port"- Throws:
java.sql.SQLException- if an error occurs
-
addSlaveHost
@Deprecated public void addSlaveHost(java.lang.String hostPortPair) throws java.sql.SQLExceptionDeprecated.UseaddReplicaHost(String)instead.- Parameters:
hostPortPair- host:port- Throws:
java.sql.SQLException
-
handleCloseConnection
-
removeReplicaHost
public void removeReplicaHost(java.lang.String hostPortPair, boolean closeGently) throws java.sql.SQLExceptionRemoves a host from the replicas hosts list. We can safely assume that if this host was removed from the replicas list, then it must be removed from each one of the replication connections from this group as well. Unnecessary calls toReplicationConnection.removeReplica(String, boolean)could result in undesirable locking issues, assuming that this method is synchronized by nature. This is a no-op if the group doesn't have this host in a replica role.- Parameters:
hostPortPair- "host:port"closeGently- remove host when it's not in use- Throws:
java.sql.SQLException- if an error occurs
-
removeSlaveHost
@Deprecated public void removeSlaveHost(java.lang.String hostPortPair, boolean closeGently) throws java.sql.SQLExceptionDeprecated.UseremoveReplicaHost(String, boolean)instead.- Parameters:
hostPortPair- host:portcloseGently- option- Throws:
java.sql.SQLException
-
promoteReplicaToSource
public void promoteReplicaToSource(java.lang.String hostPortPair) throws java.sql.SQLExceptionPromotes a replica host to source. We can safely assume that if this host was removed from the replicas list or added to the sources list, then the same host promotion must happen in each one of the replication connections from this group as well. Unnecessary calls toReplicationConnection.promoteReplicaToSource(String)could result in undesirable locking issues, assuming that this method is synchronized by nature. This is a no-op if the group already has this host in a source role and not in replica role.- Parameters:
hostPortPair- "host:port"- Throws:
java.sql.SQLException- if an error occurs
-
promoteSlaveToMaster
@Deprecated public void promoteSlaveToMaster(java.lang.String hostPortPair) throws java.sql.SQLExceptionDeprecated.UsepromoteReplicaToSource(String)instead.- Parameters:
hostPortPair- host:port- Throws:
java.sql.SQLException
-
removeSourceHost
public void removeSourceHost(java.lang.String hostPortPair) throws java.sql.SQLExceptionRemoves a host from the sources hosts list.- Parameters:
hostPortPair- host:port- Throws:
java.sql.SQLException- if an error occurs
-
removeMasterHost
@Deprecated public void removeMasterHost(java.lang.String hostPortPair) throws java.sql.SQLExceptionDeprecated.UseremoveSourceHost(String)instead.- Parameters:
hostPortPair- host:port- Throws:
java.sql.SQLException
-
removeSourceHost
public void removeSourceHost(java.lang.String hostPortPair, boolean closeGently) throws java.sql.SQLExceptionRemoves a host from the sources hosts list. We can safely assume that if this host was removed from the sources list, then it must be removed from each one of the replication connections from this group as well. Unnecessary calls toReplicationConnection.removeSourceHost(String, boolean)could result in undesirable locking issues, assuming that this method is synchronized by nature. This is a no-op if the group doesn't have this host in a source role.- Parameters:
hostPortPair- "host:port"closeGently- remove host when it's not in use- Throws:
java.sql.SQLException- if an error occurs
-
removeMasterHost
@Deprecated public void removeMasterHost(java.lang.String hostPortPair, boolean closeGently) throws java.sql.SQLExceptionDeprecated.UseremoveSourceHost(String, boolean)instead.- Parameters:
hostPortPair- host:portcloseGently- option- Throws:
java.sql.SQLException
-
getConnectionCountWithHostAsReplica
public int getConnectionCountWithHostAsReplica(java.lang.String hostPortPair) -
getConnectionCountWithHostAsSlave
@Deprecated public int getConnectionCountWithHostAsSlave(java.lang.String hostPortPair)Deprecated.UsegetConnectionCountWithHostAsReplica(String)instead.- Parameters:
hostPortPair- host:port- Returns:
- count
-
getConnectionCountWithHostAsSource
public int getConnectionCountWithHostAsSource(java.lang.String hostPortPair) -
getConnectionCountWithHostAsMaster
@Deprecated public int getConnectionCountWithHostAsMaster(java.lang.String hostPortPair)Deprecated.UsegetConnectionCountWithHostAsSource(String)instead.- Parameters:
hostPortPair- host:port- Returns:
- count
-
getNumberOfReplicasAdded
public long getNumberOfReplicasAdded() -
getNumberOfSlavesAdded
@Deprecated public long getNumberOfSlavesAdded()Deprecated.UsegetNumberOfReplicasAdded()instead.- Returns:
- count
-
getNumberOfReplicasRemoved
public long getNumberOfReplicasRemoved() -
getNumberOfSlavesRemoved
@Deprecated public long getNumberOfSlavesRemoved()Deprecated.UsegetNumberOfReplicasRemoved()instead.- Returns:
- count
-
getNumberOfReplicaPromotions
public long getNumberOfReplicaPromotions() -
getNumberOfSlavePromotions
@Deprecated public long getNumberOfSlavePromotions()Deprecated.UsegetNumberOfReplicaPromotions()instead.- Returns:
- count
-
getTotalConnectionCount
public long getTotalConnectionCount() -
getActiveConnectionCount
public long getActiveConnectionCount() -
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-