Nick Tan created CASSANDRA-11592:
------------------------------------

             Summary: 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 (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 is 
concurrent request 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