cassandra – Generating tokens

Generating tokens

If not using virtual nodes (vnodes), you must calculate tokens for your cluster.

About calculating tokens for single or multiple datacenters in Cassandra 1.2 and later 

  • Single datacenter deployments: Calculate tokens by dividing the hash range by the number of nodes in the cluster.
  • Multiple datacenter deployments: Calculate the tokens for each datacenter so that the hash range is evenly divided for the nodes in each datacenter.

 

Calculating tokens for the Murmur3Partitioner 

Use this method for generating tokens when you are not using virtual nodes (vnodes) and using the Murmur3Partitioner (default). This partitioner uses a maximum possible range of hash values from -263 to +263-1. To calculate tokens for this partitioner:

python -c 'print [str(((2**64 / number_of_tokens) * i) - 2**63) for i in range(number_of_tokens)]'

For example, to generate tokens for 6 nodes:

python -c 'print [str(((2**64 / 6) * i) - 2**63) for i in range(6)]'

The command displays the token for each node:

[ '-9223372036854775808', '-6148914691236517206', '-3074457345618258604', 
  '-2', '3074457345618258600', '6148914691236517202' ]