Class ClickHouseLoadBalancingPolicy

  • All Implemented Interfaces:
    Serializable

    public abstract class ClickHouseLoadBalancingPolicy
    extends Object
    implements Serializable
    Load balancing policy. In general, a policy is responsible for 3 things: 1) get node from a managed list; 2) managing node's status; and 3) optionally schedule background tasks like node discovery and health check.
    See Also:
    Serialized Form
    • Constructor Detail

      • ClickHouseLoadBalancingPolicy

        public ClickHouseLoadBalancingPolicy()
    • Method Detail

      • getQueryForAllLocalNodes

        protected String getQueryForAllLocalNodes()
        Gets a SQL query for finding all local nodes regardless which cluster it belongs to. Defaults to QUERY_GET_ALL_NODES.
        Returns:
        non-null SQL query
      • getQueryForClusterLocalNodes

        protected String getQueryForClusterLocalNodes()
        Gets a parameterized SQL query for finding all local nodes of a specific cluster. Defaults to QUERY_GET_CLUSTER_NODES.
        Returns:
        non-null SQL query
      • getQueryForNonLocalNodes

        protected String getQueryForNonLocalNodes()
        Gets a parameterized SQL query for finding all non-local nodes in one or many clusters. Defaults to QUERY_GET_OTHER_NODES.
        Returns:
        non-null SQL query
      • get

        protected final ClickHouseNode get​(ClickHouseNodes manager)
        Gets next node available in the list.
        Parameters:
        manager - managed nodes
        Returns:
        next node
      • suggest

        protected ClickHouseNode suggest​(ClickHouseNodes manager,
                                         ClickHouseNode server,
                                         Throwable failure)
        Sugguests a new node as replacement of the given one in order to recover from the failure, which is usually a connection error.
        Parameters:
        manager - non-null manager for finding suitable node
        server - non-null server to replace
        failure - non-null recoverable exception
        Returns:
        new server, or the exact same server from input when running out of options
      • getScheduler

        protected ScheduledExecutorService getScheduler()
        Gets scheduled executor service for auto discovery and health check.
        Returns:
        scheduled executor service, null will turn off auto discovery and health check
      • schedule

        protected ScheduledFuture<?> schedule​(ScheduledFuture<?> current,
                                              Runnable task,
                                              long interval)
        Schedules the task to run only when current run has been completed/cancelled or does not exist.
        Parameters:
        current - current task, which could be null or in running status
        task - scheduled task to run
        interval - interval between each run
        Returns:
        future object representing the scheduled task, could be null when no scheduler available(getScheduler() returns null)