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 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.
      Use getSourceHosts() instead.
      Returns:
      source hosts
    • getReplicaHosts

      public java.util.Collection<java.lang.String> getReplicaHosts()
    • getSlaveHosts

      @Deprecated public java.util.Collection<java.lang.String> getSlaveHosts()
      Deprecated.
      Use getReplicaHosts() instead.
      Returns:
      replica hosts
    • addReplicaHost

      public void addReplicaHost​(java.lang.String hostPortPair) throws java.sql.SQLException
      Adds 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 to ReplicationConnection.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.SQLException
      Deprecated.
      Parameters:
      hostPortPair - host:port
      Throws:
      java.sql.SQLException
    • handleCloseConnection

      public void handleCloseConnection​(ReplicationConnection conn)
    • removeReplicaHost

      public void removeReplicaHost​(java.lang.String hostPortPair, boolean closeGently) throws java.sql.SQLException
      Removes 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 to ReplicationConnection.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.SQLException
      Deprecated.
      Parameters:
      hostPortPair - host:port
      closeGently - option
      Throws:
      java.sql.SQLException
    • promoteReplicaToSource

      public void promoteReplicaToSource​(java.lang.String hostPortPair) throws java.sql.SQLException
      Promotes 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 to ReplicationConnection.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.SQLException
      Deprecated.
      Parameters:
      hostPortPair - host:port
      Throws:
      java.sql.SQLException
    • removeSourceHost

      public void removeSourceHost​(java.lang.String hostPortPair) throws java.sql.SQLException
      Removes 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.SQLException
      Deprecated.
      Parameters:
      hostPortPair - host:port
      Throws:
      java.sql.SQLException
    • removeSourceHost

      public void removeSourceHost​(java.lang.String hostPortPair, boolean closeGently) throws java.sql.SQLException
      Removes 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 to ReplicationConnection.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.SQLException
      Deprecated.
      Parameters:
      hostPortPair - host:port
      closeGently - option
      Throws:
      java.sql.SQLException
    • getConnectionCountWithHostAsReplica

      public int getConnectionCountWithHostAsReplica​(java.lang.String hostPortPair)
    • getConnectionCountWithHostAsSlave

      @Deprecated public int getConnectionCountWithHostAsSlave​(java.lang.String hostPortPair)
      Deprecated.
      Parameters:
      hostPortPair - host:port
      Returns:
      count
    • getConnectionCountWithHostAsSource

      public int getConnectionCountWithHostAsSource​(java.lang.String hostPortPair)
    • getConnectionCountWithHostAsMaster

      @Deprecated public int getConnectionCountWithHostAsMaster​(java.lang.String hostPortPair)
      Deprecated.
      Parameters:
      hostPortPair - host:port
      Returns:
      count
    • getNumberOfReplicasAdded

      public long getNumberOfReplicasAdded()
    • getNumberOfSlavesAdded

      @Deprecated public long getNumberOfSlavesAdded()
      Deprecated.
      Returns:
      count
    • getNumberOfReplicasRemoved

      public long getNumberOfReplicasRemoved()
    • getNumberOfSlavesRemoved

      @Deprecated public long getNumberOfSlavesRemoved()
      Deprecated.
      Returns:
      count
    • getNumberOfReplicaPromotions

      public long getNumberOfReplicaPromotions()
    • getNumberOfSlavePromotions

      @Deprecated public long getNumberOfSlavePromotions()
      Deprecated.
      Returns:
      count
    • getTotalConnectionCount

      public long getTotalConnectionCount()
    • getActiveConnectionCount

      public long getActiveConnectionCount()
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object