[英]NoNodeAvailableException: No node was available to execute the query
I am not using Elasticssearch.我没有使用 Elasticssearch。 I am trying to perform some database operations in cassandra using CQL.我正在尝试使用 CQL 在 cassandra 中执行一些数据库操作。 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.在运行代码时,一段时间后我总是在线程中遇到异常:com.datastax.oss.driver.api.core.NoNodeAvailableException:没有节点可用于执行查询。
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.我在 AWS 上运行 cassandra 3.11.4。 All my nodes are up and running and I can perform operations finely in the backend.我的所有节点都已启动并正在运行,我可以在后端很好地执行操作。
Change .withLocalDatacenter("us-east-2")
to .withLocalDatacenter("datacenter1")
and retry. .withLocalDatacenter("us-east-2")
更改为.withLocalDatacenter("datacenter1")
试。
You can execute nodetool status in cassandra and you will obtain the name of the Datacenter.您可以在 cassandra 中执行 nodetool status ,您将获得数据中心的名称。 That is the value that you must put in withLocalDatacenter
method:这是您必须在withLocalDatacenter
方法中输入的值:
/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
When running in local, better to run nodetool status command get the dc name and use in application while connecting to Cassandra instance.在本地运行时,最好在连接到 Cassandra 实例时运行 nodetool status 命令获取 dc 名称并在应用程序中使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.