【问题标题】:Cassandra count query failing due to AssertionError由于 AssertionError,Cassandra 计数查询失败
【发布时间】:2014-01-23 06:28:46
【问题描述】:

我第一次尝试 Cassandra 并在本地运行它以实现简单的会话管理数据库。 [Cassandra-2.0.4,CQL3,datastax驱动2.0.0-rc2]

当表中没有数据时,以下计数查询可以正常工作:

select count(*) from session_data where app_name=? and account=? and last_access > ?

但是即使在表中插入一行后,查询也会失败并出现以下错误:

java.lang.AssertionError
at org.apache.cassandra.db.filter.ExtendedFilter$WithClauses.getExtraFilter(ExtendedFilter.java:258)
at org.apache.cassandra.db.ColumnFamilyStore.filter(ColumnFamilyStore.java:1719)
at org.apache.cassandra.db.ColumnFamilyStore.getRangeSlice(ColumnFamilyStore.java:1674)
at org.apache.cassandra.db.PagedRangeCommand.executeLocally(PagedRangeCommand.java:111)
at org.apache.cassandra.service.StorageProxy$LocalRangeSliceRunnable.runMayThrow(StorageProxy.java:1418)
at org.apache.cassandra.service.StorageProxy$DroppableRunnable.run(StorageProxy.java:1931)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

这是我正在使用的架构:

CREATE KEYSPACE session WITH replication= {'class': 'SimpleStrategy', 'replication_factor': 1};

CREATE TABLE session_data (
username text,
session_id text,
app_name text,
account text,
last_access timestamp,
created_on timestamp,
PRIMARY KEY (username, session_id, app_name, account)
);

create index sessionIndex ON session_data (session_id);
create index sessionAppName ON session_data (app_name);
create index lastAccessIndex ON session_data (last_access);

我想知道表定义/索引或查询本身是否有问题。任何帮助/见解将不胜感激。

【问题讨论】:

    标签: cassandra


    【解决方案1】:

    您似乎遇到了 Cassandra 中的错误。这是 Cassandra 源代码中的断言和相关 cmets:

    /*
     * This method assumes the IndexExpression names are valid column names, which is not the
     * case with composites. This is ok for now however since:
     * 1) CompositeSearcher doesn't use it.
     * 2) We don't yet allow non-indexed range slice with filters in CQL3 (i.e. this will never be
     * called by CFS.filter() for composites).
     */
    assert !(cfs.getComparator() instanceof CompositeType);
    

    此代码在 cassandra-2.0.4trunk 之间作为票证 CASSANDRA-5417 的一部分进行了修改,但我不清楚作者是否意识到这一点问题。断言被删除,但评论没有。我建议向 Cassandra 项目提交错误报告。

    【讨论】:

    • 谢谢@Andy。我提交了一个错误报告CASSANDRA-6612
    • 在此期间,您是否知道是否有另一个最近的稳定版本可能没有这个问题?下载页面列出:2.0.4 和 1.2.13。但我对 Cassandra 的了解还不够,无法理解两者之间的潜在差异。
    • 我在 Cassandra 1.2 上尝试了您的架构,并为 session_idapp_name 获得了 Bad Request: Cannot create index on PRIMARY KEY part。似乎主键部分的二级索引是一个问题。尝试创建一个单独的单值主键(该值可以是 username+session_id+app_name_account 的串联,其内容将与这些字段冗余。)
    • 我在尝试时遇到了同样的问题。我记得在某处读到 1.2 支持复合键字段上的二级索引.. 但可能不是。通过单值主键,您的意思是有一个附加列来存储连接值,然后将此列用作主键?或者有没有更好的方法在 CQL 中实现这一点?
    • 谢谢@AndyS。我能够通过使用连接列创建单独的主键来解决该问题。我仍然不清楚为什么我不能在主键列上创建二级索引,但我会接受这个答案,因为它让我克服了那个特定的错误。
    猜你喜欢
    • 2019-11-30
    • 1970-01-01
    • 2015-05-14
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-19
    • 1970-01-01
    相关资源
    最近更新 更多