NoHostAvailable error in cqlsh console

青春壹個敷衍的年華 提交于 2021-01-22 08:02:14

问题


I was able to get rid of this error later but i am not sure what i did is correct. 1 )

CREATE KEYSPACE myKeySpace WITH replication = 
  {'class': 'NetworkTopologyStrategy', 'dc1': '1', 'dc2': '2'}
  AND durable_writes = true;

Execute create table and select table after this. This throws "NoHostAvailable:" error in the console.

2 ) If I change the create statement to the below one, the select query works.

CREATE KEYSPACE myKeySpace WITH replication = 
  {'class': 'NetworkTopologyStrategy', 'datacenter1': '1', 'dc2': '2'}
  AND durable_writes = true; 

If I have a default datacenter1, it works. I'm not able to understand why it is only working when I give datacenter1. Please help.


回答1:


Which data centers do you see when you execute a nodetool status?

The data centers that you specify as the replication factor (RF) for your keyspace must be predefined in either your cassandra-rackdc.properties or cassandra-topology.properties files (depending the Snitch you configured).




回答2:


I encountered the same issue when I am trying to access the table that is created in keyspace with a replication strategy as NetworkTopologyStrategy.

The reason I found later is due to replicas unavailability because I am using it in local.

If I change the keyspace replication strategy to SimpleStrategy and replication_factor to 1, the error is gone.

Hope this helps.




回答3:


You can only specify the datacenter which are present/configured in you cassandra cluster.

Run nodetool status, which gives you the cluster details like datacenter names, rack names etc.

Used the datacenter names from here while creating keyspaces with NetworkTopologyStrategy class replication.




回答4:


At first step, you may try:

'class':'SimpleStrategy'

to review your code, exclude strategy class!

After that you work on strategy class, if you did not find any error.




回答5:


You should first check the defined datacenter name in the property file "cassandra-rackdc.properties"(latest version of Cassandra using this property file) or "cassandra-topology.properties" based on the defined datacenter name you have to use that datacenter name while create a keyspace. of you can check the nodetool status before creating keyspace where you can see the default datacenter name.



来源:https://stackoverflow.com/questions/41879216/nohostavailable-error-in-cqlsh-console

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!