liveBook · Manning

Token function

As explained in ScyllaDB in Action

The TOKEN function computes or exposes the token position associated with a database key in the partitioning ring.

The TOKEN function computes the hashed token for a partition-key value and shows where that value lies on ScyllaDB’s hash ring. That position helps connect a row to the node or token range responsible for it. section 8.2.1

Use the function to:

  • Inspect a key’s token with a query such as SELECT TOKEN(id), id FROM reviews.authors; section 8.2.1
  • Restrict bulk reads to token ranges instead of subdividing the ordinary partition-key space, which can involve many or all nodes. section 12.1.1
  • Combine TOKEN predicates with vnode boundaries so each extraction query targets only the necessary node and its replicas. section 12.1.1

Reading one token range

A range query can use conditions such as SELECT * FROM articles WHERE TOKEN(id) >= ... AND TOKEN(id) < ...;. Obtain the range boundaries with nodetool describering reviews, whose output includes start tokens, end tokens, and owning endpoints. section 12.1.1

Figure 12.1 Attempting to export data via performing range queries using the partition key is an inefficient pattern that adds unnecessary load to your cluster, but you can use the TOKEN function to narrow these large queries to a single token range.
figure

Compare inefficient partition-key range queries with TOKEN-based ranges that narrow each operation to a ring slice. section 12.1.1

How ScyllaDB in Action covers it

How deep it goes
Explains hashing, ring placement, CQL predicates, vnode boundaries, and ownership discovery, but stops short of hash-function internals.
Examples
Uses reviews.authors token inspection, articles range queries, nodetool describering output, and Python driver token maps.
What it assumes
Assumes basic partition-key and query knowledge while introducing hash rings, token ownership, and virtual nodes.
What you can do after
Apply CQL token predicates and nodetool range information to perform targeted bulk reads.
How it connects
Connects partition keys to the hash ring, virtual nodes, token ranges, replication, and cluster metadata.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ScyllaDB in Action. The section links point to the parts of the book it draws on.