vfsoraki
vfsoraki

Reputation: 2307

Cassandra NoHostsAvailable error in cqlsh

I am running Cassandra 3.11 on two nodes. This is the keyspace:

CREATE KEYSPACE backend_platform_dev 
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}  AND durable_writes = true;

I have two nodes, running on VMs on my machine. When both nodes are up, everything is working. But when I take down one node, my application (elixir) starts throwing errors, as well as cqlsh (NoHostAvailable or InvalidRequest: Error from server: code=2200 [Invalid query] message="unconfigured table test").

I have searched error, and everyone had the problem of setting NetworkTopologyStrategy for a single node, but that's not my case.

What is happening here?

Edit: This is the error the driver is giving:

[unavailable] Cannot achieve consistency level ONE: %{alive: 0, consistency: :one, required: 1}

I'm sure one node is alive, one is down. Using cqlsh from my local system to connect to the Cassandra node confirms this. I'm more confused now.

Upvotes: 1

Views: 1389

Answers (1)

dilsingi
dilsingi

Reputation: 2958

The problem is with "replication_factor" being configured as 1. So there is only one copy of data. Say you are storing 10 records, then each node supposedly gets its share of records and for simplicity lets say first 5 records is stored in node1 and second 5 records is stored in node2. Now when you take down node1 and look for the first record, you will be end up with the driver error as reported, as no node is available to serve up that record.

  • Change the replication_factor to 2 minimum since there are only two nodes situation here. Recommended RF=3 for PROD.
  • Run NODETOOL REPAIR, for the records in that table to become two copies. Any future inserts will automatically be two copies, but this is to fix the existing records.
  • The consistency level of READ query is by default ONE which will succeed even in case of node failure.

SimleStrategy should work fine for Single DataCenter scenario. Still the recommended configuration for PROD is NetworkTopology Strategy.

Upvotes: 1

Related Questions