Lightweight transactions (compare-and-set)
One of the more interesting of these improvements is the introduction of optimistic lock-style “lightweight transactions” or “compare-and-set” DML operations to CQL.
INSERT INTO USERS(userid, first_name, last_name)
VALUES ('OpenCredo', 'Open', 'Credo')
IF NOT EXISTS;
The CQL language has been extended with the IF clause for INSERT and UPDATE commands, which lets the user invoke a data modification operation pending some condition specified in the IF part, and have a guaranteed isolation for the test and the modification: no other process can change the values while such a compare-and-set command runs.The addition of lightweight transactions enables use cases that simply weren’t possible to implement safely in prior releases. This is achieved without compromising Cassandra’s ability to scale, as would be the case if traditional RDBMS-style transactions relying on locking were used.
Pro
- Increased featured parity with relational databases
- No need for any external service, tool or synchronization mechanism
- Retains its good scalability characteristics
Con
- Does not offer true ACID transactions
- First release included major bugs, which may now be fixed
- Operations become slower
Triggers
The other item in the feature-list of Cassandra 2.0 that caught our attention is triggers.Triggers have been around for many years in relational database systems, and they have some controversial properties in general. Up until this release Cassandra has offered no option for those requiring triggers; the addition of triggers allows for greater flexibility.It’s still very much an experimental feature (the API is scheduled to change), and definitely not recommended for production usage. Still, it’s interesting to take a glance into the future and see what you can achieve with them.
Pro
- Shows potential
Con
- Can execute anything in the server JVM
- Depends on Cassandra-internal classes
- Written in Java, without access to CQL types
- Can’t (easily) read the database
- You have to deploy jar files on all the nodes of your cluster
Conclusion
In future blog posts we will look at both lightweight transactions and triggers in more detail, including a code-level exploration of API.Whilst not yet mature, these features mark a clear desire to bring Cassandra closer to the functionality of traditional relational databases.
This blog is written exclusively by the OpenCredo team. We do not accept external contributions.