Book Image

Apache Cassandra Essentials

By : Nitin Padalia
Book Image

Apache Cassandra Essentials

By: Nitin Padalia

Overview of this book

Apache Cassandra Essentials takes you step-by-step from from the basics of installation to advanced installation options and database design techniques. It gives you all the information you need to effectively design a well distributed and high performance database. You’ll get to know about the steps that are performed by a Cassandra node when you execute a read/write query, which is essential to properly maintain of a Cassandra cluster and to debug any issues. Next, you’ll discover how to integrate a Cassandra driver in your applications and perform read/write operations. Finally, you’ll learn about the various tools provided by Cassandra for serviceability aspects such as logging, metrics, backup, and recovery.
Table of Contents (14 chapters)
Apache Cassandra Essentials
About the Author
About the Reviewers

Tracing Cassandra queries using Java driver

We discussed tracing in the previous chapter, so you know how we can trace a query using the cqlsh client. Similarly, we can enable tracing on a per-query basis using driver as well. The following code shows a new version of our createStatus() method, with tracing enabled:

public void traceCreateStatus(String userId, String statusMsg) {
    Statement insertStatement = QueryBuilder
        .insertInto("apachecassandra", "status_updates_by_user")
        .value("userid", UUID.fromString(userId))
        .value("updated_on", System.currentTimeMillis())
        .value("status", statusMsg)
    ResultSet rs = getSession().execute(insertStatement);
    ExecutionInfo executionInfo = rs.getExecutionInfo();
    QueryTrace queryTrace = executionInfo.getQueryTrace();
      System.out.println("Trace id: " + queryTrace.getTraceId());
      for (QueryTrace.Event event : queryTrace.getEvents()) {
        System.out.printf("%120s | %12s...