This project is read-only.

Counter not working

Oct 9, 2011 at 7:18 AM

Hi everyone,

I created a Counter column for my application using this command on cassandra-cli:

create column family Counters with default_validation_class=CounterColumnType and replicate_on_write=true;

Ok, everything fine until here. Them by using cassandra-cli I incremented the value using this command:

incr Counters['QVE'][123456] by 1;

Ok again. If I use the list command I can see:

RowKey: ffef6c7562 => (counter=123456, value=1)

Them I came to application and wrote this code to get the value:

var entitys = from x in context.ColumnList where x.Key == "QVE" && x.ColumnFamily == "Counters" select x;

but I´m always get the same 0 value.

Can anyone help me on that?

Oct 9, 2011 at 9:00 AM

We don't release Cassandraemon0.8 yet. Please use latest version of trunk.

We just implemented Counter at Oct 2.

Oct 9, 2011 at 5:18 PM

Hi Sabro,

I´m using the lastest version of trunk and even looking into context.ColumnList and context.SuperColumnList my returned value is always 0.

Do you have any idea?

Oct 9, 2011 at 5:48 PM

Please try context.CounterColumnList. If you do this, you can get List<CassandraEntity<List<CounterColumn>>>.

Oct 9, 2011 at 7:24 PM
Edited Oct 9, 2011 at 7:26 PM


I did this client command at client: 

incr Counters['QVEF6C7562'][123456] by 1;

And running a list command, I can see that the data is there:


[default@Tracking] list Counters;

Using default limit of 100


RowKey: ffef6c7562=> (counter=123456, value=1)


And to retreive the data, even using CounterColumnList it´s not working:


var entitys = from x in context.CounterColumnList where x.Key == "QVEF6C7562" && x.ColumnFamily == "Counters" select x;

var count = entitys.CountColumn();


Can you give me more tips? I promisse I´ll send the feedbacks later :)


Thanks in advance,

Oct 9, 2011 at 7:39 PM

Let's try updating column family. Execute next command on cassandra-cli prompt.

update column family Counters with comparator = 'UTF8Type';

Oct 9, 2011 at 7:46 PM

Sorry, above comment is mistake. I overlook QVEF6C7562 is key.

It is over my head.

Oct 9, 2011 at 7:48 PM

I did, and here is the schema:


create column family Counters
  with column_type = 'Standard'
  and comparator = 'UTF8Type'
  and default_validation_class = 'CounterColumnType'
  and key_validation_class = 'BytesType'
  and memtable_operations = 0.2953125
  and memtable_throughput = 63
  and memtable_flush_after = 1440
  and rows_cached = 0.0
  and row_cache_save_period = 0
  and keys_cached = 200000.0
  and key_cache_save_period = 14400
  and read_repair_chance = 1.0
  and gc_grace = 864000
  and min_compaction_threshold = 4
  and max_compaction_threshold = 32
  and replicate_on_write = true
  and row_cache_provider = 'ConcurrentLinkedHashCacheProvider';

And even using following code lines, I still got only 0 as return:
var entitys = from x in context.CounterColumnList where x.Key == "QVEF6C7562" &&  x.ColumnFamily == "Counters" select x;
var count = entitys.CountColumn();

var entitys2 = from x in context.CounterColumnList where x.Key == 123456 && x.ColumnFamily == "Counters" select x;
var count2 = entitys2.CountColumn();

Any other suggestion?



Oct 9, 2011 at 8:02 PM

So finally it´s worked. I can´t understand why I couldn´t read the data inserted by cassandra-cli but following the new 0.8 cassandraemon documentation ( and using the following code to insert and them read. It worked:


var cc1 = new CounterColumn().SetNameValue("1234", 1);
context.InsertOnSubmit("Counters", "QVEF6C7562".ToCassandraByte(), cc1);

var query = from x in context.CounterColumnList
            where x.ColumnFamily == "Counters" && x.Key == "QVEF6C7562" 
            select x.ToFlatDictionary<string, long>();

var counters = query.First().ToList();
foreach (var kvp in counters)
     var abc = kvp.Key + " = " + kvp.Value;

I beleive there is something wrong from read a data that was inserted directly by cassandra-cli.

Thanks for your great help sabro.