[ 
https://issues.apache.org/jira/browse/CASSANDRA-11592?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Sylvain Lebresne resolved CASSANDRA-11592.
------------------------------------------
    Resolution: Won't Fix

LWT and counters are pretty specific (and fairly incompatible) paths so I'm 
afraid we can't really provide this.

bq. i need to 1) read the current counter, 2) increase it and check if it 
exceeds the capacity in the application code. but, however, if there are 
concurrent requests come to the app at the same time, this way is broken

If you want to do it this way, you can use a simple {{int}} (rather than a 
{{counter}}) and use LWT to protect against concurrent request. Of course, you 
do have to read-before-write and the performance is unlikely to be very good.

> Feature Request - Conditional update on counters
> ------------------------------------------------
>
>                 Key: CASSANDRA-11592
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-11592
>             Project: Cassandra
>          Issue Type: Bug
>            Reporter: Nick Tan
>            Priority: Minor
>
> hi folks
> what i'd like to do is have a atomic update on counters if it's value is less 
> than some value.
> let's take a example, saying there is a `room`, the capacity is 50 peoples, 
> now i'd like to track the number of peoples join the room. if the counter 
> exceed the room capacity, i'd like to get error notified.
> table define:
> {code:sql}
> CREATE TABLE IF NOT EXISTS room (
>     id uuid,
>     name text,
>     capacity int,
>     PRIMARY KEY(id)
> )
> CREATE TABLE IF NOT EXISTS people_in_room (
>     room_id uuid,
>     num counter,    -- the current number of people in the room
>     PRIMARY KEY(room_id)
> );
> {code}
> pseudo update:
> {code}
> UPDATE people_in_room SET num=num+1 WHERE room_id = :room_id IF num < 
> :room_capacity;
> {code}
> the expected result is, if current num exceeds the room capacity (aka. the IF 
> clause is false), i'd like to get `Applied` column with value of 'false' 
> returned immediately.
> in this way, i can perform the atomic update for counters.
> otherwise, i need to 1) read the current counter, 2) increase it and check if 
> it exceeds the capacity in the application code. but, however, if there are 
> concurrent requests come to the app at the same time, this way is broken.
> thanks



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to