获得“不能完成请求:一个或多个节点不可用”当使用cqlsh执行insert语句时 [英] Getting "unable to complete request: one or more nodes were unavailable" when performing insert statement using cqlsh

查看:220
本文介绍了获得“不能完成请求:一个或多个节点不可用”当使用cqlsh执行insert语句时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Cassandra 2的全新安装上执行插入操作,虽然我能够设置新的键空间和表格,但是当尝试执行插入操作时,我会得到上面提到的错误。 / p>

我没有任何奇怪的多服务器设置,它只是运行一个计算机与测试数据库,因此我与节点配置混乱

用于创建所述项目的命令是:

  CREATE KEYSPACE demodb WITH REPLICATION = {'class':'NetworkTopologyStrategy ','DC1':3}; 
USE demodb;
CREATE TABLE users(user_name varchar,state varchar,birth_year bigint,PRIMARY KEY(user_name));
INSERT INTO用户(user_name,state,birth_year)VALUES('canadiancreed','PA',1976);


解决方案

  CREATE KEYSPACE demodulationb WITH REPLICATION = {'class':'NetworkTopologyStrategy','DC1':3}; 

很可能是你的罪魁祸首。它说,demodb键空间中的数据属于DC1,应该复制3次。如果您的单个测试节点未指定为DC1的成员,则插入此键空间的任何请求都将失败。此外,如果它是DC1的成员,并且一致性级别大于1,所有请求将失败,因为写入将不可能获得多个acknolegdment。



检查数据中心的名称(nodetool状态),并调整它们的键空间复制细节以匹配。这很可能解决你的问题。



----编辑更多细节和更好的格式----



最常见的错误新用户与Cassandra。基本上在Cassandra中有硬件的逻辑单元,我们称之为数据中心。数据中心应该表示一组地理上或者以某种其他方式不同的机器组。您可以制作其中的许多功能,并防止在一个地理位置发生故障,导致应用程序下线。



键空间是一种逻辑结构,用于组织信息组,它将与关系世界中的数据库进行分析。每个Keyspace都可以指定应该复制哪个机器和多少个机器。如果我们使用NetworkTopologyStrategy,则在每个数据中心basiss上指定复制 。我们使用CREATE KEYSPACE .... WITH REPLICATION在创建时指定这些详细信息(虽然可以稍后修改)。



在上面的语句中, Keyspace demodb中的所有信息应该被放置在数据中心DC1中,并且在该数据中心中应该有3个数据副本。这基本上意味着您在DC1中至少有3个节点,并且您希望在每个节点上有一个数据副本。这本身不会导致插入失败,除非整个数据中心对于Cassandra集群是未知的。如果你没有初始配置你的C *集群,并且正在运行的库存yaml。



运行nodetool状态将显示当前节点相信集群的状态。这是C *运行的本地机器的输出。

 数据中心:Cassandra 
==== ===============
状态=上/下
| /状态=正常/离开/加入/移动
- 地址加载拥有)主机ID令牌机架
UN 127.0.0.1 93.37 KB 100.0%50be3bec-7e30-4385-bd4a-918055a29292 4731866028208108826 rack1

此输出显示我有一个节点在名为Cassandra的集群中操作。这意味着对于在其他数据中心中需要副本的键空间的任何插入都将失败,因为集群不知道如何处理这些请求。 (如果节点只是关闭,但我们在我们可以保存提示之前已经看到它们,但是如果从未见过其他DC,我们将拒绝该请求,因为群集很可能配置错误。)



要修复这种情况,我将使用

修改我的键空间

  cqlsh:demodb& ALTER KEYSPACE demodb WITH REPLICATION = {'class':'NetworkTopologyStrategy','Cassandra':1}; 

现在,demoDB需要在数据中心Cassandra中的一台机器上的数据的副本。这是伟大的beacuase作为我的nodetool输出状态,我有一个名为Cassandra的数据中心中的一个节点。如果我尝试插入现在它通过。

  cqlsh:demodb> INSERT INTO users(user_name,state,birth_year)VALUES('canadiancreed','PA',1976); 
cqlsh:demodb> select * from user where user_name ='canadiancreed';

user_name | birth_year |状态
--------------- + ------------ + -------
canadiancreed | 1976 | PA

(1 rows)

具有正确的数据中心名称

  CREATE KEYSPACE demodb WITH REPLICATION = {'class':'NetworkTopologyStrategy','Cassandra' :1}; 


I'm trying to perform an insert on a brand new install of Cassandra 2, and while I was able to set up a new keyspace and table just fine, I get the eror mentioned above when attempting to perform an insert.

I dont' have any fancy multi server setup, it's just running one one computer with a test db hence my confusion with node configuration

Commands used to create said items are:

CREATE KEYSPACE demodb WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'DC1' : 3 };
USE demodb;
CREATE TABLE users (user_name varchar, state varchar, birth_year bigint, PRIMARY KEY (user_name));
INSERT INTO users (user_name, state, birth_year) VALUES ('canadiancreed', 'PA', 1976);

解决方案

CREATE KEYSPACE demodb WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'DC1' : 3 };

Is most likely your culprit. It says that data in the demodb keyspace belongs in DC1 and should be replicated 3 times. If your single test node is not specified as being a member of DC1 any request to insert to this keyspace will fail. In addition, if it is a member of DC1 and the consistency level is greater than 1 all requests will fail because it will be impossible for the write to get more than one acknolegdment.

Check what your Data Center is named (nodetool status) and adjust they keyspace replication details to match. That will most likely solve your problems.

---- Edited for more Details and Better Formatting ----

This is one of the most common errors new users have with Cassandra. Basically in Cassandra there are logical units of hardware we call Datacenters. A datacenter is supposed to represent a group of geographically or in some other way distinct group of machines. You can make many of these and protect against failure in one geographic location from causing your application to go offline.

Keyspaces are a logical structure for organizing groups of information, it would be analgous to a Database in the relational world. Each Keyspace gets to specify on which and how many machines should it replicate against. If we use the NetworkTopologyStrategy the replication is specified on a per datacenter basiss. We specify these details at creation time (although they can be modified later) using the "CREATE KEYSPACE .... WITH REPLICATION ".

In your above statement you have specified that all information within the Keyspace demodb should be placed in the datacenter "DC1" and there should be 3 copies of the data in that datacenter. This basically means you have at least 3 Nodes in DC1 and you want a copy of the data on each of those nodes. This by itself will not cause an insert to fail unless the entire datacenter is unknown to the Cassandra cluster. This would be the case if you did no initial configuration of your C* cluster and are just running off the stock yaml.

Running nodetool status will show you what a current node believes about the state of the cluster. Here is the output from C* running off my local machine.

Datacenter: Cassandra
=====================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Owns (effective)  Host ID                               Token                                    Rack
UN  127.0.0.1  93.37 KB   100.0%            50be3bec-7e30-4385-bd4a-918055a29292  4731866028208108826                      rack1

This output shows that I have a single node operating within a cluster named "Cassandra". This means any inserts to keyspaces which require replicas in other Datacenters will fail because the cluster doesn't know how to handle those requests. (If the nodes were simply down but we had seen them before we could save hints but if the other DC has never been seen we reject the request because the cluster has most likely been misconfigured.)

To fix this situation for I would modify my Keyspace using

cqlsh:demodb> ALTER KEYSPACE demodb WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'Cassandra' : 1 };

Now demoDB requires a copy of the data in 1 machine in the datacenter Cassandra. This is great beacuase as my nodetool output states, I have one node in a datacenter named Cassandra. If I try an insert now it passes.

cqlsh:demodb> INSERT INTO users (user_name, state, birth_year) VALUES ('canadiancreed', 'PA', 1976);
cqlsh:demodb> select * from users where user_name = 'canadiancreed' ;

 user_name     | birth_year | state
---------------+------------+-------
 canadiancreed |       1976 |    PA

(1 rows)

and I would change my setup schema script to have the correct datacenter name as well

CREATE KEYSPACE demodb WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'Cassandra' : 1 };

这篇关于获得“不能完成请求:一个或多个节点不可用”当使用cqlsh执行insert语句时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆