Skip to content

Instantly share code, notes, and snippets.

@dev0x10
Forked from gjcourt/rebalance.sh
Last active August 29, 2015 14:25
Show Gist options
  • Save dev0x10/44aae54ad96cd63b6754 to your computer and use it in GitHub Desktop.
Save dev0x10/44aae54ad96cd63b6754 to your computer and use it in GitHub Desktop.

Revisions

  1. @gjcourt gjcourt created this gist Apr 27, 2012.
    29 changes: 29 additions & 0 deletions rebalance.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/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