【问题标题】:How to set client side timestamp in spring data cassandra?如何在 Spring Data cassandra 中设置客户端时间戳?
【发布时间】:2016-11-22 20:36:20
【问题描述】:

在 datastax 驱动中,我们有类似的 api

withTimestampGenerator(new AtomicMonotonicTimestampGenerator())

启用该功能以在客户端为每个查询设置时间戳。我们如何使用 spring data canssandra 实现相同的目标。

我知道我可以在 cql 中使用 "USING TIMESTAMP value" 但是 spring data cassandra 提供了什么?我在 CassandraClusterFactoryBean 中找不到这样的 api。

【问题讨论】:

    标签: cassandra spring-data-cassandra


    【解决方案1】:

    你是对的!

    不幸的是,SD Cassandra 似乎缺少 CassandraCqlClusterFactoryBean 类上的配置选项,该选项支持使用 DataStax Java 驱动程序 Cluster.Builder API 的 withTimestampGenerator(:TimestampGenerator) 配置设置。

    同样不幸的是,目前也没有解决方法(除了 CQL 中的 USING TIMESTAMP)。

    似乎CassandraCqlClusterFactoryBean 缺少以下配置选项:

    1. Cluster.Builder.withAddressTranslator(:AddressTranslator)
    2. Cluster.Builder.withClusterName(:String)
    3. Cluster.Builder.withCodeRegistry(:CodecRegistry)
    4. Cluster.Builder.withMaxSchemaAgreementWaitSeconds(:int)
    5. Cluster.Builder.withSpeculativeExecutionPolicy(:SpeculativeExecutionPolicy)

    不过,请注意,withTimestampGenerator(..) 仅在 DataStax Java 驱动程序的第 3 版中受支持,即 SD Cassandra 的下一个版本(即 1.5.0)会支持...

    此功能仅适用于 V3 或更高版本的原生协议。在早期版本中,时间戳总是在服务器端生成,通过这种方法设置生成器是没有效果的。

    【讨论】:

    • 注意:由于 SD Cassandra API(即CassandraCqlClusterFactoryBean)不支持这些配置选项,SD Cassandra XML 命名空间配置也不支持元数据(显然)。
    • 感谢约翰的回复。所以现在我只会使用 USING TIMESTAMP。
    【解决方案2】:

    时间戳功能在 SD 1.5.x 中可用, public void setTimestampGenerator(TimestampGenerator timestampGenerator) { this.timestampGenerator = timestampGenerator; }

    https://github.com/spring-projects/spring-data-cassandra/blob/cc4625f492c256e5fa3cb6640d19b4e048b9542b/spring-data-cassandra/src/main/java/org/springframework/data/cql/config/CassandraCqlClusterFactoryBean.java

    【讨论】:

      猜你喜欢
      • 2021-07-07
      • 2013-02-08
      • 2023-04-07
      • 2020-03-31
      • 2018-07-23
      • 2013-10-14
      • 2020-11-17
      • 2016-12-26
      • 1970-01-01
      相关资源
      最近更新 更多