DZone
Database Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Database Zone > Apache Phoenix Setting Trace On and Off

Apache Phoenix Setting Trace On and Off

Here is a brief how-to of setting trace on and trace off in Apache Phoenix.

Ayola Jayamaha user avatar by
Ayola Jayamaha
·
Jun. 29, 16 · Database Zone · Tutorial
Like (2)
Save
Tweet
2.20K Views

Join the DZone community and get the full member experience.

Join For Free

Apache Phoenix is a SQL layer on top of HBase. Writing tracing information to tracing table "SYSTEM.TRACING_STATS" is optional and can be manipulated through the query statements "trace on" and "trace off."

The following code sample sets "trace on", executes few SQL query statements, and sets "trace off."

try {

    Connection con = DriverManager.getConnection("jdbc:phoenix:"+PHOENIX_HOST+":"+PHOENIX_PORT);
    Statement statement = con.createStatement();
    ResultSet rs = statement.executeQuery("TRACE ON");
    statement.executeUpdate("INSERT into books values (1, Little Women)";
    statement.executeUpdate("DELETE * from books where index = 3");
    statement.executeUpdate("DROP table books");
    rs = statement.executeQuery("TRACE OFF"); 
    con.close();

    } 
catch (Exception ex) {
    System.out.println(ex.getMessage());
    }


When "trace on" and "trace off" are executed the relevant trace_id for the entire trace is returned. It can be retrieved from the ResultSet.

ResultSet rs =statement.executeQuery("TRACE ON");
while (rs.next()) {
    traceId = rs.getString("trace_id");
    }


 Also, the particular trace_id for the trace can be retrieved from the following code snippet.

PhoenixConnection pconn = (PhoenixConnection) con;
long traceId = pconn.getTraceScope().getSpan().getTraceId();


The trace_id we get from all these three methods is written to the tracing table with a small delay. Therefore we need to query the tracing table for the particular trace_id appropriately.

The query statements,

statement.executeUpdate("INSERT into books values (1, Little Women)";
statement.executeUpdate("DELETE * from books where index = 3");
statement.executeUpdate("DROP table books");

can be replaced by any other query statements as preferred by the user to be executed between "trace on" and "trace off". All these queries belong to a single trace identified by a unique trace_id. But these queires may fork into multiple spans.

Apache Phoenix

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Test JavaScript Code in a Browser
  • 7 Traits of an Effective Software Asset Manager
  • Choosing Between GraphQL Vs REST
  • Synchronization Methods for Many-To-Many Associations

Comments

Database Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo