Skip to content

Instantly share code, notes, and snippets.

@danielmewes
Created February 21, 2014 00:20
Show Gist options
  • Select an option

  • Save danielmewes/9126318 to your computer and use it in GitHub Desktop.

Select an option

Save danielmewes/9126318 to your computer and use it in GitHub Desktop.

Revisions

  1. danielmewes created this gist Feb 21, 2014.
    22 changes: 22 additions & 0 deletions split-table.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/bin/bash

    # Splits a given table into n evenly-spaced shards.
    # call with ./split-table <tablename> <numshards>

    table=$1
    shards=$2
    cluster="localhost:29015"

    splits=`seq 0 $((16**4/$shards)) $((16**4+1)) \
    | tail -n +2 \
    | head -$((shards-1)) \
    | xargs printf " 'S%04x'"`

    echo "Splitting at these points: $splits"

    conf=`eval 'cat<<EOF
    split shard $table $splits
    '"$conf"'
    EOF'`

    echo $conf | rethinkdb admin -j $cluster