You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Tamar Fraenkel <ta...@tok-media.com> on 2012/03/29 10:09:26 UTC
Counter question
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
Re: Counter question
Posted by Tamar Fraenkel <ta...@tok-media.com>.
Thanks! will do.
Tamar
*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
On Thu, Mar 29, 2012 at 12:11 PM, Shimi Kiviti <sh...@gmail.com> wrote:
> You set the consistency with every request.
> Usually a client library will let you set a default one for all write/read
> requests.
> I don't know if Hector lets you set a default consistency level per CF.
> Take a look at the Hector docs or ask it in the Hector mailing list.
>
> Shimi
>
>
> On Thu, Mar 29, 2012 at 11:47 AM, Tamar Fraenkel <ta...@tok-media.com>wrote:
>
>> Can this be set on a CF basis.
>> Only this CF needs higher consistency level.
>> Thanks,
>> Tamar
>>
>> *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
>>
>>
>>
>>
>>
>> On Thu, Mar 29, 2012 at 10:44 AM, Shimi Kiviti <sh...@gmail.com> wrote:
>>
>>> Like everything else in Cassandra, If you need full consistency you need
>>> to make sure that you have the right combination of (write consistency
>>> level) + (read consistency level)
>>>
>>> if
>>> W = write consistency level
>>> R = read consistency level
>>> N = replication factor
>>> then
>>> W + R > N
>>>
>>> Shimi
>>>
>>>
>>> On Thu, Mar 29, 2012 at 10:09 AM, Tamar Fraenkel <ta...@tok-media.com>wrote:
>>>
>>>> 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
>>>>
>>>>
>>>>
>>>>
>>>
>>
>
Re: Counter question
Posted by Shimi Kiviti <sh...@gmail.com>.
You set the consistency with every request.
Usually a client library will let you set a default one for all write/read
requests.
I don't know if Hector lets you set a default consistency level per CF.
Take a look at the Hector docs or ask it in the Hector mailing list.
Shimi
On Thu, Mar 29, 2012 at 11:47 AM, Tamar Fraenkel <ta...@tok-media.com>wrote:
> Can this be set on a CF basis.
> Only this CF needs higher consistency level.
> Thanks,
> Tamar
>
> *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
>
>
>
>
>
> On Thu, Mar 29, 2012 at 10:44 AM, Shimi Kiviti <sh...@gmail.com> wrote:
>
>> Like everything else in Cassandra, If you need full consistency you need
>> to make sure that you have the right combination of (write consistency
>> level) + (read consistency level)
>>
>> if
>> W = write consistency level
>> R = read consistency level
>> N = replication factor
>> then
>> W + R > N
>>
>> Shimi
>>
>>
>> On Thu, Mar 29, 2012 at 10:09 AM, Tamar Fraenkel <ta...@tok-media.com>wrote:
>>
>>> 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
>>>
>>>
>>>
>>>
>>
>
Re: Counter question
Posted by Paolo Bernardi <be...@gmail.com>.
On Thu, 2012-03-29 at 11:47 +0200, Tamar Fraenkel wrote:
> Can this be set on a CF basis.
> Only this CF needs higher consistency level.
The consistency level of read/write operations is specified at each
single read/write function call. This means that you have to use the
desired consistency level for each read/write operation involving your
CF.
Paolo
--
@bernarpa
http://paolobernardi.wordpress.com
Re: Counter question
Posted by Tamar Fraenkel <ta...@tok-media.com>.
Can this be set on a CF basis.
Only this CF needs higher consistency level.
Thanks,
Tamar
*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
On Thu, Mar 29, 2012 at 10:44 AM, Shimi Kiviti <sh...@gmail.com> wrote:
> Like everything else in Cassandra, If you need full consistency you need
> to make sure that you have the right combination of (write consistency
> level) + (read consistency level)
>
> if
> W = write consistency level
> R = read consistency level
> N = replication factor
> then
> W + R > N
>
> Shimi
>
>
> On Thu, Mar 29, 2012 at 10:09 AM, Tamar Fraenkel <ta...@tok-media.com>wrote:
>
>> 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
>>
>>
>>
>>
>
Re: Counter question
Posted by Shimi Kiviti <sh...@gmail.com>.
Like everything else in Cassandra, If you need full consistency you need to
make sure that you have the right combination of (write consistency level)
+ (read consistency level)
if
W = write consistency level
R = read consistency level
N = replication factor
then
W + R > N
Shimi
On Thu, Mar 29, 2012 at 10:09 AM, Tamar Fraenkel <ta...@tok-media.com>wrote:
> 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
>
>
>
>