2

我在使用 Cassandra 1.2 (DSE 3.1.1) 时遇到了一个奇怪的问题。我有一个名为 JSESSION 的表,结构如下:

cqlsh> use recommender;
cqlsh:recommender> describe table jsession;

CREATE TABLE jsession (
  sessionid text,
  accessdate timestamp,
  atompaths set<text>,
  filename text,
  processed boolean,
  processedtime timestamp,
  userid text,
  usertag bigint,
  PRIMARY KEY (sessionid, accessdate)
) 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
  read_repair_chance=0.100000 AND
  replicate_on_write='true' AND
  populate_io_cache_on_flush='false' AND
  compaction={'class': 'SizeTieredCompactionStrategy'} AND
  compression={'sstable_compression': 'SnappyCompressor'};

CREATE INDEX processed_index ON jsession (processed);

您可以看到该表在布尔字段“已处理”上建立了索引。当我开始在此表上编码时,以下查询曾经正常工作:

cqlsh:recommender> select * from jsession where processed = false limit 100;

但是现在大小超过 100,000(根本不是一个大数字),查询突然停止工作,我还想不出解决方法。

cqlsh:recommender> select count(*) from jsession limit 1000000;

 count
--------
 142320

cqlsh:recommender> select * from jsession where processed = false limit 100;
Request did not complete within rpc_timeout.

我尝试了几个选项,将 rpc_timout 增加到 60 秒,还用更多内存(现在是 8GB)启动 Cassandra,但我仍然遇到同样的问题。你有什么解决办法吗?

更深层次的问题是在 CQL3 中为布尔字段建模的正确方法是什么,以便我可以搜索该字段并对其进行更新。处理完该会话后,我需要将“已处理”字段设置为 true。

4

1 回答 1

2

您没有布尔建模问题。您只需要对结果进行分页。

select * from jsession where processed = false and token(sessionid) > token('ABC') limit 1000;

其中“ABC”是您阅读的最后一个会话 ID(或“”用于第一个查询)。只需继续将令牌 ID 反馈到此查询中,直到您阅读完所有内容。

另见http://www.datastax.com/documentation/cql/3.1/webhelp/index.html#cql/cql_reference/../cql_using/paging_c.html

于 2013-12-06T22:04:10.623 回答