2

I am trying to setup two node Cassandra Cluster on windows machine. I have basically two windows machine and I was following this datastax tutorial

Whenever I use the below command to get the token number from the above tutorial -

python -c "num=2; print ""\n"".join([(""token %d: %d"" %(i,(i*(2**127)/num))) for i in range(0,num)])"

I always get this error -

C:\Users\username>python -c "num=2; print ""\n"".join([(""token %d: %d"" %(i,(i*(2**127)/num))) for i
in range(0,num)])"
  File "<string>", line 1
    num=2; print "\n".join([("token %d: %d" %(i,(i*(2**127)/num))) for i in range(0,num)])
                    ^
SyntaxError: invalid syntax
arsenal
  • 23,366
  • 85
  • 225
  • 331

1 Answers1

1

You might have better luck putting that command into an actual Python script. Here is a similar Python script that I use (saved as newCluster.py):

import sys

if (len(sys.argv) > 1):
        num=int(sys.argv[1])
else:
        num=int(raw_input("How many nodes are in your cluster? "))
for i in range(0, num):
        print 'node %d: %d' % (i, (i*(2**127)/num))

When I run that for two nodes, I get:

How many nodes are in your cluster? 2
node 0: 0
node 1: 85070591730234615865843651857942052864

Here is exactly how I edit and run it:

enter image description here

Which version of Python are you using? I have tested this script in 2.6.7 and 2.7.3.

Also to be balanced, your initial_token values for a two node cluster simply need to have a difference of 85,070,591,730,234,615,865,843,651,857,942,052,864. They don't necessarily have to be 0 and 85070591730234615865843651857942052864; although those two values should work just fine.

Aaron
  • 55,518
  • 11
  • 116
  • 132
  • I copied the above content in a notepad file and save it as newcluster.py.. When I am running from the cmd prompt like this `C:\Users\uname\Desktop>newcluster.py`. I always get this error `File "newcluster.py", line 8 print 'node %d: %d' % (i, (i*(2**127)/num)) ^ SyntaxError: invalid syntax` – arsenal Nov 01 '13 at 07:37
  • I am running `C:\Python33>python Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.` – arsenal Nov 01 '13 at 08:03
  • remove the extra space between % and ( on the last line. That should be more like `print 'node %d: %d' %(i, (i*(2**127)/num))` – Sven Delmas Nov 05 '13 at 00:36