Cassandra RandomPartitioner Tokenizing

Posted in: Cassandra, Technical Track

So I’m creating a new cluster, and after setting up I needed to get my tokens.  As we’re told in

Token selection:

Using a strong hash function means RandomPartitioner keys will, on average, be evenly spread across the Token space, but you can still have imbalances if your Tokens do not divide up the range evenly, so you should specify InitialToken to your first nodes as i * (2**127 / N) for i = 0 .. N-1. In Cassandra 0.7, you should specify initial_token in cassandra.yaml.

Here’s a nice simple code snippet to figure out your RandomPartitioner tokens based on the size of your cluster:

#! /usr/bin/python

#nodes = int(raw_input( “How many nodes?” ))

import sys


def tokens(nodes):

    for i in range(1, nodes + 1):

        print (i * (2 ** 127 – 1) / nodes)

This should give something like this:

[root@cassandra06 conf]# ./ 6







Interested in working with Laine? Schedule a tech call.

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *