How to executing batch statement and LWT as a transaction in Cassandra

谁都会走 提交于 2019-12-06 12:16:27

Caution with Lightweight Transactions (LWT)

Lightweight Transactions are currently considered a Cassandra anti-pattern because of the performance issues you are suffering.

Here is a bit of context to explain.

Cassandra does not use RDBMS ACID transactions with rollback or locking mechanisms. It does not provide locking because of a fundamental constraint on all kinds of distributed data store called the CAP Theorem. It states that it is impossible for a distributed computer system to simultaneously provide all three of the following guarantees:

  • Consistency (all nodes see the same data at the same time)
  • Availability (a guarantee that every request receives a response about whether it was successful or failed)
  • Partition tolerance (the system continues to operate despite arbitrary message loss or failure of part of the system)

Because of this, Cassandra is not good for atomic operations and you should not use Cassandra for this purpose.

It does provide lightweight transactions, which can replace locking in some cases. But because the Paxos protocol (the basis for LWT) involves a series of actions that occur between nodes, there will be multiple round trips between the node that proposes a LWT and the other replicas that are part of the transaction.

This has an adverse impact on performance and is one reason for the WriteTimeoutException error. In this situation you can't know if the LWT operation has been applied, so you need to retry it in order to fallback to a stable state. Because LWTs are so expensive, the driver will not automatically retry it for you.

LTW comes with big performance penalties if used frequently, and we see some clients with big timeout issues due to using LWTs.

Lightweight transactions are generally a bad idea and should be used infrequently.

If you do require ACID properties on part of your workload but still require it to scale , consider shifting that part of your load to cochroach BD. In summary, if you do need ACID transactions it is generally a lot easier to bring a second technology in.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!