类 LoadBalancedConnectionProxy

  • 所有已实现的接口:
    PingTarget, InvocationHandler

    public class LoadBalancedConnectionProxy
    extends MultiHostConnectionProxy
    implements PingTarget
    A proxy for a dynamic com.mysql.cj.jdbc.JdbcConnection implementation that load balances requests across a series of MySQL JDBC connections, where the balancing takes place at transaction commit. Therefore, for this to work (at all), you must use transactions, even if only reading data. This implementation will invalidate connections that it detects have had communication errors when processing a request. Problematic hosts will be added to a global blocklist for loadBalanceBlocklistTimeout ms, after which they will be removed from the blocklist and made eligible once again to be selected for new connections. This implementation is thread-safe, but it's questionable whether sharing a connection instance amongst threads is a good idea, given that transactions are scoped to connections in JDBC.
    • 构造器详细资料

      • LoadBalancedConnectionProxy

        public LoadBalancedConnectionProxy​(ConnectionUrl connectionUrl)
                                    throws SQLException
        Creates a proxy for java.sql.Connection that routes requests between the hosts in the connection URL.
        参数:
        connectionUrl - The connection URL containing the hosts to load balance.
        抛出:
        SQLException - if an error occurs
    • 方法详细资料

      • propagateProxyDown

        protected void propagateProxyDown​(JdbcConnection proxyConn)
        Propagates the connection proxy down through all live connections.
        覆盖:
        propagateProxyDown 在类中 MultiHostConnectionProxy
        参数:
        proxyConn - The top level connection in the multi-host connections chain.
      • shouldExceptionTriggerFailover

        @Deprecated
        public boolean shouldExceptionTriggerFailover​(Throwable t)
        已过时。
      • pickNewConnection

        public void pickNewConnection()
                               throws SQLException
        Picks the "best" connection to use for the next transaction based on the BalanceStrategy in use.
        抛出:
        SQLException - if an error occurs
      • createConnectionForHost

        public ConnectionImpl createConnectionForHost​(HostInfo hostInfo)
                                               throws SQLException
        Creates a new physical connection for the given HostInfo and updates required internal mappings and statistics for that connection.
        参数:
        hostInfo - The host info instance.
        返回:
        The new Connection instance.
        抛出:
        SQLException - if an error occurs
      • createConnectionForHost

        public ConnectionImpl createConnectionForHost​(String hostPortPair)
                                               throws SQLException
        Creates a new physical connection for the given host:port info. If the this connection's connection URL knows about this host:port then its host info is used, otherwise a new host info based on current connection URL defaults is spawned.
        参数:
        hostPortPair - The host:port pair identifying the host to connect to.
        返回:
        The new Connection instance.
        抛出:
        SQLException - if an error occurs
      • addToGlobalBlocklist

        public void addToGlobalBlocklist​(String host,
                                         long timeout)
        Adds a host to the blocklist with the given timeout.
        参数:
        host - The host to be blocklisted.
        timeout - The blocklist timeout for this entry.
      • removeFromGlobalBlocklist

        public void removeFromGlobalBlocklist​(String host)
        Removes a host from the blocklist.
        参数:
        host - The host to be removed from the blocklist.
      • addToGlobalBlocklist

        public void addToGlobalBlocklist​(String host)
        Adds a host to the blocklist.
        参数:
        host - The host to be blocklisted.
      • isGlobalBlocklistEnabled

        public boolean isGlobalBlocklistEnabled()
        Checks if host blocklist management was enabled.
        返回:
        true if host blocklist management was enabled
      • isGlobalBlacklistEnabled

        @Deprecated
        public boolean isGlobalBlacklistEnabled()
        已过时。
        返回:
        true if host blocklist management was enabled
      • getGlobalBlocklist

        public Map<String,​Long> getGlobalBlocklist()
        Returns a local hosts blocklist, while cleaning up expired records from the global blocklist, or a blocklist with the hosts to be removed.
        返回:
        A local hosts blocklist.
      • removeHostWhenNotInUse

        public void removeHostWhenNotInUse​(String hostPortPair)
                                    throws SQLException
        Removes a host from the host list, allowing it some time to be released gracefully if needed.
        参数:
        hostPortPair - The host to be removed.
        抛出:
        SQLException - if an error occurs
      • removeHost

        public void removeHost​(String hostPortPair)
                        throws SQLException
        Removes a host from the host list.
        参数:
        hostPortPair - The host to be removed.
        抛出:
        SQLException - if an error occurs
      • addHost

        public boolean addHost​(String hostPortPair)
        Adds a host to the hosts list.
        参数:
        hostPortPair - The host to be added.
        返回:
        true if host was added and false if the host list already contains it
      • inTransaction

        public boolean inTransaction()
      • getTransactionCount

        public long getTransactionCount()
      • getActivePhysicalConnectionCount

        public long getActivePhysicalConnectionCount()
      • getTotalPhysicalConnectionCount

        public long getTotalPhysicalConnectionCount()
      • getConnectionGroupProxyID

        public long getConnectionGroupProxyID()
      • getCurrentActiveHost

        public String getCurrentActiveHost()
      • getCurrentTransactionDuration

        public long getCurrentTransactionDuration()