SDt
SDt

Reputation: 482

NoNodeAvailableException: No node was available to execute the query

I am not using Elasticssearch. I am trying to perform some database operations in cassandra using CQL. I am using threads. While running the code I am always getting the exception in thread after a while : com.datastax.oss.driver.api.core.NoNodeAvailableException: No node was available to execute the query.

I have tested with even one thread. The error is still there. Here is my code :

InetAddress addrOne = InetAddress.getByName("52.15.195.41");
InetSocketAddress addrSocOne = new InetSocketAddress(addrOne,9042);
CqlSession sessionOne = CqlSession.builder().addContactPoint(addrSocOne).withLocalDatacenter("us-east-2").withKeyspace("test").build();

while(counter <= 100)
{
    String query = "select max(id) FROM samplequeue";
    ResultSet rs = session.execute(query);
    for (Row row : rs) 
    {
        int exS = row.getInt("system.max(id)");
    }
    counter++;
    Thread.sleep(50);
}

This is a very simple, modified example just to demonstrate the problem. I am unable to resolve it. All the threads are exiting giving the same exception. I am running cassandra 3.11.4 on AWS. All my nodes are up and running and I can perform operations finely in the backend.

Upvotes: 19

Views: 29843

Answers (3)

PraveenKumar K G
PraveenKumar K G

Reputation: 186

When running in local, better to run nodetool status command get the dc name and use in application while connecting to Cassandra instance.

Upvotes: 0

Ceci G J
Ceci G J

Reputation: 181

You can execute nodetool status in cassandra and you will obtain the name of the Datacenter. That is the value that you must put in withLocalDatacenter method:

/opt/apache-cassandra-3.11.2/bin$ ./nodetool status
Datacenter: **dc1**
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address         Load       Tokens       Owns (effective)  Host ID    Rack

Upvotes: 18

William
William

Reputation: 224

Change .withLocalDatacenter("us-east-2") to .withLocalDatacenter("datacenter1") and retry.

Upvotes: 20

Related Questions