카싼드라의 ring에서 담당하는 데이타 range 는 광장히 중요하다. range를 결정해주는 token 에 관한 range 재계산 이동 스크립트이다
#! /usr/bin/python
import sys
if len(sys.argv) != 3:
   print "usage: move_tokens.py <current_size> <new_size>"
   sys.exit(1)
CURRENT_NODES = int(sys.argv[1])
GOING_TO_NODES = int(sys.argv[2])
RING_SIZE = 2**127
def tokens(n):
  rv = []
  for x in xrange(n):
    rv.append(RING_SIZE / n * x)
  return rv
def print_layout(nodes):
  i = 0
  for n in nodes:
    i += 1
    print "%d:\t%d" % (i, n)
current = tokens(CURRENT_NODES)
go = tokens(GOING_TO_NODES)
print "Existing Tokens: "
print_layout(current)
print ""
print ""
print "New Tokens: "
print_layout(go)
print ""
print ""
i = 0
j = 0
pending = []
while j != len(go) and i != len(current):
  cur = current[i]
  next = go[j]
  if next == cur:
    if pending:
      for x in pending:
         print x
      pending = []
    print "[%d] Old Node %d stays at %d" % (j+1, i+1, cur)
    i += 1
  if next > cur:
    if pending:
      for x in pending:
        print x
    pending = []
  #diff = (next - cur)
  print "[%d] Old Node %d moves to %d" % (j+1, i+1, next)
  i += 1
 if next < cur:
   pending.insert(0, "[%d] New Node added at %d" % (j+1, next))
 j += 1
 if pending:
   for x in pending:
     print x
 pending = []
while j != len(go):
  print "[%d] Add new node %d at %d" % (j+1, j+1, go[j])
  j += 1