#!/bin/sh # This will allow you to rebalance the Cassandra ring # Accepts hosts from stdin and automatically rebalances # tokens in your ring. # # $ echo "one two three" | ./rebalance.sh RING_SIZE=$(echo "2^127" | bc) while read host do if [ -z $hosts ] then hosts=$host else hosts="$hosts $host" fi done HOST_NUM=$(echo $hosts | wc -w) INDEX=0 for host in $hosts do token=$(echo "$INDEX*$RING_SIZE/$HOST_NUM" | bc) ssh $host "/usr/bin/nodetool move $token" INDEX=$((INDEX+1)) done