2
2
3
3
## Introduction
4
4
5
- The driver uses a load balancing policy to determine which node(s) to contact
5
+ The driver uses a load balancing policy to determine which node(s) and shard(s) to contact
6
6
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.
@@ -15,11 +15,13 @@ using `SessionBuilder::host_filter` method.
15
15
## Plan
16
16
17
17
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
18
+ constructs a load balancing plan. This plan is essentially a list of pairs of node and optional shard to
19
19
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
20
+ the nodes+shards which are the best to contact (e.g. they might be replicas for the
21
21
requested data or have the best latency).
22
22
23
+ In this chapter, "element" will refer to a pair of node and optional shard.
24
+
23
25
## Policy
24
26
25
27
The Scylla/Cassandra driver provides a default load balancing policy (see
@@ -84,15 +86,15 @@ 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
89
+ ` pick ` returns the first element to contact for a given query, which is usually
88
90
the best based on a particular load balancing policy. If ` pick ` returns ` None ` ,
89
91
then ` fallback ` will not be called.
90
92
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
+ ` fallback ` , returns an iterator that provides the rest of the elements in the load
94
+ balancing plan. ` fallback ` is called only when using the initial picked element
93
95
fails (or when executing speculatively).
94
96
95
- It's possible for the ` fallback ` method to include the same node that was
97
+ It's possible for the ` fallback ` method to include the same element that was
96
98
returned by the ` pick ` method. In such cases, the query execution layer filters
97
99
out the picked node from the iterator returned by ` fallback ` .
98
100
0 commit comments