【发布时间】:2017-05-30 13:57:19
【问题描述】:
我正在尝试使用 java 驱动程序测量 Cassandra 中查询的服务器端查询执行时间。我正在使用rSet.getExecutionInfo().getQueryTrace().getDurationMicros(),其中 rSet 是我正在执行的查询的结果集。我使用 cqlsh 手动打开了跟踪,并且能够通过 cqlsh 获取跟踪,但是当我使用 java 驱动程序尝试它时得到一个空值。在使用 java 驱动程序时我还应该做些什么来启用跟踪?
编辑
添加用于查询和连接集群的代码。
我用来查询和测量服务器端执行时间的代码sn-p
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());
我用来连接 Cassandra 集群的代码
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();
}
【问题讨论】:
-
我们将需要更多的东西,比如确定问题的部分代码。就目前而言,我可以告诉你的是,某处有一个空值,它不是很有帮助......
-
用代码编辑了问题。
-
谢谢,stacktrace 指向了上面代码的哪一行,因为我真的看不到任何明显的东西:(
-
第二行,rSet.getExecutionInfo().getQueryTrace()).getDurationMicros()返回的值为null。因此,当我尝试打印该值时出现空指针错误。
-
虽然我对 casandra 没有任何经验,但阅读文档:
getQueryTrace() returns the QueryTrace object for this query if tracing was enable for this query, or null otherwise.这可能是您获得 NPE 的原因吗?