0

Im trying to understand this.

cassandra batches are atomic always, and if the batch only modifies a single partition of a single table, then that batch is also isolated.

but what about multi table batches partitioned by the same key? assume this tables:

orders (
    order_id pk,
    created_at,
    user_id
)

order_items ( order_id, product_id, quantity, primary key (order_id, product_id) )

both tables are partitioned by the same key. if i want to atomically create an order, let say order_id = 123, like this:

begin batch 
  insert into orders ... (123) 
  insert into order_items .... where order_id = 123
  insert into order_items .... where order_id = 123
apply batch 

is this batch atomic and isolated ? provided that orders table partition for 123 and order_items table partition for 123 reside in the same node.

Erick Ramirez
  • 4,590
  • 1
  • 8
  • 30

1 Answers1

0

Isolation can only be achieved if the batch is writing to a single partition because by definition, there is only one partition -- there are no other partitions to isolate.

For multi-partition batches, Cassandra can only guarantee (1) atomicity, and (2) the order of the statements within the batch but (3) not isolation because (4) any client (app instance) can read the already-written rows even when there are still rows in the batch to process.

I should also point out that the partitioner's hashing algorithm is deterministic so a partition key will always get hashed to the same token value. The reason I mention this is that you mentioned twice about the partitions being "on the same node". The partitions in any table will ALWAYS be on the same replicas IF those partitions all have the same partition key so being "on the same node" is irrelevant in this discussion. Cheers!

Erick Ramirez
  • 4,590
  • 1
  • 8
  • 30