wittyameta
wittyameta

Reputation: 395

Cassandra error during read - NoHostAvailableException: All host(s) tried for query failed (no host was tried)

I looked at this and this, but couldn't find any solution.

I'm getting 'no host was tried' error only during read query. Writing to cassandra works fine. I'm using datastax cassandra java driver - 3.3.0.

I am trying the following read query as 'health-check':

SELECT * from counter_table;

Some code snippet which creates the Cluster:

Cluster cluster = Cluster.builder()
    .addContactPointsWithPorts(convertToInternetAddress())
    .withAuthProvider(authProvider)
    .withPoolingOptions(poolingOptions)
    .withRetryPolicy(cassandraRetryPolicy)
    .build();

Edit 1: I've updated the sample query which gives this error for the 1st time. I'm querying a table with counter fields without giving any partition key. However, there are only 5 records in the table

Edit 2: Decreasing the cluster pool timeout seems to have fixed it. Any idea why?

Upvotes: 1

Views: 572

Answers (1)

wittyameta
wittyameta

Reputation: 395

I figured it out eventually. I was using multiple sessions, and one of the sessions was getting closed. The queries using the closed session were giving this error.

Upvotes: 1

Related Questions