Skip to content

Instantly share code, notes, and snippets.

@cdimartino
Created May 16, 2013 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdimartino/5594819 to your computer and use it in GitHub Desktop.
Save cdimartino/5594819 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"
nodetool -v -h $host move $token
INDEX=$((INDEX+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment