The Linux Page

Unable to complete the operation against any hosts — from Cassandra

Today I was testing a new intsallation that I prepared in the last month or so and once I hit Cassandra, I got this strange message:

   NoHostAvailable: ('Unable to complete the operation against any hosts',
   {<Host: dc1>: Unavailable('Error from server: code=1000
   [Unavailable exception] message="Cannot achieve consistency level ONE"
   info={\'required_replicas\': 1, \'alive_replicas\': 0, \'consistency\': \'ONE\'}',)})

I looked for a solution with Google but was not really able to find anything that would explain that error.

Obviously, it is telling us that here is a need for at least 1 replica and right now that Cassandra cannot find any (alive_replicas is zero!)

Now, how come I can connect to Cassandra, the very one I am trying to access, the very one that tells me that there is no replicas. Is there something I do not understand here?

In this case it is a test with a single node, so you would think that it is indeed always going to work...

So... going back to the setup, I looked at my keyspace definition an I see:

    CREATE KEYSPACE snap_websites
           WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1': '1'}
           AND durable_writes = true;

So I'm all happy about it. After all, it looks good.

Then I wonder, could it be that somehow I need to define what DC1 actually is? I have dealt with something called a topology before and maybe that's it. I read the cassandra.yaml setup file and find out that the topology is indeed used by default, because the default snitch is GossipingPropertyFileSnitch.

    endpoint_snitch: GossipingPropertyFileSnitch

Great. So I'm making progress. I now look inside that topology file and I see two fields:


Am I am thinking, well... it also says DC1, doesn't it?

So I decide to search about data center and case sensitivity. It is case sensitive! So "dc1" != "DC1"... Changing the KEYSPACE with "dc1" and the database started to work as expected.

    ALTER KEYSPACE snap_websites
           WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': '1'}
           AND durable_writes = true;

(Note: it is not unlikely that you will get a timeout error on this sort of change. If that happens, try the DESCRIBE KEYSPACE snap_websites to verify that it took as expected.)