You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Kant Kodali <ka...@peernova.com> on 2016/10/18 00:20:55 UTC

What is the point of counter type when we can do the same thing with int or bigint?

I just read the following link

https://docs.datastax.com/en/cql/3.3/cql/cql_using/useCounters.html


and I wonder what is the point of counter type when we can do the same
thing with int or bigint? what are benefits of using counter data type?

Re: What is the point of counter type when we can do the same thing with int or bigint?

Posted by Jeff Jirsa <je...@crowdstrike.com>.
The only way to do this in Cassandra now is with counters - whether you add 1 or n, it's counters or ugly read before write and lightweight transactions. Counters give Cassandra the closest thing they'll ever have to vector clocks - they give the user a way to do commutative deltas in a distributed system with all the hard work handled for you. 

In a world without counters, think about a situation like this - 

Imagine you have 6 nodes - 3 in each data center 

You insert a row with key=jeff into one DC (dc1)

The data centers are disconnected due to an ISP failure

You run "set value=value+1 where name='jeff'" in dc1

You run "set value=value+1 where name='jeff'" in dc2 - what happens?

What's the value when the data centers reconnect? 

Counters handle this for you - they aren't perfect, but they're better than most people would do independently at the application level. 

-- 
Jeff Jirsa


> On Oct 17, 2016, at 6:44 PM, Kant Kodali <ka...@peernova.com> wrote:
> 
> How about “Set the value 1 above what it is now" ? The same principle should apply right?
> 
> 
> 
> 
>> On Mon, Oct 17, 2016 at 6:21 PM, Jeff Jirsa <je...@crowdstrike.com> wrote:
>> You cant use int/bigint to say “Set the value 2 above what it is now”, unless you use a read to get the current value, then write using lightweight transactions, which have a significant performance penalty.
>> 
>>  
>> 
>> The primary reason for this is because no individual Cassandra node is guaranteed to know the current state of any cell at the time the write arrives – counters attempt to solve this
>> 
>>  
>> 
>>  
>> 
>>  
>> 
>>  
>> 
>> From: Kant Kodali <ka...@peernova.com>
>> Reply-To: "user@cassandra.apache.org" <us...@cassandra.apache.org>
>> Date: Monday, October 17, 2016 at 5:20 PM
>> To: "user@cassandra.apache.org" <us...@cassandra.apache.org>
>> Subject: What is the point of counter type when we can do the same thing with int or bigint?
>> 
>>  
>> 
>> I just read the following link 
>> 
>>  
>> 
>> https://docs.datastax.com/en/cql/3.3/cql/cql_using/useCounters.html
>> 
>>  
>> 
>>  
>> 
>> and I wonder what is the point of counter type when we can do the same thing with int or bigint? what are benefits of using counter data type?
>> 
>>  
>> 
>>  
>> 
>> ____________________________________________________________________
>> CONFIDENTIALITY NOTE: This e-mail and any attachments are confidential and may be legally privileged. If you are not the intended recipient, do not disclose, copy, distribute, or use this email or any attachments. If you have received this in error please let the sender know and then delete the email and all attachments.
> 

____________________________________________________________________
CONFIDENTIALITY NOTE: This e-mail and any attachments are confidential and may be legally privileged. If you are not the intended recipient, do not disclose, copy, distribute, or use this email or any attachments. If you have received this in error please let the sender know and then delete the email and all attachments.

Re: What is the point of counter type when we can do the same thing with int or bigint?

Posted by Kant Kodali <ka...@peernova.com>.
Also are you saying counters are atomic?

On Mon, Oct 17, 2016 at 6:43 PM, Kant Kodali <ka...@peernova.com> wrote:

> How about “Set the value 1 above what it is now" ? The same principle
> should apply right?
>
>
>
>
> On Mon, Oct 17, 2016 at 6:21 PM, Jeff Jirsa <je...@crowdstrike.com>
> wrote:
>
>> You cant use int/bigint to say “Set the value 2 above what it is now”,
>> unless you use a read to get the current value, then write using
>> lightweight transactions, which have a significant performance penalty.
>>
>>
>>
>> The primary reason for this is because no individual Cassandra node is
>> guaranteed to know the current state of any cell at the time the write
>> arrives – counters attempt to solve this
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *From: *Kant Kodali <ka...@peernova.com>
>> *Reply-To: *"user@cassandra.apache.org" <us...@cassandra.apache.org>
>> *Date: *Monday, October 17, 2016 at 5:20 PM
>> *To: *"user@cassandra.apache.org" <us...@cassandra.apache.org>
>> *Subject: *What is the point of counter type when we can do the same
>> thing with int or bigint?
>>
>>
>>
>> I just read the following link
>>
>>
>>
>> https://docs.datastax.com/en/cql/3.3/cql/cql_using/useCounters.html
>> <https://urldefense.proofpoint.com/v2/url?u=https-3A__docs.datastax.com_en_cql_3.3_cql_cql-5Fusing_useCounters.html&d=DQMFaQ&c=08AGY6txKsvMOP6lYkHQpPMRA1U6kqhAwGa8-0QCg3M&r=yfYEBHVkX6l0zImlOIBID0gmhluYPD5Jje-3CtaT3ow&m=iPfY1BzZydK_tAV9GSU9eibcSU0419tiNB_jGLI_HU0&s=MDcnGmdhGITER0oavba63eeQTprmLKX_aCo8NdvkrPQ&e=>
>>
>>
>>
>>
>>
>> and I wonder what is the point of counter type when we can do the same
>> thing with int or bigint? what are benefits of using counter data type?
>>
>>
>>
>>
>> ____________________________________________________________________
>> CONFIDENTIALITY NOTE: This e-mail and any attachments are confidential
>> and may be legally privileged. If you are not the intended recipient, do
>> not disclose, copy, distribute, or use this email or any attachments. If
>> you have received this in error please let the sender know and then delete
>> the email and all attachments.
>>
>
>

Re: What is the point of counter type when we can do the same thing with int or bigint?

Posted by Kant Kodali <ka...@peernova.com>.
How about “Set the value 1 above what it is now" ? The same principle
should apply right?




On Mon, Oct 17, 2016 at 6:21 PM, Jeff Jirsa <je...@crowdstrike.com>
wrote:

> You cant use int/bigint to say “Set the value 2 above what it is now”,
> unless you use a read to get the current value, then write using
> lightweight transactions, which have a significant performance penalty.
>
>
>
> The primary reason for this is because no individual Cassandra node is
> guaranteed to know the current state of any cell at the time the write
> arrives – counters attempt to solve this
>
>
>
>
>
>
>
>
>
> *From: *Kant Kodali <ka...@peernova.com>
> *Reply-To: *"user@cassandra.apache.org" <us...@cassandra.apache.org>
> *Date: *Monday, October 17, 2016 at 5:20 PM
> *To: *"user@cassandra.apache.org" <us...@cassandra.apache.org>
> *Subject: *What is the point of counter type when we can do the same
> thing with int or bigint?
>
>
>
> I just read the following link
>
>
>
> https://docs.datastax.com/en/cql/3.3/cql/cql_using/useCounters.html
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__docs.datastax.com_en_cql_3.3_cql_cql-5Fusing_useCounters.html&d=DQMFaQ&c=08AGY6txKsvMOP6lYkHQpPMRA1U6kqhAwGa8-0QCg3M&r=yfYEBHVkX6l0zImlOIBID0gmhluYPD5Jje-3CtaT3ow&m=iPfY1BzZydK_tAV9GSU9eibcSU0419tiNB_jGLI_HU0&s=MDcnGmdhGITER0oavba63eeQTprmLKX_aCo8NdvkrPQ&e=>
>
>
>
>
>
> and I wonder what is the point of counter type when we can do the same
> thing with int or bigint? what are benefits of using counter data type?
>
>
>
>
> ____________________________________________________________________
> CONFIDENTIALITY NOTE: This e-mail and any attachments are confidential and
> may be legally privileged. If you are not the intended recipient, do not
> disclose, copy, distribute, or use this email or any attachments. If you
> have received this in error please let the sender know and then delete the
> email and all attachments.
>

Re: What is the point of counter type when we can do the same thing with int or bigint?

Posted by Jeff Jirsa <je...@crowdstrike.com>.
You cant use int/bigint to say “Set the value 2 above what it is now”, unless you use a read to get the current value, then write using lightweight transactions, which have a significant performance penalty.

 

The primary reason for this is because no individual Cassandra node is guaranteed to know the current state of any cell at the time the write arrives – counters attempt to solve this

 

 

 

 

From: Kant Kodali <ka...@peernova.com>
Reply-To: "user@cassandra.apache.org" <us...@cassandra.apache.org>
Date: Monday, October 17, 2016 at 5:20 PM
To: "user@cassandra.apache.org" <us...@cassandra.apache.org>
Subject: What is the point of counter type when we can do the same thing with int or bigint?

 

I just read the following link 

 

https://docs.datastax.com/en/cql/3.3/cql/cql_using/useCounters.html

 

 

and I wonder what is the point of counter type when we can do the same thing with int or bigint? what are benefits of using counter data type?

 

 

____________________________________________________________________
CONFIDENTIALITY NOTE: This e-mail and any attachments are confidential and may be legally privileged. If you are not the intended recipient, do not disclose, copy, distribute, or use this email or any attachments. If you have received this in error please let the sender know and then delete the email and all attachments.