Skip to content

Instantly share code, notes, and snippets.

@cdimartino
Created May 16, 2013 20:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdimartino/5594857 to your computer and use it in GitHub Desktop.
Save cdimartino/5594857 to your computer and use it in GitHub Desktop.
Quick and dirty rebalancing of Cassandra cluster.
#!/bin/sh
# This will allow you to rebalance the Cassandra ring
#
# $ ./rebalance.sh file_of_hosts
RING_SIZE=$(echo "2^127" | bc)
HOSTS=$(cat $1 | sed 'N;s/\n/ /')
HOST_NUM=$(echo $HOSTS | wc -w)
INDEX=0
for host in $HOSTS
do
token=$(echo "$INDEX*$RING_SIZE/$HOST_NUM" | bc)
echo "Moving $host to $token"
ssh $host "sudo nodetool -v -h localhost move $token"
INDEX=$((INDEX+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment