Package com.clickhouse.client
Class ClickHouseLoadBalancingPolicy
java.lang.Object
com.clickhouse.client.ClickHouseLoadBalancingPolicy
- All Implemented Interfaces:
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSimilar as the default policy, which always picks the first healthy node.static final Stringstatic final Stringstatic final Stringstatic final StringPolicy to pick a healthy node randomly from the list.static final StringPolicy to pick healthy node one after another based their order in the list. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final ClickHouseNodeget(ClickHouseNodes manager) Gets next node available in the list.protected ClickHouseNodeget(ClickHouseNodes manager, ClickHouseNodeSelector t) Gets next node available in the list according to the given node selector.protected StringGets a SQL query for finding all local nodes regardless which cluster it belongs to.protected StringGets a parameterized SQL query for finding all local nodes of a specific cluster.protected StringGets a parameterized SQL query for finding all non-local nodes in one or many clusters.protected ScheduledExecutorServiceGets scheduled executor service for auto discovery and health check.Gets or creates singleton load balancing policy.protected ScheduledFuture<?>schedule(ScheduledFuture<?> current, Runnable task, long interval) Schedules thetaskto run only whencurrentrun has been completed/cancelled or does not exist.protected ClickHouseNodesuggest(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.toString()protected voidupdate(ClickHouseNodes manager, ClickHouseNode node, ClickHouseNode.Status status) Updates node status to one ofClickHouseNode.Status.
-
Field Details
-
QUERY_GET_ALL_NODES
- See Also:
-
QUERY_GET_CLUSTER_NODES
- See Also:
-
QUERY_GET_OTHER_NODES
- See Also:
-
FIRST_ALIVE
Similar as the default policy, which always picks the first healthy node. Besides, it provides scheduler for node discovery and health check.- See Also:
-
RANDOM
Policy to pick a healthy node randomly from the list.- See Also:
-
ROUND_ROBIN
Policy to pick healthy node one after another based their order in the list.- See Also:
-
-
Constructor Details
-
ClickHouseLoadBalancingPolicy
public ClickHouseLoadBalancingPolicy()
-
-
Method Details
-
of
Gets or creates singleton load balancing policy.- Parameters:
name- policy name, one ofFIRST_ALIVE,RANDOMandROUND_ROBIN, or a fully qualified class name- Returns:
- non-null load balancing policy
-
getQueryForAllLocalNodes
Gets a SQL query for finding all local nodes regardless which cluster it belongs to. Defaults toQUERY_GET_ALL_NODES.- Returns:
- non-null SQL query
-
getQueryForClusterLocalNodes
Gets a parameterized SQL query for finding all local nodes of a specific cluster. Defaults toQUERY_GET_CLUSTER_NODES.- Returns:
- non-null SQL query
-
getQueryForNonLocalNodes
Gets a parameterized SQL query for finding all non-local nodes in one or many clusters. Defaults toQUERY_GET_OTHER_NODES.- Returns:
- non-null SQL query
-
get
Gets next node available in the list.- Parameters:
manager- managed nodes- Returns:
- next node
-
get
Gets next node available in the list according to the given node selector.- Parameters:
manager- managed nodest- node selector- Returns:
- next node
- Throws:
IllegalArgumentException- when no node available to use
-
suggest
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 nodeserver- non-null server to replacefailure- non-null recoverable exception- Returns:
- new server, or the exact same server from input when running out of options
-
update
Updates node status to one ofClickHouseNode.Status.- Parameters:
manager- non-null node managernode- non-null node to updatestatus- non-null status of the node
-
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
Schedules thetaskto run only whencurrentrun has been completed/cancelled or does not exist.- Parameters:
current- current task, which could be null or in running statustask- scheduled task to runinterval- interval between each run- Returns:
- future object representing the scheduled task, could be null when no
scheduler available(
getScheduler()returns null)
-
toString
-