Search in sources :

Example 6 with TraceHolder

use of org.apache.phoenix.trace.TraceReader.TraceHolder in project phoenix by apache.

the class PhoenixTracingEndToEndIT method testClientServerIndexingTracing.

/**
     * Test that span will actually go into the this sink and be written on both side of the wire,
     * through the indexing code.
     * @throws Exception
     */
@Test
public void testClientServerIndexingTracing() throws Exception {
    // one call for client side, one call for server side
    latch = new CountDownLatch(2);
    testTraceWriter = new TestTraceWriter(tracingTableName, defaultTracingThreadPoolForTest, defaultTracingBatchSizeForTest);
    // separate connection so we don't create extra traces
    Connection conn = getConnectionWithoutTracing();
    createTestTable(conn, true);
    // trace the requests we send
    Connection traceable = getTracingConnection();
    LOG.debug("Doing dummy the writes to the tracked table");
    String insert = "UPSERT INTO " + enabledForLoggingTable + " VALUES (?, ?)";
    PreparedStatement stmt = traceable.prepareStatement(insert);
    stmt.setString(1, "key1");
    stmt.setLong(2, 1);
    // this first trace just does a simple open/close of the span. Its not doing anything
    // terribly interesting because we aren't auto-committing on the connection, so it just
    // updates the mutation state and returns.
    stmt.execute();
    stmt.setString(1, "key2");
    stmt.setLong(2, 2);
    stmt.execute();
    traceable.commit();
    // wait for the latch to countdown, as the metrics system is time-based
    LOG.debug("Waiting for latch to complete!");
    // should be way more than GC pauses
    latch.await(200, TimeUnit.SECONDS);
    // read the traces back out
    /* Expected:
         * 1. Single element trace - for first PreparedStatement#execute span
         * 2. Two element trace for second PreparedStatement#execute span
         *  a. execute call
         *  b. metadata lookup*
         * 3. Commit trace.
         *  a. Committing to tables
         *    i. Committing to single table
         *    ii. hbase batch write*
         *    i.I. span on server
         *    i.II. building index updates
         *    i.III. waiting for latch
         * where '*' is a generically named thread (e.g phoenix-1-thread-X)
         */
    boolean indexingCompleted = checkStoredTraces(conn, new TraceChecker() {

        @Override
        public boolean foundTrace(TraceHolder trace, SpanInfo span) {
            String traceInfo = trace.toString();
            // skip logging traces that are just traces about tracing
            if (traceInfo.contains(tracingTableName)) {
                return false;
            }
            return traceInfo.contains("Completing index");
        }
    });
    assertTrue("Never found indexing updates", indexingCompleted);
}
Also used : TraceHolder(org.apache.phoenix.trace.TraceReader.TraceHolder) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) PreparedStatement(java.sql.PreparedStatement) SpanInfo(org.apache.phoenix.trace.TraceReader.SpanInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

TraceHolder (org.apache.phoenix.trace.TraceReader.TraceHolder)6 Connection (java.sql.Connection)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Test (org.junit.Test)5 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)4 PreparedStatement (java.sql.PreparedStatement)3 SpanInfo (org.apache.phoenix.trace.TraceReader.SpanInfo)3 ResultSet (java.sql.ResultSet)2 Span (org.apache.htrace.Span)2 TraceScope (org.apache.htrace.TraceScope)1