36

I am going through apache cassandra and working on sample data insertion, retrieving etc.

The documentation is very limited.

I am interested in knowing

  • can we completely replace relation db like mysql/ oracle with cassandra?
  • does cassandra support rollback/ commit?
  • does cassandra clients (thrift/ hector) support fetching associated object (objects where we save one super columns' key in another super column family)?

This will help me a lot to proceed further.

thank you in advance.

Kumar D
  • 1,308
  • 5
  • 19
  • 43

5 Answers5

37

Short answer: No.

By design, Cassandra values availability and partition tolerance over consistency1. Basically, it's not possible to get acceptable latency while maintaining all three of qualities: one has to be sacrificed. This is called CAP theorem.

The amount of consistency is configurable in Cassandra using consistency levels, but there doesn't exist any semantics for rollback. There's no guarantee that you'll be able to roll back your changes even if the first write succeeds.

If you want to build application with transactions or locks on top of Cassandra, you probably want to look at Zookeeper, which can be used to provide distributed synchronization.

You might've already guessed this, but Cassandra doesn't have foreign keys or anything like that. This has to be handled manually. I'm not that familiar with Hector, but a higher-level client could be able to do this semi-automatically.

Whether or not you can use Cassandra to easily replace a RDBMS depends on your specific use case. In your use case (based on your questions), it might be hard to do so.

Marco A.
  • 43,032
  • 26
  • 132
  • 246
Lautis
  • 626
  • 5
  • 4
  • Thanks Lautis. After considering all the features, we decided not to go for cassandra and stick to relational database. – Kumar D Jul 10 '10 at 11:41
  • 1
    Good thread on the cassandra mailing list about transactions: http://cassandra-user-incubator-apache-org.3065146.n2.nabble.com/best-practices-for-simulating-transactions-in-Cassandra-td7064256.html – Zanson Dec 22 '11 at 23:20
  • 1
    @Lautis What does it mean that « [Consistency is configurable] **but** there doesn't exist any semantics for rollback» I'm interested in the "but" how transaction is related to "consistency levels"? – amirouche Sep 11 '15 at 14:57
  • a suggestion... use a 'hybrid' approach. we are using mysql and Cassandra(for high read/write data that do not need ACID transactions.) – Jeryl Cook May 09 '16 at 14:06
6

In version 2.x you can combine CQL-statements in logged batch that is atomic. Either all or none of statements succeed. Also you can read about lightweight transactions. More than that - there are several persistence managers for Cassandra. You can achive foreign keys behavior on client level with them. For example, Achilles and Kundera.

sedovav
  • 1,986
  • 1
  • 17
  • 28
2

If Zookeeper is able to handle transactions that has Oracle-quality then its a done deal. Relations and relation integrity is no problem to implement on top of ANY database. A foreign key is just another data-field. ACID/Transactions is the key issue.

Mattias
  • 29
  • 1
  • 1
    I disagree that foreign key is just another data-field. The type of enforcement implemented in SQL databases handles when the data deleted by other connection just about when your connection is trying to refer to it. It will reject one of the connections properly. How would you enforce that when implementing in higher layer, without locking/resource synchronization that also affects performance? – Daniel Baktiar Apr 23 '14 at 10:03
1

instead of commit and rollback, you must use batch. batch worked atomic, this means all records in multiple tables submit or no submit atomic mode for example :

var batch = new BatchStatement();
batchItem= session.Prepare(stringCommand);
batch.Add(batchItem);
var result = session.ExecuteAsync(batch);
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 08 '21 at 15:35
  • for more information, you can see below links, above example is for c# language and below links is contain cassandra cql example https://www.tutorialspoint.com/cassandra/cassandra_batch.htm and https://www.baeldung.com/java-cql-cassandra-batch, i hope this help to you – Rasoul Harouni Feb 17 '22 at 20:35
0
  1. Of course you can but it is completely depends on your use case. If you don't pick the right db for your use case then you need to worry about lots of things on your own. For ex, in rdbms geographically distribution doesn't provided you need to find a way to do it. In cassandra, you lack some acid properties under some conditions. You need to handle those properties on application side.

  2. Yes but limited for certain use cases. You can use batch property. It supports rollback but you lack the isolation. I am not sure this property exist in OSS Cassandra. For more info look

  3. Dont understand what you mean by super column. If you ask to find an id in another table columns, yeah you can do it, why not. But definitely not understand what you mean by super column.

Overall Cassandra is not ACID compliant but there are some features that helps you under some conditions to be ACID compliant like batch, lightweight transactions.

c.guzel
  • 173
  • 6
  • 18