【问题标题】:Transaction Management for Spring data cassandraSpring数据cassandra的事务管理
【发布时间】:2014-10-29 04:43:44
【问题描述】:

我使用 Spring 和 Cassandra 作为底层数据库。曾提到过春雨伞项目'spring data cassandra'。 与hibernate不同,无法找到此处管理事务的方式。 如果你们中的一些人已经合并,请分享交易管理器的详细信息。

【问题讨论】:

    标签: java spring spring-data-cassandra


    【解决方案1】:

    Cassandra 不支持传统 (ACID) 意义上的事务。有一些结构可以在特殊情况下实现诸如事务原子性之类的东西,例如原子批处理(请参阅http://www.datastax.com/dev/blog/atomic-batches-in-cassandra-1-2)或轻量级事务(请参阅http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0),但没有任何东西适合全面的事务管理。

    这主要是 Cassandra 架构的结果,该架构侧重于传统关系数据库无法达到的可扩展性和容错性。

    【讨论】:

    • 我知道 Cassandra 不支持事务原子性。我想知道是否有一些框架可以为我执行任务。Kundera(github.com/impetus-opensource/Kundera/wiki/…) 似乎可以完成这项工作但我正在寻找 Spring-data-cassandra 项目的特定内容(projects.spring.io/spring-data-cassandra)
    • 对不起,@Anish,在 SDC 中没有这样的东西。随时在jira.spring.io/browse/DATACASS 创建一个请求它的问题
    • @Mathew Adams :我在 JIRA 中记录了相同的内容,但他们将其标记为无效。他们误解为 Cassandra 问题,而不是可以通过 Spring 创建包装器而不是在 Cassandra 之上来合并的东西。你可以找到我记录的错误here
    【解决方案2】:

    Cassandra 批处理目前默认是原子的。 http://docs.datastax.com/en/cql/3.0/cql/cql_reference/batch_r.html

    所以它可能是 Spring 数据中与 @Transactional 的最佳等价物 (虽然,完整的 ACID 不适合这个世界,但它不是这样玩的)

    应该播放这样的东西(您可以根据需要更改 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);
    

    【讨论】:

      猜你喜欢
      • 2019-02-24
      • 2015-07-16
      • 1970-01-01
      • 2016-12-02
      • 1970-01-01
      • 2013-06-30
      • 2017-05-29
      相关资源
      最近更新 更多