Cassandra RandomPartitioner Tokenizing

Nov 2, 2010 / By Laine Campbell


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







Share this article

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>