Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is an update in Cassandra not an anti pattern?

As per Datastax documentation a read before a write in Cassandra is an anti pattern.

Whenever we use UPDATE either in CQLSH or using the Datastax drivers to set a few columns (with IFs & collection updates), does it not do a read before write first? Is that not an anti pattern? Am I missing something?

P.S I am not talking about mere UPSERTS but UPDATES on specific columns.

TIA!

like image 204
Tanvi Avatar asked Aug 03 '17 17:08

Tanvi


People also ask

How updates work in Cassandra?

Cassandra treats each new row as an upsert: if the new row has the same primary key as that of an existing row, Cassandra processes it as an update to the existing row. During a write, Cassandra adds each new row to the database without checking on whether a duplicate record exists.

Is Cassandra Good for updates?

Lots of updates and deletes. Cassandra is incredible at writes (here are the reasons for this amazing write performance). But it's only append-oriented. If you need to update a lot, Cassandra's no good: for each update, it just adds a 'younger' data version with the same primary key.

What is keyspace in Cassandra?

What is a Keyspace in Cassandra? A keyspace is a data container in Cassandra, similar to a database in relational database management systems (RDMBS). A cluster has one keyspace per application, as many as needed, depending on requirements and system usage.


1 Answers

No, Update is not an anti-pattern.

In Cassandra update is an upsert operation similar to insert.

UPDATE writes one or more column values to a row in a Cassandra table. Like INSERT, UPDATE is an upsert operation: if the specified row does not exist, the command creates it. All UPDATEs within the same partition key are applied atomically and in isolation.

But Lightweight transactions are read before write operation. Actually at the cost of four round trips.

Example of Lightweight transaction :

#Lightweight transaction Insert
INSERT INTO customer_account (customerID, customer_email) 
VALUES (‘LauraS’, ‘[email protected]’)
IF NOT EXISTS;

#Lightweight transaction Update
UPDATE customer_account
SET    customer_email=’[email protected]’
IF     customerID=’LauraS’; 

Both of the above statement are Lightweight transactions

Source : http://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlUpdate.html#cqlUpdate__description

like image 168
Ashraful Islam Avatar answered Oct 30 '22 05:10

Ashraful Islam