【问题标题】:Cassandra: how to initialize the counter column with value?Cassandra:如何用值初始化计数器列?
【发布时间】:2016-07-30 02:07:25
【问题描述】:

我必须使用 Facebook Linkbench 对 Cassandra 进行基准测试。 Benchmark 有两个阶段,加载阶段和请求阶段。 在加载阶段,Linkbench 用默认值(图形数据)填充 cassandra 表:节点、链接和计数(用于链接计数)。

计数表如下所示:

keyspace.counttable ( link_id bigint, link_type bigint, time bigint, version bigint, count counter, PRIMARY KEY (link_id, link_type, time, version)

我的问题是如何插入默认计数器值(在 Linkbench 请求阶段递增和递减计数器之前)?

如果用 cassandra 无法做到这一点,我应该如何增加/减少 bigint 变量(而不是计数器变量)

有什么建议和建议吗?非常感谢。

【问题讨论】:

    标签: cassandra


    【解决方案1】:

    默认值为零。给定

    create table counttable ( link_id bigint, link_type bigint, time bigint, version bigint, count counter, PRIMARY KEY (link_id, link_type, time, version) );

    update counttable set count = count + 1 where link_id = 1 and link_type = 1 and time = 1 and version = 1;

    我们看到count的值现在是1。

    select * from counttable ; link_id | link_type | time | version | count ---------+-----------+------+---------+------- 1 | 1 | 1 | 1 | 1 (1 rows)

    因此,如果我们想将其设置为其他值,我们可以:

    update counttable set count = count + 500 where link_id = 1 and link_type = 1 and time = 1 and version = 2; select * from counttable ; link_id | link_type | time | version | count ---------+-----------+------+---------+------- 1 | 1 | 1 | 1 | 1 1 | 1 | 1 | 2 | 500 (2 rows)

    【讨论】:

      【解决方案2】:

      没有用非零值初始化计数器列的优雅方法。您可以对计数器字段执行的唯一操作是递增/递减。我建议将偏移量(例如您的预期初始值)保留在不同的列中,并在您的客户端应用程序中简单地添加这两个值。

      【讨论】:

      • 谢谢!我正在寻找只有一个操作和一列(增量或减量)的解决方案。它必须带有计数器字段或整数。
      【解决方案3】:

      感谢您的回答。我实现了以下解决方案来初始化计数器字段。 由于计数器字段的初始值和默认值是 0 ,我用我的默认值递增它。它看起来像 Don Branson 解决方案,但只有一列:

      创建表计数表( link_id 大整数, 链接类型大整数, 计数计数器, 主键(link_id,link_type) );

      我用这个语句设置值(在加载阶段):

      update counttable set count = count + myValue where link_id = 1 and link_type = 1;
      
      select * from counttable ;
      
       link_id | link_type | count
      ---------+-----------+--------
             1 |         1 |  myValue (added to 0)
      
      (1 row)
      

      【讨论】:

        猜你喜欢
        • 2017-10-05
        • 1970-01-01
        • 2021-06-03
        • 1970-01-01
        • 2021-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-23
        相关资源
        最近更新 更多