Skip to content

Instantly share code, notes, and snippets.

@cdimartino
Created May 16, 2013 20:30
Show Gist options
  • Save cdimartino/5594847 to your computer and use it in GitHub Desktop.
Save cdimartino/5594847 to your computer and use it in GitHub Desktop.
#!/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)
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