多线程时 Datastax Cassandra NoNodeAvailableException
我正在尝试用 Java 构建一个多线程 Cassandra 导入器。我正在使用这个包:group: 'com.datastax.cassandra', name: 'cassandra-driver-core', version: '4.0.0'
单线程(使用主线程)工作正常,但即使有 1 个子线程我立即收到com.datastax.oss.driver.api.core.NoNodeAvailableException:没有节点可用于执行查询
我正在Docker中的cassandra实例上测试我的应用程序(希望这不是问题)。这是我的建造者。
session = CqlSession.builder()
.addContactPoint(new InetSocketAddress("localhost", 9042))
.withKeyspace(CqlIdentifier.fromCql("links"))
.withLocalDatacenter("datacenter1")
.build();
这就是我执行查询的方式
JSONObject json = new JSONObject(linksRow);
JsonInsert query = insertInto("links").json(json.toString());
session.execute(query.toString());
你能告诉我我做错了什么吗?根据文档,CqlSession 应该是线程安全的。 (https://docs.datastax.com/en/ developer/java-driver/4.0/manual/core/)
编辑:添加插入查询
I'm trying to build a multithreaded Cassandra importer in Java. I'm using this package:group: 'com.datastax.cassandra', name: 'cassandra-driver-core', version: '4.0.0'
Single threaded (using the main thread) works fine but even with 1 subthread I instantly receive com.datastax.oss.driver.api.core.NoNodeAvailableException: No node was available to execute the query
I'm testing my application on a cassandra instance in Docker (hope this is not the problem). This is the builder I have.
session = CqlSession.builder()
.addContactPoint(new InetSocketAddress("localhost", 9042))
.withKeyspace(CqlIdentifier.fromCql("links"))
.withLocalDatacenter("datacenter1")
.build();
And this is how I execute a query
JSONObject json = new JSONObject(linksRow);
JsonInsert query = insertInto("links").json(json.toString());
session.execute(query.toString());
Could you tell me what I'm doing wrong? The CqlSession should be thread-safe according to the documentation. (https://docs.datastax.com/en/developer/java-driver/4.0/manual/core/)
Edit: Added insert query
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些查询是否在每个线程上不断运行?
本地单个 Cassandra 节点可能没有足够的资源来处理多个请求。这将导致 Cassandra 返回该节点对客户端“不可用”。
Cassandra 的 Java 堆有多大?它可能需要更大。也可能是本地系统在运行 Cassandra、多线程应用程序以及其他可能正在运行的应用程序时发生了太多事情。
基本上,检查
conf/jvm-server.options
的“HEAP SETTINGS”。如果堆是“自动计算的”,则对于应用程序尝试用它执行的操作来说,它可能太小。Are these queries running constantly on each thread?
It could be that the local, single Cassandra node just doesn't have enough resources available to handle multiple requests. That would cause Cassandra to return that the node is "unavailable" to the client.
How large is Cassandra's Java heap? It might need to be bigger. It also might be that the local system just has too much going on with running Cassandra, a multi-threaded app, and whatever else might be running.
Basically, check the "HEAP SETTINGS" of
conf/jvm-server.options
. If the heap is getting "automatically calculated," it's likely too small for what the app is trying to do with it.