Skip to content

Instantly share code, notes, and snippets.

@arnobroekhof
Forked from kintarowins/rebalance.sh
Last active September 28, 2016 10:32
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 arnobroekhof/3ce994fec5684e928cad94770536f5c4 to your computer and use it in GitHub Desktop.
Save arnobroekhof/3ce994fec5684e928cad94770536f5c4 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