question

satvantsingh_190085 avatar image
satvantsingh_190085 asked Erick Ramirez edited

How does token range work in single-node clusters without vnodes?

How token range work in single node cluster , as per below example my node has token "704134931341156592" so how this single token work as a range. if it work as range so what will be it range could you please explain ?



cassandratoken
1591244172342.png (7.5 KiB)
1591244406749.png (9.0 KiB)
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 Erick Ramirez edited

In a single-node cluster, the node owns the whole token range. It doesn't really matter what token is assigned to it. Since it's the only node in the cluster, it has all the data.

Instead, let me illustrate with an example 3-node cluster.

Token assignments

I've calculated balanced tokens for 3 nodes like this:

 $ _node_count=3; python -c "print [str(((2**64 / $_node_count) * i) - 2**63) for i in range($_node_count)]"
 ['-9223372036854775808', '-3074457345618258603', '3074457345618258602']

I've assigned the tokens to each of the nodes in cassandra.yaml:

 10.101.33.146 - initial_token: -9223372036854775808
 10.101.33.196 - initial_token: -3074457345618258603
  10.101.36.82 - initial_token: 3074457345618258602

Ring

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

And here's a visual representation of where the nodes are placed around the ring based on their token assignment:

905-ring-3-nodes.png

Range owned

Based on the assigned tokens, here are the token ranges 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

To show you what those ranges mean, I've created this table where name is the partition key:

 CREATE TABLE community.users (
     name text PRIMARY KEY,
     address text
 )

In this table, I have 3 users -- Tom, Dick and Harry. Below are the token values for each partition key:

 cqlsh:community> SELECT name, TOKEN(name) FROM users ;
    
  name  | system.token(name)
 -------+----------------------
    tom | -5186961623470975143
  harry | -4632103420999695370
   dick |  1627195465470592336

For tom, token -5186961623470975143 lies between the range owned by node 10.101.33.196. The token for harry also lies between the range owned by node 10.101.33.196. Finally, the token for dick is in the range owned by node 10.101.36.82.

To confirm this, here are the outputs of the nodetool getendpoints:

 $ nodetool getendpoints community users tom
 10.101.33.196

 $ nodetool getendpoints community users harry
 10.101.33.196

 $ nodetool getendpoints community users dick
 10.101.36.82

Hopefully this all makes sense now. Cheers!


ring-3-nodes.png (98.9 KiB)
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.