Uploaded image for project: 'Apache Cassandra'
  1. Apache Cassandra
  2. CASSANDRA-8319

Allow LWT DELETE with column comparison

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Low
    • Resolution: Invalid
    • 2.1.2
    • Legacy/CQL
    • None

    Description

      Right now, the only way to use LWT with DELETE is to rely on the IF NOT EXISTS keyword

      There may be some scenarios where using IF column=xxx with DELETE is relevant.

      I am preparing a hands-on with a chat application using C*. A chatroom is defined as:

      CREATE TABLE chatroom (
          room_id uuid PRIMARY KEY,
          name text,
          participants list<frozen <person>> // person is an UDT representing a subset of the users table);
      

      Right now, upon removing a participant from the room, I need to:

      • count remaining participants in the room (read the participants list)
      • remove the room (the whole partition) is there isn't anyone inside

      This is a read-before-write pattern, but even this does not prevent race conditions. Indeed, the last participant may leave the room at the same time a new one enters

      So using LWT with "DELETE FROM chatroom IF participants = [] WHERE room_id= ..." may help making the removal safe

      With this design, room creation/deletion as well as participants addition/removal should go through LWT to be consistent. It's slow but participant joining and leaving event frequency is low enough compared to people posting messages to make the trade off not too expensive in general

      Attachments

        Activity

          People

            Unassigned Unassigned
            doanduyhai DuyHai Doan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: