2013-11-07

Evil Cassandra Unavailable Exception and a few Solutions

This is a nasty situation when learning cassandra: You have a cassandra cluster up, you try running your clients (server or command line) and nothing seems to work (example from cassandra-cli):

[default@blub] list user;
Using default limit of 100
Using default column limit of 100
null
UnavailableException()
   at org.apache.cassandra.thrift.Cassandra$get_range_slices_result.read(Cassa....

Basically the reason is that your query's consistency level cannot be satisfied by the cassandra cluster. Couple of fixes, depending on your situation:

  1. If your configured replication factor is 1 or your cluster has too few nodes: Use a lower consistency level. Test in cassandra-cli:
    [default@blub] consistencylevel as one;
    Consistency level is set to 'ONE'.

  2. If you started with a single node and recently added another, or you had to replace a node, or you changed the replication factor: Run repair on the node(s):
    apache-cassandra-1.2.5$ ./bin/nodetool -h localhost repair -l
    [2013-11-07 11:09:04,369] Starting repair command #1, repairing 1 ranges for keyspace blub
    [2013-11-07 11:09:04,376] Repair command #1 finished
    [2013-11-07 11:09:04,387] Nothing to repair for keyspace 'system'
    [2013-11-07 11:09:04,393] Starting repair command #2, repairing 1 ranges for keyspace system_auth
    [2013-11-07 11:09:04,394] Repair command #2 finished
    [2013-11-07 11:09:04,402] Nothing to repair for keyspace 'system_traces'

  3. If you run with
    org.apache.cassandra.locator.NetworkTopologyStrategy and multiple data centers: Careful with consistency level QUORUM: In my experience it requires quorums in all data centers! So if you have a data center with replication set to 1 you will always get UnavailableException:
    CREATE KEYSPACE vcodeks     with placement_strategy = 'org.apache.cassandra.locator.NetworkTopologyStrategy'
        strategy_options = {dc1:2, dc2:1};

    In this case it is better to use consistency level TWO. If you only care about one data center you might be happy with LOCAL_QUORUM if you configure all your client's DCs. But be aware that in the upper example LOCAL_QUORUM clients with dc set to dc1 won't be available if only one node in dc1 failed, even though you have a combined 3 replicas over all. 

2012-06-22

Moving to deverado.wordpress.com

Moving to deverado.wordpress.com because commenting was difficult.

I have third party cookies disabled, and I like it that way. Blogger doesn't work like that, just tested it. Here is the discussion that tipped me of.

I like discussions and disabling third party cookies -> move decision clear. Always wanted to try tumblr and Wordpress.
Tumblr: Out because requires people to have accounts to comment on posts
Wordpress: Powerful - but I'll miss the tree-archive widget!

2012-06-21

Chef's awesome - but bootstrapping can be a pain

Bootstrapping chef nodes in a bar bones virtual server environment took me some time to figure out. I had especially issues with the hostname not being recognized.

Problem is that in my bare-bones vservers the servers come without a useful hostname/domainname setting.

Finally now everything works. I did:



  1. Create the vserver(s)
  2. Set up the vserver's DNS entries
  3. Copy my ssh id to the server(s):
    scp ~/.ssh/id_dsa.pub root@1.1.1.1:/root/.ssh/authorized_keys
  4. Create my base role (check out the quickstart)
  5. Add the hostname and resolv recipes of johntdyer https://github.com/johntdyer/hostname-chef https://github.com/johntdyer/resolv-chef (they have to be in you local repo as cookbooks/resolve and .../hostname). Upload them and add them to the base role's run-list
  6. DNS should be ready now, so:
    knife bootstrap hostname.domain.de -E dev -N hostname.domain.de -r 'role[base]'
    Decide if you need the environment setting (-E) - I find it damn useful.
  7. NOW BEWARE, your nodes can now be found with
    knife search "name:*" BUT
    knife ssh "name:*" DOES NOT WORK. Maybe a bug: http://serverfault.com/questions/346418/knife-ssh-doesnt-find-my-nodes/346542#346542
    The nodename init needs a chef-client run to propagate. So do:
    knife ssh "name:**filter**" chef-client -E dev -a ipaddress -x root
    Here pay attention to the ipaddress part. I would love to know how I should have discovered that the thing that is referred to as IP in knife search and other places is called ipaddress here...
  8. Done. Check your nodes: knife search node "*:*"
    The names should be corrected now.

If anybody knows the siblings to ipaddress and where that is documented please let me know. There's a question, too: http://serverfault.com/questions/400836/what-are-the-values-for-attributes-in-knife-ssh-a-ipaddress-etc

2012-04-22

BSON objectid customization for sharding


Following the recommendations in http://www.mongodb.org/display/DOCS/Choosing+a+Shard+Key I implemented these two id generators that follow the ObjectId model. I hope some day they can get driver support so that saving them in binary format will be possible.
ShardableObjectId: Creates a nice distribution of keys over all buckets/shards for linear write/read scaling.
ShardableObjectIdWithMoPrefix: Creates keys prefixed with yyyymm so eg. 201203 so that inserts affect only part of the index.
Currently I propose just using them as string generators with the toString or toStringBase64URLSafe methods. The generated strings are safe for copy'n paste and work in most frameworks as entity ids that can be passed in the URL.
Needs:
  • BSON mongodb driver
  • apache commons codec
Limitations:
  • design has a log of repeated code everywhere (shardable* and BSON ObjectId very similar).
  • string generation not optimized. Too lazy to change apache commons codec now.
  • depends on commons codec
Those limitations are fine for me of course.

What do you think?

2012-04-10

Using dust.js in play framework 2.0

I'm really into trying frameworks and play 2.0 is a really nice package. Something's always missing, and for me and play 2.0 it's dust.js templates.

There's a half official typesafe dust sbt plugin, but

  1. I cannot make it download via ivy/mave/sbt magic
  2. I cannot compile it - how do I let it find play?
So had to make a shameless copy of the nice coffeescript plugin that comes with play 2.0. You can clone my dust sbt play plugin on github.

Just call 
  1. git clone git://github.com/georgkoester/Play20.git  
  2. cd Play20
  3. git checkout dust_play_sbt_plugin 
  4. cd framework
  5. ./build
  6. build-repository
  7. compile
  8. publish-local
and you got a version of play 2.0 with my patch. Of course you could just pull the patch too.

Happy playin!