Skip to content

Instantly share code, notes, and snippets.

@kintarowins
Forked from gjcourt/rebalance.sh
Created August 22, 2012 23:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save kintarowins/3430444 to your computer and use it in GitHub Desktop.
Save kintarowins/3430444 to your computer and use it in GitHub Desktop.
Cassandra node rebalancing script
#!/bin/sh
#this looks up the nodes from the ring and rebalances them automatically
hosts = `/usr/bin/nodetool ring |grep Normal |awk '{print $1}' |xargs echo`
RING_SIZE=$(echo "2^127" | bc)
HOST_NUM=$(echo $hosts | wc -w)
INDEX=0
for host in $hosts
do
token=$(echo "$INDEX*$RING_SIZE/$HOST_NUM" | bc)
if [[ $token -ne 0 ]]; then
/usr/bin/nodetool -h $host move $token
fi
INDEX=$((INDEX+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment