类 ReplicationConnectionGroup
- java.lang.Object
-
- com.mysql.cj.jdbc.ha.ReplicationConnectionGroup
-
public class ReplicationConnectionGroup extends Object
Group of connection objects which can be configured as a group. This is used for promotion/demotion of slaves and masters in a replication configuration, and for exposing metrics around replication-aware connections.
-
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidaddSlaveHost(String hostPortPair)Adds a host to the slaves hosts list.longgetActiveConnectionCount()longgetConnectionCount()intgetConnectionCountWithHostAsMaster(String hostPortPair)intgetConnectionCountWithHostAsSlave(String hostPortPair)StringgetGroupName()Collection<String>getMasterHosts()longgetNumberOfSlavePromotions()longgetNumberOfSlavesAdded()longgetNumberOfSlavesRemoved()Collection<String>getSlaveHosts()longgetTotalConnectionCount()voidhandleCloseConnection(ReplicationConnection conn)voidpromoteSlaveToMaster(String hostPortPair)Promotes a slave host to master.longregisterReplicationConnection(ReplicationConnection conn, List<String> localMasterList, List<String> localSlaveList)voidremoveMasterHost(String hostPortPair)Removes a host from the masters hosts list.voidremoveMasterHost(String hostPortPair, boolean closeGently)Removes a host from the masters hosts list.voidremoveSlaveHost(String hostPortPair, boolean closeGently)Removes a host from the slaves hosts list.StringtoString()
-
-
-
方法详细资料
-
getConnectionCount
public long getConnectionCount()
-
registerReplicationConnection
public long registerReplicationConnection(ReplicationConnection conn, List<String> localMasterList, List<String> localSlaveList)
-
getGroupName
public String getGroupName()
-
getMasterHosts
public Collection<String> getMasterHosts()
-
getSlaveHosts
public Collection<String> getSlaveHosts()
-
addSlaveHost
public void addSlaveHost(String hostPortPair) throws SQLException
Adds a host to the slaves hosts list. We can safely assume that if this host was added to the slaves list, then it must be added to each one of the replication connections from this group as well. Unnecessary calls toReplicationConnection.addSlaveHost(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 slave role.- 参数:
hostPortPair- "host:port"- 抛出:
SQLException- if an error occurs
-
handleCloseConnection
public void handleCloseConnection(ReplicationConnection conn)
-
removeSlaveHost
public void removeSlaveHost(String hostPortPair, boolean closeGently) throws SQLException
Removes a host from the slaves hosts list. We can safely assume that if this host was removed from the slaves list, then it must be removed from each one of the replication connections from this group as well. Unnecessary calls toReplicationConnection.removeSlave(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 slave role.- 参数:
hostPortPair- "host:port"closeGently- remove host when it's not in use- 抛出:
SQLException- if an error occurs
-
promoteSlaveToMaster
public void promoteSlaveToMaster(String hostPortPair) throws SQLException
Promotes a slave host to master. We can safely assume that if this host was removed from the slaves list or added to the masters list, then the same host promotion must happen in each one of the replication connections from this group as well. Unnecessary calls toReplicationConnection.promoteSlaveToMaster(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 master role and not in slave role.- 参数:
hostPortPair- "host:port"- 抛出:
SQLException- if an error occurs
-
removeMasterHost
public void removeMasterHost(String hostPortPair) throws SQLException
Removes a host from the masters hosts list.- 参数:
hostPortPair- host:port- 抛出:
SQLException- if an error occurs
-
removeMasterHost
public void removeMasterHost(String hostPortPair, boolean closeGently) throws SQLException
Removes a host from the masters hosts list. We can safely assume that if this host was removed from the masters list, then it must be removed from each one of the replication connections from this group as well. Unnecessary calls toReplicationConnection.removeMasterHost(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 master role.- 参数:
hostPortPair- "host:port"closeGently- remove host when it's not in use- 抛出:
SQLException- if an error occurs
-
getConnectionCountWithHostAsSlave
public int getConnectionCountWithHostAsSlave(String hostPortPair)
-
getConnectionCountWithHostAsMaster
public int getConnectionCountWithHostAsMaster(String hostPortPair)
-
getNumberOfSlavesAdded
public long getNumberOfSlavesAdded()
-
getNumberOfSlavesRemoved
public long getNumberOfSlavesRemoved()
-
getNumberOfSlavePromotions
public long getNumberOfSlavePromotions()
-
getTotalConnectionCount
public long getTotalConnectionCount()
-
getActiveConnectionCount
public long getActiveConnectionCount()
-
-