Skip to content

Cassandra Development Environment in Mac OS Snow Leopard

July 2, 2010

I just started working with Cassandra so I am no expert on the subject, and this post is more about self documentation of what I did to get it working on my laptop, running Snow Leopard, than an expert’s How to guide. If it helps you out all the better, and leave your comments.

Getting Cassandra to run on Mac OSX is very easy just download the latest binary from http://cassandra.apache.org/. At the time of this writing the version was 0.6.3, but I updated the important parts to 0.7rc3 so it should work with that version as well.

Create the directories Cassandra needs to work:


sudo mkdir -p /opt/cassandra
sudo chown -R `whoami` /opt/cassandra
sudo mkdir -p /var/log/cassandra
sudo chown -R `whoami` /var/log/cassandra
sudo touch /var/log/cassandra/system.log
sudo mkdir -p /var/lib/cassandra
sudo chown -R `whoami` /var/lib/cassandra

Get Cassandra and copy it to /opt/cassandra. In this example I used wget. Notice that the version numbers may change so use the correct link for your version from http://cassandra.apache.org/download/


wget http://apache.opensourceresources.org/cassandra/0.6.3/apache-cassandra-0.6.3-bin.tar.gz
tar xzf apache-cassandra-0.6.3-bin.tar.gz
cd apache-cassandra-0.6.3/bin
./cassandra -f

If all is ok you should now see


INFO 22:01:15,273 Auto DiskAccessMode determined to be mmap
INFO 22:01:15,887 Saved Token not found. Using 114412163776176127313248360017471199843
INFO 22:01:15,888 Saved ClusterName not found. Using Test Cluster
INFO 22:01:15,898 Creating new commitlog segment /var/lib/cassandra/commitlog/CommitLog-1278036075898.log
INFO 22:01:15,937 LocationInfo has reached its threshold; switching in a fresh Memtable at CommitLogContext(file='/var/lib/cassandra/commitlog/CommitLog-1278036075898.log', position=419)
INFO 22:01:15,946 Enqueuing flush of Memtable-LocationInfo@1373164447(169 bytes, 4 operations)
INFO 22:01:15,954 Writing Memtable-LocationInfo@1373164447(169 bytes, 4 operations)
INFO 22:01:16,262 Completed flushing /var/lib/cassandra/data/system/LocationInfo-1-Data.db
INFO 22:01:16,295 Starting up server gossip
INFO 22:01:16,406 Binding thrift service to localhost/127.0.0.1:9160
INFO 22:01:16,414 Cassandra starting up...

Now lets test Cassandra. Open a new Terminal window, or tab, and:


cd /opt/cassandra/bin
./cassandra-cli --host localhost --port 9160

Cassandra 0.7rc3 output and testing is a bit different so check with the comments bellow.

At the prompt (for 0.6.x)


cassandra> set Keyspace1.Standard2['jsmith']['first'] = 'John'
Value inserted.
cassandra> set Keyspace1.Standard2['jsmith']['last'] = 'Smith'
Value inserted.
cassandra> set Keyspace1.Standard2['jsmith']['age'] = '42'
Value inserted.
cassandra> get Keyspace1.Standard2['jsmith']
(column=age, value=42; timestamp=1249930062801)
(column=first, value=John; timestamp=1249930053103)
(column=last, value=Smith; timestamp=1249930058345)
Returned 3 rows.
cassandra> quit

If you’re able to get the values out of Keyspace1 all is good and Cassandra is up and running.
If you are installing 0.7 or higher the test Keyspace1 is not loaded automatically and you need to run jconsole to load the “schema”. And go to MBeans -> org.apache.cassandra.service -> StorageService -> Operations -> loadSchemaFromYAML as documented on LiveSchemaUpdates

Please note that jconsole needs to connect to localhost on port 8080, to talk to Cassandra. Do not use the Thrift port 9160.

Now lets install Chiton, a GTK GUI written in Python that will allow us to view the data stored in Cassandra.


mkdir chiton-temp
cd chiton-temp
git clone git://github.com/driftx/chiton.git
export VERSIONER_PYTHON_PREFER_32_BIT=yes

In order to fulfill a Chiton dependecies we also need

  • Twisted 8.1.0 or later
  • Thrift (latest svn)
  • PyGTK 2.14 or later
  • simplejson
  • Telephus

First download and install Apple’s Xcode if you don’t have it already then, get a PyGTK Mac OS build ¬†from http://www.daimi.au.dk/%7Emadsk/files/

Copy PyGTK to /Develper as instructed in the README.txt of the PyGTK package.

Now for each of the packages, except Thrift run


cd
sudo python setup.py install

If you want to use Python 2.6 run

sudo python2.6 setup.py install

Compiling thrift. Go to the directory to which you checked out Thrift from the SVN
Because of the time it may take to compile all the updates, you may skip the
port selfupdate and port upgrade outdated. But if you start getting compilation errors you MUST do them and wait :(
My iMac took 5 hours!!!


cd
sudo port selfupdate
sudo port upgrade outdated
sudo port install boost pkgconfig libevent
cp /opt/local/share/aclocal/pkg.m4 ./aclocal
aclocal --acdir=./aclocal
./bootstrap.sh
./configure --with-boost=/opt/local --with-libevent=/opt/local --prefix=/opt/local
sudo make install
cd /opt/cassandra/apache-cassandra-0.6.3/interface/
thrift --gen py:new_style cassandra.thrift
cp -a ./gen-py/cassandra ~/chiton-temp/

(thank you Rich for the configure details

Almost done!!!
All we need to do is add the PYTHONPATH to our ~/.profile. Using your favorite editor open ~/.profile and add:


export PYTHONPATH=/usr/lib/python2.6/site-packages/:/Developer/MacPyGTK/inst/lib/python2.6/site-packages:/usr/lib/python2.6/site-packages/thrift:/Library/Python/2.6/site-packages/telephus:~/chiton-temp/chiton
export JAVA_HOME=$(/usr/libexec/java_home)
export VERSIONER_PYTHON_PREFER_32_BIT=yes

The directories in your PYTHONPATH may be a bit different, but the idea is to add all the directories where all the packages we just installed are located. If you miss one you will get import errors when running chiton-client.

Reconfigure Cassandra to allow the Thrift connections from Chiton, you need to set ThriftFramedTransport to true in cassandra’s storage-conf.xml. In my system


vi /opt/cassandra/apache-cassandra-0.6.3/conf/storage-conf.xml
<
ThriftFramedTransport>true</ThriftFramedTransport>

Done!!!!

If all is well you should now be able to run chiton-client. Login to localhost on port 9160. Don’t forget to have Cassandra daemon running (cassandra -f).

Since we changed the Thrift access to framed, from now on if you want to use the cassandra-cli don’t forget the –framed command line option. Cassandra 0.6.3 daemon crashes with:


ERROR 23:50:24,264 Uncaught exception in thread Thread[pool-1-thread-5,5,main]
java.lang.OutOfMemoryError: Java heap space

if you don’t use –framed.

Hope this guide helps you get your development machine ready to work with Cassandra.

About these ads
5 Comments
  1. This breakdown is fantastic. I’ve followed it all the way through to:

    $ aclocal -acdir=./aclocal

    where I get the following error:
    aclocal: unrecognized option `-acdir=./aclocal’

    Your help is greatly appreciated! I want to take Cassandra for a spin and your notes have been the most useful I’ve found. Thanks!

    • I think WordPress is “eating” the dashes… use

      aclocal --acdir=./aclocal

      notice the 2 dashes

  2. Great explanation!

  3. Updated and verified with Cassandra 0.7rc3.

    when testing your 0.7rc3 install you should run


    cd /opt/cassandra/bin
    ./cassandra-cli --host localhost --port 9160

    [default@unknown] show keyspaces;
    Keyspace: system:
    Replication Strategy: org.apache.cassandra.locator.LocalStrategy
    Replication Factor: 1
    Column Families:
    ColumnFamily: HintsColumnFamily (Super)
    "hinted handoff data"
    Columns sorted by: org.apache.cassandra.db.marshal.BytesType/org.apache.cassandra.db.marshal.BytesType
    Row cache size / save period: 0.0/0
    Key cache size / save period: 0.01/3600
    Memtable thresholds: 0.2953125/63/60
    GC grace seconds: 0
    Compaction min/max thresholds: 4/32
    Read repair chance: 0.0
    ColumnFamily: IndexInfo
    "indexes that have been completed"
    Columns sorted by: org.apache.cassandra.db.marshal.UTF8Type
    Row cache size / save period: 0.0/0
    Key cache size / save period: 0.01/3600
    Memtable thresholds: 0.2953125/63/60
    GC grace seconds: 0
    Compaction min/max thresholds: 4/32
    Read repair chance: 0.0
    ColumnFamily: LocationInfo
    "persistent metadata for the local node"
    Columns sorted by: org.apache.cassandra.db.marshal.BytesType
    Row cache size / save period: 0.0/0
    Key cache size / save period: 0.01/3600
    Memtable thresholds: 0.2953125/63/60
    GC grace seconds: 0
    Compaction min/max thresholds: 4/32
    Read repair chance: 0.0
    ColumnFamily: Migrations
    "individual schema mutations"
    Columns sorted by: org.apache.cassandra.db.marshal.TimeUUIDType
    Row cache size / save period: 0.0/0
    Key cache size / save period: 0.01/3600
    Memtable thresholds: 0.2953125/63/60
    GC grace seconds: 0
    Compaction min/max thresholds: 4/32
    Read repair chance: 0.0
    ColumnFamily: Schema
    "current state of the schema"
    Columns sorted by: org.apache.cassandra.db.marshal.UTF8Type
    Row cache size / save period: 0.0/0
    Key cache size / save period: 0.01/3600
    Memtable thresholds: 0.2953125/63/60
    GC grace seconds: 0
    Compaction min/max thresholds: 4/32
    Read repair chance: 0.0
    [default@unknown]

    There Cassandra 0.7rc3 is up and running on your Mac! Easy

  4. sanados permalink

    sudo touch /var/log/cassandra/system.log

    should be issued before you chown on /var/log/cassandra or just use touch /var/log/cassandra/system.log without sudo.

    Nothing serious but causes permission problems as the system.log will be created as root with sudo and therefore missing write writes afterwards.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: