Created
June 16, 2011 13:23
-
-
Save dehora/1029218 to your computer and use it in GitHub Desktop.
Cassandra token range generator in Groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
println("Cassandra Token Range Generator \n") | |
int nodes = -1 | |
if (args.length >= 1) { | |
nodes = new Integer(args[0]) | |
} | |
else { | |
gets = { | |
print it | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) | |
String input = br.readLine() | |
return input | |
} | |
nodes = new Integer(gets('How many nodes are in your cluster? :')) | |
} | |
println "Token Ranges:" | |
for (int i in 0..nodes-1) { | |
// token_range = (i*(2**127))/nodes, but no no no, we give you... | |
BigInteger token_range = new BigInteger(2).pow(127).divide(new BigInteger(nodes)).multiply(new BigInteger(i)) | |
println "node " + i + ": range: " + token_range | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment