Skip to content

Commit 8dedad4

Browse files
committed
Document TABLETS_ROUTING_V2 tablet-version tracking and leader-aware routing
Extend the "Tablet Awareness" section of the Scylla-specific guide to cover the V2 protocol extension: the per-connection negotiation, the tablet_version_block byte that lets the server skip re-sending routing information the driver already has, and leader-aware routing for strongly-consistent (Raft-backed) tablet tables. Also document the strongly_consistent flag now exposed on keyspace metadata.
1 parent 4205343 commit 8dedad4

1 file changed

Lines changed: 56 additions & 1 deletion

File tree

docs/scylla-specific.rst

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,66 @@ For more details on paging, see :ref:`query-paging`.
148148
Tablet Awareness
149149
----------------
150150

151-
**scylla-driver** is tablet-aware, which means that it is able to parse `TABLETS_ROUTING_V1` extension to ProtocolFeatures, recieve tablet information sent by Scylla in the `custom_payload` part of the `RESULT` message, and utilize it.
151+
**scylla-driver** is tablet-aware, which means that it is able to parse the `TABLETS_ROUTING_V1` and `TABLETS_ROUTING_V2` extensions to ProtocolFeatures, receive tablet information sent by Scylla in the `custom_payload` part of the `RESULT` message, and utilize it.
152152
Thanks to this, queries to tablet-based tables are still shard-aware.
153153

154154
Details on the scylla cql protocol extensions
155155
https://github.com/scylladb/scylladb/blob/master/docs/dev/protocol-extensions.md#negotiate-sending-tablets-info-to-the-drivers
156156

157157
Details on the sending tablet information to the drivers
158158
https://github.com/scylladb/scylladb/blob/master/docs/dev/protocol-extensions.md#sending-tablet-info-to-the-drivers
159+
160+
161+
Tablet version tracking and leader-aware routing
162+
------------------------------------------------
163+
164+
When the cluster offers it, the driver negotiates ``TABLETS_ROUTING_V2`` in
165+
preference to V1. The negotiation happens per connection, so a mixed-version
166+
cluster during a rolling upgrade is handled transparently. V2 adds two
167+
capabilities on top of V1, both invisible to application code.
168+
169+
**Tablet version tracking.** Every tablet now carries a ``tablet_version`` that
170+
changes whenever its replica set is reconfigured. The driver caches the version
171+
it last saw for each tablet and, on every prepared-statement execution over a V2
172+
connection, appends a single ``tablet_version_block`` byte derived from it. The
173+
server returns updated routing information in the ``custom_payload`` only when
174+
that byte shows the driver's cached view is stale, instead of attaching it to
175+
every response. This keeps the cached routing information fresh while avoiding
176+
the per-response overhead that V1 incurs.
177+
178+
**Leader-aware routing for strongly-consistent tables.** Tables in a
179+
strongly-consistent keyspace -- one created with a ``consistency`` option and
180+
backed by Raft -- have a tablet leader that coordinates operations. For those
181+
tables the driver sends each request directly to the leader, saving the extra
182+
hop the coordinator would otherwise take to forward it. Eventually-consistent
183+
tables are unaffected and keep their usual token-aware (optionally shuffled)
184+
replica ordering.
185+
186+
Leader-aware routing is best-effort and bounded by the load-balancing policy:
187+
the leader is only targeted directly if the wrapped policy would consider it in
188+
the first place. For example, a ``DCAwareRoundRobinPolicy`` configured with no
189+
remote hosts will not send cross-datacenter traffic to a leader in another
190+
datacenter; the request goes to a local replica and the server forwards it to
191+
the leader, exactly as it would without V2.
192+
193+
No configuration is required: as with V1, a ``TokenAwarePolicy`` is all that is
194+
needed. Whether a keyspace is strongly consistent is also surfaced on its
195+
metadata, should you need it:
196+
197+
.. code:: python
198+
199+
from cassandra.cluster import Cluster
200+
201+
cluster = Cluster()
202+
session = cluster.connect()
203+
204+
ks = cluster.metadata.keyspaces["my_keyspace"]
205+
if ks.strongly_consistent:
206+
print("requests to this keyspace's tablet tables are routed to the leader")
207+
208+
.. note::
209+
210+
While strongly-consistent tables are gated behind Scylla's
211+
``STRONGLY_CONSISTENT_TABLES`` cluster feature, the extension is advertised
212+
on the wire as ``TABLETS_ROUTING_V2_EXPERIMENTAL``. Connecting to a cluster
213+
that does not offer it transparently falls back to ``TABLETS_ROUTING_V1``.

0 commit comments

Comments
 (0)