You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Vlad Paiu <vl...@opensips.org> on 2011/11/04 12:29:10 UTC

Cassandra Counters and TTL

Hello,

I'm a new user of Cassandra and I think it's great.
Still, while developing my APP using Cassandra, I got stuck with some 
things and I'm not really sure that Cassandra can handle them at the 
moment.

So, first of all, does Cassandra allow for Counters and regular Keys to 
be located in the same ColumnFamily ?

Secondly, is there any way to dynamically set the TTL for a key ? In the 
sense that I have a key, I initially set it with no TTL, but after a 
while I decide that it should expire in 100 seconds. Can Cassandra do 
this ?

3. Can counters have a TTL ?

4. Is there any way to atomically reset a counter ? I read on the 
website that the only way to do it is read the variable value, and then 
set it to -value, which seems rather bogus to me.

Regards,

-- 
Vlad Paiu
OpenSIPS Developer


Re: Cassandra Counters and TTL

Posted by Sylvain Lebresne <sy...@datastax.com>.
On Mon, Nov 7, 2011 at 10:12 AM, Vlad Paiu <vl...@opensips.org> wrote:
> Hello,
>
> Thanks for your answer. See my reply in-line.
>
> On 11/04/2011 01:46 PM, Amit Chavan wrote:
>
> Answers inline.
>
> On Fri, Nov 4, 2011 at 4:59 PM, Vlad Paiu <vl...@opensips.org> wrote:
>>
>> Hello,
>>
>> I'm a new user of Cassandra and I think it's great.
>> Still, while developing my APP using Cassandra, I got stuck with some
>> things and I'm not really sure that Cassandra can handle them at the moment.
>>
>> So, first of all, does Cassandra allow for Counters and regular Keys to be
>> located in the same ColumnFamily ?
>
> What do you mean when you say "regular Keys"? If you are hinting at columns
> apart from counters, then the answer is *no*: only counters can exist in a
> CounterColumnFamily and other column families cannot hold counters.
>
>
> Yes, this is what I was asking. Thanks for the answer.
>>
>> Secondly, is there any way to dynamically set the TTL for a key ? In the
>> sense that I have a key, I initially set it with no TTL, but after a while I
>> decide that it should expire in 100 seconds. Can Cassandra do this ?
>
> TTL is not for one key, it is for one column.
>
> When I was saying 'Key' I actually meant to say column. Seems I'm not yet
> very acquainted with Cassandra terminology. So in the end, can you
> dynamically alter the TTL of a Column ?

You'll have to update the column with the new TTL. Which does involve
that you know the column value and so may require reading the column
first.

>
>
>>
>> 3. Can counters have a TTL ?
>
> No. Currently, counters do not (or if I am correct - cannot) have TTL.
>
> Ok. Any info if this will be implemented anytime soon ?

The current status is not anytime soon because we don't have a good solution
for it so far. See https://issues.apache.org/jira/browse/CASSANDRA-2103 for
more details.

>
>> 4. Is there any way to atomically reset a counter ? I read on the website
>> that the only way to do it is read the variable value, and then set it to
>> -value, which seems rather bogus to me.
>
> I think that is the only way to reset a counter. I would like to know if
> there is another way.
>
> Ok then, waiting for someone to confirm. It's bad that you cannot atomically
> reset a counter value, as a two-way resetting might lead to undetermined
> behaviour.

There is no other way. Which does mean that you need some external way
to make sure that not two client will attempt resetting the same counter at
the same time. Or model so that you don't need counter resets (I'm not
saying this is always possible, but there is probably a number of cases
where resetting a counter could be replaced by switching to a brand new
counter).

> Also, can I set the counter to a specific value, without keeping state on
> the client ? For example, if the client does not know the current counter
> value is 3. Can it set the counter value to 10, without first getting the
> counter value, and then incrementing by 7 ?

No.

--
Sylvain

>
> Background: I am using Cassandra since the past two months. Hope the
> community corrects me if I am wrong.
>
>>
>> Regards,
>>
>> --
>> Vlad Paiu
>> OpenSIPS Developer
>>
>
>
>
> --
> Regards
> Amit S. Chavan
>
>
>
>
> Regards,
>
> Vlad Paiu
> OpenSIPS Developer
>

Re: Cassandra Counters and TTL

Posted by Vlad Paiu <vl...@opensips.org>.
Hello,

Thanks for your answer. See my reply in-line.

On 11/04/2011 01:46 PM, Amit Chavan wrote:
>
> Answers inline.
>
> On Fri, Nov 4, 2011 at 4:59 PM, Vlad Paiu <vladpaiu@opensips.org 
> <ma...@opensips.org>> wrote:
>
>     Hello,
>
>     I'm a new user of Cassandra and I think it's great.
>     Still, while developing my APP using Cassandra, I got stuck with
>     some things and I'm not really sure that Cassandra can handle them
>     at the moment.
>
>     So, first of all, does Cassandra allow for Counters and regular
>     Keys to be located in the same ColumnFamily ?
>
> What do you mean when you say "regular Keys"? If you are hinting at 
> columns apart from counters, then the answer is *no*: only counters 
> can exist in a CounterColumnFamily and other column families cannot 
> hold counters.
Yes, this is what I was asking. Thanks for the answer.
>
>
>     Secondly, is there any way to dynamically set the TTL for a key ?
>     In the sense that I have a key, I initially set it with no TTL,
>     but after a while I decide that it should expire in 100 seconds.
>     Can Cassandra do this ?
>
> TTL is not for one key, it is for one column.

When I was saying 'Key' I actually meant to say column. Seems I'm not 
yet very acquainted with Cassandra terminology. So in the end, can you 
dynamically alter the TTL of a Column ?

>
>     3. Can counters have a TTL ?
>
> No. Currently, counters do not (or if I am correct - cannot) have TTL.
>
>
Ok. Any info if this will be implemented anytime soon ?

>     4. Is there any way to atomically reset a counter ? I read on the
>     website that the only way to do it is read the variable value, and
>     then set it to -value, which seems rather bogus to me.
>
> I think that is the only way to reset a counter. I would like to know 
> if there is another way.
>
Ok then, waiting for someone to confirm. It's bad that you cannot 
atomically reset a counter value, as a two-way resetting might lead to 
undetermined behaviour.

Also, can I set the counter to a specific value, without keeping state 
on the client ? For example, if the client does not know the current 
counter value is 3. Can it set the counter value to 10, without first 
getting the counter value, and then incrementing by 7 ?

> Background: I am using Cassandra since the past two months. Hope the 
> community corrects me if I am wrong.
>
>
>     Regards,
>
>     -- 
>     Vlad Paiu
>     OpenSIPS Developer
>
>
>
>
> -- 
> Regards
> Amit S. Chavan
>
>
>

Regards,

Vlad Paiu
OpenSIPS Developer



Re: Cassandra Counters and TTL

Posted by Amit Chavan <ca...@gmail.com>.
Answers inline.

On Fri, Nov 4, 2011 at 4:59 PM, Vlad Paiu <vl...@opensips.org> wrote:

> Hello,
>
> I'm a new user of Cassandra and I think it's great.
> Still, while developing my APP using Cassandra, I got stuck with some
> things and I'm not really sure that Cassandra can handle them at the moment.
>
> So, first of all, does Cassandra allow for Counters and regular Keys to be
> located in the same ColumnFamily ?
>
What do you mean when you say "regular Keys"? If you are hinting at columns
apart from counters, then the answer is *no*: only counters can exist in a
CounterColumnFamily and other column families cannot hold counters.


>
> Secondly, is there any way to dynamically set the TTL for a key ? In the
> sense that I have a key, I initially set it with no TTL, but after a while
> I decide that it should expire in 100 seconds. Can Cassandra do this ?
>
TTL is not for one key, it is for one column.


>
> 3. Can counters have a TTL ?
>
No. Currently, counters do not (or if I am correct - cannot) have TTL.

>
> 4. Is there any way to atomically reset a counter ? I read on the website
> that the only way to do it is read the variable value, and then set it to
> -value, which seems rather bogus to me.
>
I think that is the only way to reset a counter. I would like to know if
there is another way.

Background: I am using Cassandra since the past two months. Hope the
community corrects me if I am wrong.


>
> Regards,
>
> --
> Vlad Paiu
> OpenSIPS Developer
>
>


-- 
Regards
Amit S. Chavan