cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tamar Fraenkel <ta...@tok-media.com>
Subject Counter question
Date Thu, 29 Mar 2012 08:09:26 GMT
Hi!
Asking again, as I didn't get responses :)

I have a ring with 3 nodes and replication factor of 2.
I have counter cf with the following definition:

CREATE COLUMN FAMILY tk_counters
    with comparator = 'UTF8Type'
    and default_validation_class = 'CounterColumnType'
    and key_validation_class = 'CompositeType(UTF8Type,UUIDType)'
    and replicate_on_write = true;

In my code (Java, Hector), I increment a counter and then read it.
Is it possible that the value read will be the value before increment?
If yes, how can I ensure it does not happen. All my reads and writes are
done with consistency level one.
If this is consistency issue, can I do only the actions on tk_counters
column family with a higher consistency level?
What does replicate_on_write mean? I thought this should help, but maybe
even if replicating after write, my read happen before replication finished
and it returns value from a still not updated node.

My increment code is:
    Mutator<Composite> mutator =
            HFactory.createMutator(keyspace,
                    CompositeSerializer.get());
    mutator.incrementCounter(key,"tk_counters", columnName, inc);
    mutator.execute();

My read counter code is:
    CounterQuery<Composite,String> query =
            createCounterColumnQuery(keyspace,
                    CompositeSerializer.get(), StringSerializer.get());
    query.setColumnFamily("tk_counters");
    query.setKey(key);
    query.setName(columnName);
    QueryResult<HCounterColumn<String>> r = query.execute();
    return r.get().getValue();

Thanks,
*Tamar Fraenkel *
Senior Software Engineer, TOK Media

[image: Inline image 1]

tamar@tok-media.com
Tel:   +972 2 6409736
Mob:  +972 54 8356490
Fax:   +972 2 5612956

Mime
View raw message