2
2
3
3
## Introduction
4
4
5
- The driver uses a load balancing policy to determine which node(s) to contact
6
- when executing a query. Load balancing policies implement the
5
+ The driver uses a load balancing policy to determine which node(s) and shard(s)
6
+ to contact when executing a query. Load balancing policies implement the
7
7
` LoadBalancingPolicy ` trait, which contains methods to generate a load
8
8
balancing plan based on the query information and the state of the cluster.
9
9
@@ -12,12 +12,14 @@ being opened. For a node connection blacklist configuration refer to
12
12
` scylla::transport::host_filter::HostFilter ` , which can be set session-wide
13
13
using ` SessionBuilder::host_filter ` method.
14
14
15
+ In this chapter, "target" will refer to a pair ` <node, optional shard> ` .
16
+
15
17
## Plan
16
18
17
19
When a query is prepared to be sent to the database, the load balancing policy
18
- constructs a load balancing plan. This plan is essentially a list of nodes to
20
+ constructs a load balancing plan. This plan is essentially a list of targets to
19
21
which the driver will try to send the query. The first elements of the plan are
20
- the nodes which are the best to contact (e.g. they might be replicas for the
22
+ the targets which are the best to contact (e.g. they might be replicas for the
21
23
requested data or have the best latency).
22
24
23
25
## Policy
@@ -84,17 +86,16 @@ first element of the load balancing plan is needed, so it's usually unnecessary
84
86
to compute entire load balancing plan. To optimize this common case, the
85
87
` LoadBalancingPolicy ` trait provides two methods: ` pick ` and ` fallback ` .
86
88
87
- ` pick ` returns the first node to contact for a given query, which is usually
88
- the best based on a particular load balancing policy. If ` pick ` returns ` None ` ,
89
- then ` fallback ` will not be called.
89
+ ` pick ` returns the first target to contact for a given query, which is usually
90
+ the best based on a particular load balancing policy.
90
91
91
- ` fallback ` , returns an iterator that provides the rest of the nodes in the load
92
- balancing plan. ` fallback ` is called only when using the initial picked node
93
- fails (or when executing speculatively).
92
+ ` fallback ` , returns an iterator that provides the rest of the targets in the
93
+ load balancing plan. ` fallback ` is called when using the initial picked
94
+ target fails (or when executing speculatively) or when ` pick ` returned ` None ` .
94
95
95
- It's possible for the ` fallback ` method to include the same node that was
96
+ It's possible for the ` fallback ` method to include the same target that was
96
97
returned by the ` pick ` method. In such cases, the query execution layer filters
97
- out the picked node from the iterator returned by ` fallback ` .
98
+ out the picked target from the iterator returned by ` fallback ` .
98
99
99
100
### ` on_query_success ` and ` on_query_failure ` :
100
101
0 commit comments