简体   繁体   English

Spring Data Cassandra的事务管理

[英]Transaction Management for Spring data cassandra

I am using Spring and Cassandra as the underlying database. 我使用Spring和Cassandra作为底层数据库。 Had referred to the spring umbrella project 'spring data cassandra'. 曾提到过春季伞项目'spring data cassandra'。 Could not find out how transactions are managed here unlike hibernate. 与休眠不同,无法找到此处如何管理事务。 Kindly share the details for the Transaction Manager to be included if some of you have incorporated the same. 如果您有些人已经合并,请分享交易管理器的详细信息。

Cassandra does not support transactions in the traditional (ACID) sense. Cassandra不支持传统(ACID)的事务。 There are a few constructs where you can achieve something like transactional atomicity in special cases, like atomic batches (see http://www.datastax.com/dev/blog/atomic-batches-in-cassandra-1-2 ) or Lightweight Transactions (see http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0 ), but nothing that lends itself to a full-blown transaction management. 有一些构造可以在特殊情况下实现事务原子性,例如原子批(参见http://www.datastax.com/dev/blog/atomic-batches-in-cassandra-1-2 )或轻量级交易(参见http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0 ),但没有任何内容可以用于全面的事务管理。

This is mostly the result of the architecture of Cassandra, which focuses on scalability and fault tolerance on a level not possible with traditional relational databases. 这主要是Cassandra体系结构的结果,该体系结构侧重于可伸缩性和容错能力,其水平是传统关系数据库无法实现的。

Cassandra batch is currently atomic by default. 默认情况下,Cassandra批处理当前是原子的。 http://docs.datastax.com/en/cql/3.0/cql/cql_reference/batch_r.html http://docs.datastax.com/en/cql/3.0/cql/cql_reference/batch_r.html

So it is , probably, the best equivalent to @Transactional in spring data (Although, full ACID is not for this world, it is just not that way it plays) 因此,它可能是春季数据中@Transactional的最佳替代品(尽管完整的ACID不适用于这个世界,但这并不是它的播放方式)

Something like this should play(YOU can change values of ConsistencyLevel and RetryPolicy as you wish - that is the matter!): 这样的事情应该起作用(您可以根据需要更改ConsistencyLevel和RetryPolicy的值-就是这样!):

Insert insert1 = CassandraTemplate.createInsertQuery("table1", value1, new WriteOptions(ConsistencyLevel.LOCAL_ONE, RetryPolicy.DEFAULT), cassandraConverter);

Insert insert2 = CassandraTemplate.createInsertQuery("table2", value2, new WriteOptions(ConsistencyLevel.LOCAL_ONE, RetryPolicy.DEFAULT), cassandraConverter);

Batch batch = QueryBuilder.batch(insert1,insert2);

//cassandraOperations - object of CassandraTemplate , injected by Spring
cassandraOperations.execute(batch);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM