Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

biswa333_125242 avatar image
biswa333_125242 asked Erick Ramirez answered

How does the token get assigned by the partitioner?

A partitioner determined how the data is distributed across the nodes in the cluster. It is nothing but a hash function that generates a hash token value to a partition key. After that the token is used to assign (Choose the correct one), my guess is number 1. Can you please confirm ?

  1. The node on which the partition will reside
  2. The row that the partition will be stored on
  3. The table in which the data will be stored.
partitioner
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered

I'm not sure where you got the information but the question doesn't make sense so allow me to explain.

The partitioner determines which node a partition belongs to based on the token value that is returned by hashing the partition key. For example, for partition key Ramirez:

    Murmur3Partitioner( PK = 'Ramirez' ) = -4404190778401486753

Let me use an example cluster to illustrate how tokens and the partitioner work. Here is the output of nodetool ring:

$ nodetool ring community
 
 Datacenter: Cassandra
 ==========
 Address        Rack        Status State   Load            Owns                Token                                       
                                                                               3074457345618258602                         
 10.101.33.146  rack1       Up     Normal  174.98 KiB      33.33%              -9223372036854775808                        
 10.101.33.196  rack1       Up     Normal  164.12 KiB      33.33%              -3074457345618258603                        
 10.101.36.82   rack1       Up     Normal  200.86 KiB      33.33%              3074457345618258602

From this example, here are the range of tokens owned by each node:

  10.101.36.82 : -3074457345618258602 to 3074457345618258602
 10.101.33.146 :  3074457345618258603 to -9223372036854775808
 10.101.33.196 : -9223372036854775807 to -3074457345618258603
                                         -4404190778401486753

This means that the partition with partition key Ramirez belongs to node 10.101.33.196 since the token for Ramirez (-4404190778401486753) is in the range owned by node 10.101.33.196.

When a coordinator gets a write request for a partition with last_name = 'Ramirez', the coordinator will forward the write to node 10.101.33.196. Similarly, when a coordinator gets a read request for the partition with last_name = 'Ramirez', the data will be retrieved from node 10.101.33.196.

To be clear, the partitioner doesn't assign tokens like what you stated in your question:

After that the token is used to assign ...

The token value from the partitioner hash function determines which node a partition is held. Cheers!

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.