Skip to content

Instantly share code, notes, and snippets.

@dev0x10
Forked from kintarowins/rebalance.sh
Last active August 29, 2015 14:25
Show Gist options
  • Save dev0x10/e67a71a16c4192aea242 to your computer and use it in GitHub Desktop.
Save dev0x10/e67a71a16c4192aea242 to your computer and use it in GitHub Desktop.
#!/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