尝试从Cassandra检索数据时出现不可用的异常

时间:2021-03-23 04:49:19

I have a Cassandra DB and am creating a column family as follows.

我有一个Cassandra数据库,我正在创建一个列系列,如下所示。

CREATE COLUMN FAMILY users
WITH comparator = UTF8Type
AND key_validation_class=UTF8Type
AND column_metadata = [
{column_name: username, validation_class: UTF8Type}
{column_name: city, validation_class: UTF8Type, index_type="KEYS"}
];

I am inserting data into the column family using the following in node.js

我使用node.js中的以下内容将数据插入到列族中

var cql = "INSERT INTO App.users(KEY,username,city) VALUES (?,?,?)";
cassandra.execute(cql,[json.username+(new Date().getTime()),json.username,
    json.city], function(err, rows) {
  if(err) {
    console.log(err);
    return 1;
  }
  return 0;
});

This executes properly, but suppose I use cassandra-cli and run

这可以正常执行,但假设我使用cassandra-cli并运行

 get user where city='NYC';

I get an unavailable exception. The following is the CQL query which I have in my node.js script which throws the same exception.

我得到一个不可用的例外。以下是我在node.js脚本中的CQL查询,该脚本会抛出相同的异常。

var cql = "SELECT notes,heading FROM App.users where city=?";

Do you have any idea what I am doing wrong? I have made a secondary index on the city column, I hope that is correct. Thanks in advance.

你知道我做错了什么吗?我在城市专栏上做了一个二级索引,我希望这是正确的。提前致谢。

2 个解决方案

#1


1  

Thanks Abhi for your suggestion. The link was really helpful, so I created the keyspace in the following manner and it worked properly.

感谢Abhi的建议。该链接非常有用,因此我以下列方式创建了密钥空间,并且它正常工作。

create keyspace App with placement_strategy ='org.apache.cassandra.locator.SimpleStrategy' 
   and strategy_options = {replication_factor:2};

I have connected 2 computers to my cassandra cluster, hence the replication_factor is set to 2.

我已将2台计算机连接到我的cassandra集群,因此replication_factor设置为2。

#2


0  

Perhaps it is a keyspace creation issue. Check your keyspace creation schema properly. May be this discussion on cassandra user group will give you a better idea

也许这是一个密钥空间创建问题。正确检查您的密钥空间创建架构。可能这个关于cassandra用户组的讨论会给你一个更好的主意

#1


1  

Thanks Abhi for your suggestion. The link was really helpful, so I created the keyspace in the following manner and it worked properly.

感谢Abhi的建议。该链接非常有用,因此我以下列方式创建了密钥空间,并且它正常工作。

create keyspace App with placement_strategy ='org.apache.cassandra.locator.SimpleStrategy' 
   and strategy_options = {replication_factor:2};

I have connected 2 computers to my cassandra cluster, hence the replication_factor is set to 2.

我已将2台计算机连接到我的cassandra集群,因此replication_factor设置为2。

#2


0  

Perhaps it is a keyspace creation issue. Check your keyspace creation schema properly. May be this discussion on cassandra user group will give you a better idea

也许这是一个密钥空间创建问题。正确检查您的密钥空间创建架构。可能这个关于cassandra用户组的讨论会给你一个更好的主意