doubleB
doubleB

Reputation: 348

Error during inserting data: NoHostAvailable:

I try to learn basics of Apache Cassandra. I found this simple example of application at https://docs.datastax.com/en/cql/3.1/cql/ddl/ddl_music_service_c.html

So I created a keyspace, then I created a table, and now I am trying to add some data to the database.

But when I try to Insert data I have got an error: "NoHostAvailable:" That's it. No more information.

NoHostAvailable

So far I've tried to update python driver (NoHostAvailable exception connecting to Cassandra from python) but it didn't work.

What I do wrong? Or is it a problem with cqlsh?

Upvotes: 8

Views: 7812

Answers (6)

Majid Hajibaba
Majid Hajibaba

Reputation: 3260

To change replication strategy (from NetworkTopologyStrategy) to SimpleStrategy (which is proper for single node) run the following query:

ALTER KEYSPACE yourkeyspaceName WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} ;

Upvotes: 1

LetsNoSQL
LetsNoSQL

Reputation: 1538

It happens some times when the node is down who is having the desired partition ranges for that insert. Please check your all nodes from below commands and try to run query again.

nodetool status

nodetool describecluster.

Upvotes: 0

Aaron
Aaron

Reputation: 57748

Let's clear the air here...

You ABSOLUTELY can use NetworkTopologyStrategy in a single-node configuration. I currently have five versions of Cassandra installed on my local, and they are all configured that way, and they work just fine.

Albeit, it is not as simple as just using SimpleStrategy, so there are some steps that need to be taken:

Start by setting the GossipingPropertyFileSnitch in the cassandra.yaml:

endpoint_snitch: GossipingPropertyFileSnitch

That tells Cassandra to use the cassandra-rackdc.properties file to name logical data centers and racks:

$ cat conf/cassandra-rackdc.properties | grep -v "#"

dc=dc1
rack=rack1

If you have a new cluster, you can change those. If you have an existing cluster, leaving them is the best idea. But you'll want to reference the dc name, because you'll need that in your keyspace definition.

Now, if you define your keyspace like this:

CREATE KEYSPACE stackoverflow WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': '1'};

With this configuration, NetworkTopologyStrategy can be used just fine.

Opinions will differ on this, but I do not recommend using SimpleStrategy. It's a good idea to practice getting used to using NetworkTopologyStrategy on your local. I say this, because I have seen the opposite happen: folks accidentally deploy a SimpleStrategy keyspace into a MDHA cluster in production, and then wonder why their configured application consistency cannot be met.

Upvotes: 1

sujithkrishnan
sujithkrishnan

Reputation: 71

For me, it happened as one of the instance went down. Restarted the second instance and error gone. But in the schema table, I am seeing the Topology as Simple for my keyspace. That is confusing.

Upvotes: 0

Shuo
Shuo

Reputation: 8927

Just met same problem. check the keyspace's replication setting, if using NetworkTopologyStrategy, ensure the dc name is correct.

Upvotes: 3

doubleB
doubleB

Reputation: 348

OK. I've found the answer. The NetworkTopologyStrategy is not suited for running on a single node. After changing replication strategy on SimpleStrategy everything started to work.

Upvotes: 7

Related Questions