1
votes

I'm trying to measure the server side query execution time for a query in Cassandra using the java driver. I'm using rSet.getExecutionInfo().getQueryTrace().getDurationMicros() where rSet is the result set for the query I'm executing. I manually turned on tracing using cqlsh and was able to get the trace through cqlsh but I get a null value when I try it with the java driver. Is there something else I should be doing to enable tracing while using the java driver?

EDIT

Adding code used to query and connect to the cluster.

The code snippet I use to query and measure server side execution time

ResultSet rSet = session.execute("SELECT * from quelea.users where user_id = " + userId +" ALLOW Filtering");
System.out.println("Server-side query Execution time : " + rSet.getExecutionInfo().getQueryTrace()).getDurationMicros());

The code I use to connect to the Cassandra cluster

public void connect(final String node, final int port)  
   {  
      this.cluster = Cluster.builder().addContactPoint(node).withPort(port).build();  
      final Metadata metadata = cluster.getMetadata();  
      out.printf("Connected to cluster: %s\n", metadata.getClusterName());  
      for (final Host host : metadata.getAllHosts())  
      {  
         out.printf("Datacenter: %s; Host: %s; Rack: %s\n",  
            host.getDatacenter(), host.getAddress(), host.getRack());  
      }  
      session = cluster.connect();  
   }  
1
We are going to need a litle more than that, like part of your code to determine the issue. As this stands all i can tell you is that somewhere there is a null value which is not teribly helpful... - fill͡pant͡
Edited the question with the code. - Kapil
Thanks, which line of the code above does the stacktrace point to because i can't really see anything obvious :( - fill͡pant͡
The second line, the value returned by rSet.getExecutionInfo().getQueryTrace()).getDurationMicros() is null. So I'm getting a null pointer error when I'm trying to print out the value. - Kapil
Although i haven't really had any experience in with casandra, reading the docs: getQueryTrace() returns the QueryTrace object for this query if tracing was enable for this query, or null otherwise. could this be the reason you get a NPE? - fill͡pant͡

1 Answers

2
votes

Based on your provided code:

ResultSet rSet = session.execute("SELECT * from quelea.users where user_id = " + userId +" ALLOW Filtering");

It appears that you are not enabling tracing, which is why getQueryTrace() returns null, thus why getDurationMicros() throws a NullPointerException. (Note: when using TRACING on; in cqlsh, it only applies to your cqlsh session, not globally).

To enable tracing you can use enableTracing(), i.e.:

Statement statement = new SimpleStatement("SELECT * from quelea.users where user_id = " + userId +" ALLOW Filtering").enableTracing();
ResultSet rSet = session.execute(statement);