0

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 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

9 Comments

I am indeed trying to get multiple records from a single partition. The table is incrementally repaired every day. That aside,tracing is enabled, and querying node1 is sometimes answered by node 1, sometimes by node 2 & 3. Similarly, querying node2 results in querying node 2 sometimes, but also node 1 & node 3. Isn't local_one supposed to prevent cross-node queries? Even if the query can't be satisfied by a particular node, it should return an empty set - thats my desired behaviour. As mentioned in the qestion, the only effect of setNode() is to always initially query the desired node.
I have tried to run the query from the cqlsh terminal by turning tracing on, and setting consistency level to local_one. But the session still sometimes hits other nodes, and sometimes it doesn't.
One other question - will changing the load balancing policy help? I'm finding it difficult to find documentation/examples which tells me how I can change/set Load Balancign Policy in DataStax 4.x.
"But the session still sometimes hits other nodes, and sometimes it doesn't." Like I said, the coordinator has to query other nodes other than "local" because the requested data isn't available on the local node. Cheers!
How can the exact same data sometimes be available from the local node, and sometimes not? I am happy to share the trace logs.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.