Created
April 27, 2012 16:15
-
-
Save gjcourt/2510509 to your computer and use it in GitHub Desktop.
Cassandra node rebalancing script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could avoid using ssh here if you use
nodetool
's--host
argument. What do you think of that approach @gjcourt?