Node specified with setNode() method forwards read request to other nodes

79 Views Asked by At

I am trying to read data present in a specific cassandra (4) node, using Datastax driver version 4.13. I have read this post, which supposedly works for driver versions 3.x

I have modified my code as best I can for driver version 4.x. The operative part of the code looks like

BoundStatement bs= psGetAllOptimizedModule.bind(imei,year,month,startDate,endDate)
            .setTracing(true)
            .setNode(localNode).setConsistencyLevel(ConsistencyLevel.LOCAL_ONE).setPageSize(pageSize);
    Instant start=Instant.now();
    ResultSet rs = session.execute(bs);

While the query is indeed directed to the specified node, the node then is sometimes forwarding requests to other nodes, even though the data is present on the specified node.

I wanted to check if this is at all possible in cassandra, and if so, what I need to do differently.

Update: As requested, the information asked for has been added to a pastebin here, as its too long to add to the question.

1

There are 1 best solutions below

9
Erick Ramirez On

The Statement.setNode() API does in fact restrict the request such that the driver will ignore the load balancing policy and only execute the statement on the specified node.

However, the symptom you described indicates to me that the query cannot be satisfied by just one node so it has to request data from other replicas despite setting the consistency to LOCAL_ONE.

In fact the name psGetAllOptimizedModule suggests to me that you are trying to retrieve more than just one record so it makes sense that the coordinating node needs to request the data from other nodes.

You can easily confirm that this is the case by running the query locally on the Cassandra node with tracing enabled and consistency set to LOCAL_ONE. Cheers!