7

I just finished creating my table in cassandra. I attempted to insert data into the table and I was given this error:

cqlsh:test> INSERT into qw (id, user, pass, email, phoneNum) VALUES (1,  'scman', '123','sc@gmaail.com','123-456-7890');
NoHostAvailable:

I checked that my server was running. What could be causing this problem.

Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161
Connor Myers
  • 111
  • 1
  • 1
  • 7
  • How many nodes are in your cluster? And what RF did you set in your keyspace? If you are using NetworkTopologyStrategy, make sure to use the same data center name that appears in `nodetool status`. – Aaron Dec 29 '16 at 04:54

2 Answers2

11

This is too late to answer. But I wanted to share my experience.

If you have a single node cluster and use NetworkTopologyStrategy, then it throws this error. Check your keyspace configuration.

Error during inserting data: NoHostAvailable:

Community
  • 1
  • 1
Chaity
  • 1,348
  • 13
  • 20
  • 1
    "If you have a single node cluster and use NetworkTopologyStrategy, then it throws this error." This is generalization not correct: https://stackoverflow.com/questions/39904798/error-during-inserting-data-nohostavailable/62266053#62266053 – Aaron Jun 08 '20 at 15:55
2

My CQL command to update the replication

ALTER KEYSPACE my_keyspace WITH replication = {'class' : 'NetworkTopologyStrategy', 'DC1' : 1 ,'DC2' :2 };

was slightly different from the config files : conf/cassandra-rackdc.properties

# These properties are used with GossipingPropertyFileSnitch and will
# indicate the rack and dc for this node
dc=dc1
rack=rack1

resulting in a

cqlsh: my_keyspace> select * from world where message_id = 'hello_world';

NoHostAvailable:

the replication strategy is case sensitive and copy/paste from documentation may lead you to a mistake.

Fix : Changing the replication info so that it match the config files

ALTER KEYSPACE my_keyspace WITH replication = {'class' : 'NetworkTopologyStrategy', 'dc1' : 1 ,'dc2' :2 };

And execute on each node :

bin/nodetool repair --full my_keyspace

Got replication set on every node

A.HEDDAR
  • 299
  • 2
  • 4