计数器未在cassandra中更新

时间:2016-08-31 08:53:10

标签: cassandra

我在cf中更新新计数器时遇到问题。如果我执行下一个cql语句(特定键是新的):

UPDATE markerstats SET numbermarkers = numbermarkers + 1 WHERE projectid = 4 AND type = 'SNP';

查询执行没有错误。然后我执行下一个查询:

SELECT * FROM markerstats

我没有得到新更新计数器的行。我尝试过使用datastax java驱动程序,devcenter以及直接使用。 cf的定义是:

CREATE TABLE markerstats (
  projectid bigint,
  type text,
  numbermarkers counter,
  numberpartitions counter,
  PRIMARY KEY ((projectid), type)
) WITH
  bloom_filter_fp_chance=0.010000 AND
  caching='KEYS_ONLY' AND
  comment='' AND
  dclocal_read_repair_chance=0.000000 AND
  gc_grace_seconds=864000 AND
  index_interval=128 AND
  read_repair_chance=0.100000 AND
  replicate_on_write='true' AND
  populate_io_cache_on_flush='false' AND
  default_time_to_live=0 AND
  speculative_retry='99.0PERCENTILE' AND
  memtable_flush_period_in_ms=0 AND
  compaction={'class': 'SizeTieredCompactionStrategy'} AND
  compression={'sstable_compression': 'LZ4Compressor'};

我正在使用cassandra(2.0.7)单节点实例进行测试。

任何人都知道可能出现什么问题?

注意:我之前在cf a DELETE语句

中执行过

2 个答案:

答案 0 :(得分:1)

Thanks to the help of the comments in the questions I could manage to restore the counters which were deleted by: updating the gc_grace_seconds of the cf to 0 and running a major compaction on the table.

Source: http://grokbase.com/t/cassandra/user/14a9988tww/deleting-counters

Looks like the limitation on reuse counters after deleting them is going to be removed in some 3.* version (https://issues.apache.org/jira/browse/CASSANDRA-9810)

答案 1 :(得分:1)

我在ScyllaDB(最新版本4.4.0)中重现了这种情况,它与Cassandra非常相似并且支持CQL。如果您之前删除了该行,则具有相同 WHERE 条件的新 UPDATE 命令不会将该行插入到数据库中。这似乎是一个错误,但最好不要删除计数器。相反,您可以将所有计数器值更新为 0 而不是删除。