Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

nyjdams_136971 avatar image
nyjdams_136971 asked ·

Getting "NoHostAvailable" in exercise 14 of DS201 Academy course

I've recently redone all the exercises 1-13 in DS201, being very careful to follow the instructions exactly.

So I get to exercise 14, where it says to bring down both the nodes responsible for the 'cassandra' partition. So I run this:

/home/ubuntu/node1/resources/cassandra/bin/nodetool getendpoints killrvideo videos_by_tag 'cassandra'
127.0.0.2
127.0.0.3

So I bring them both down using 'stopdaemon'. Immediately, I run 'nodetool status':

ubuntu@ds201-node1:~$ node1/bin/nodetool status
Datacenter: east-side
=====================
Status=Up/Down|/ State=Normal/Leaving/Joining/Moving--  Address    Load       Tokens       Owns    Host ID                               Rack
DN  127.0.0.2  288.53 KiB  128          ?       a3555477-06e2-47fa-b209-e19c753d4cf4  hakuna-matata
Datacenter: west-side
=====================
Status=Up/Down|/ State=Normal/Leaving/Joining/Moving--  Address    Load       Tokens       Owns    Host ID                               Rack
UN  127.0.0.1  274.19 KiB  128          ?       8c3a4a55-5b38-42ba-8234-e9d588e56b80  hakuna-matata
DN  127.0.0.3  241.59 KiB  128          ?       b396b07e-dde0-4f4c-8de7-e79d6d360c79  hakuna-matataNote: 
Non-system keyspaces don't have the same replication settings, effective ownership information is meaningless

Both nodes are down.

Then the exercise says to insert a new row after setting 'consistency any':

cqlsh> consistency any;
Consistency level set to ANY.
cqlsh> use killrvideo;
NoHostAvailable: 
cqlsh> INSERT INTO killrvideo.videos_by_tag(tag, added_date, video_id, title) VALUES ('cassandra', '2016-2-11', uuid(), 'Cassandra, Take Me Home');
NoHostAvailable: 
cqlsh> 

The exercise says 'the write will succeed' - but it clearly doesn't. And there are no hints under any of the nodes.


What have I done wrong?

cassandraacademy
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Erick Ramirez avatar image
Erick Ramirez answered ·

@nyjdams_136971 It sounds like you were connected to a node which is now down. If I were to guess, it would most likely be node 127.0.0.2:

DN  127.0.0.2  288.53 KiB  128          ?       a3555477-06e2-47fa-b209-e19c753d4cf4  hakuna-matata

The default CQL port for client connections (cqlsh is just another client) is 9042. In the VM image for DS201, each DSE node is configured to listen on different ports:

$ for _node in node*; do echo "$_node - `grep ^native_transport_port $_node/resources/cassandra/conf/cassandra.yaml`"; done
node1 - native_transport_port: 9041
node2 - native_transport_port: 9042
node3 - native_transport_port: 9043

Since only node 127.0.0.1 is up, you need to connect with cqlsh on port 9041 by running:

$ cd node1
$ bin/cqlsh 127.0.0.1 9041

Once you're connected, you should be able to complete exercise 14. Cheers!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

bhisey.swapnil avatar image
bhisey.swapnil answered ·

Hi,

In the situation where the cqlsh is not able to establish a connection to the Cassandra node, either at startup or at a later point in time, the cqlsh will throw a NoHostAvailableException.

As of message printed in cqlsh as NoHostAvailableException , Please make sure you are connecting to a node which is UN (UP/NORMAL) in your case that is 127.0.0.1 and insert a record. As you are using "Consistency ANY", you write should succeed once you connect to 127.0.0.1.

Once you build an application you should be able to add multiple contact points which you can configure through the driver. Contact points are addresses of Cassandra nodes that the driver uses to discover the cluster topology. Only one contact point is required (the driver will retrieve the address of the other nodes automatically), but if the single contact point is unavailable, the driver cannot initialize itself correctly.

You can read about the driver here.


Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.