Home > Enterprise >  Datastax Cassandra NoNodeAvailableException when multithreading
Datastax Cassandra NoNodeAvailableException when multithreading

Time:02-24

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

CodePudding user response:

JsonInsert query = insertInto("links").json(json.toString());

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.

  • Related