cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tamar Fraenkel <ta...@tok-media.com>
Subject another counter question
Date Wed, 28 Mar 2012 09:00:37 GMT
Hi!
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.

   1. Is it possible that the value read will be the value before increment?
   2. If yes, how can I ensure it does not happen. All my reads and writes
   are done with consistency level one.
   3. If this is consistency issue, can I do only the actions on
   tk_counters column family with a higher consistency level?
   4. 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