Skip to content

Instantly share code, notes, and snippets.

@gjcourt
Created April 27, 2012 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gjcourt/2510509 to your computer and use it in GitHub Desktop.
Save gjcourt/2510509 to your computer and use it in GitHub Desktop.
Cassandra node rebalancing script
#!/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
@DavidAllison
Copy link

You could avoid using ssh here if you use nodetool's --host argument. What do you think of that approach @gjcourt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment