cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nick Tan (JIRA)" <>
Subject [jira] [Commented] (CASSANDRA-11592) Feature Request - Conditional update on counters
Date Mon, 18 Apr 2016 13:49:25 GMT


Nick Tan commented on CASSANDRA-11592:

thanks [~slebresne]

yes, i'm using the 'simple int with LWT' approach for now, at least it fulfills the requirement
with putting aside the performance.

> Feature Request - Conditional update on counters
> ------------------------------------------------
>                 Key: CASSANDRA-11592
>                 URL:
>             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
> 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}
>     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

View raw message