Search in sources :

Example 1 with ExecutionInfo

use of com.datastax.driver.core.ExecutionInfo in project atlasdb by palantir.

the class CqlKeyValueServices method logTracedQuery.

@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
public void logTracedQuery(String tracedQuery, ResultSet resultSet, Session session, LoadingCache<String, PreparedStatement> statementCache) {
    if (log.isInfoEnabled()) {
        List<ExecutionInfo> allExecutionInfo = Lists.newArrayList(resultSet.getAllExecutionInfo());
        for (final ExecutionInfo info : allExecutionInfo) {
            if (info.getQueryTrace() == null) {
                continue;
            }
            final UUID traceId = info.getQueryTrace().getTraceId();
            log.info("Traced query {} with trace uuid {}", tracedQuery, traceId);
            traceRetrievalExec.submit((Callable<Void>) () -> {
                StringBuilder sb = new StringBuilder();
                sb.append("Retrieving traced query " + tracedQuery + " trace uuid: " + traceId);
                int tries = 0;
                boolean success = false;
                while (tries < MAX_TRIES) {
                    ResultSetFuture sessionFuture = session.executeAsync(statementCache.getUnchecked("SELECT * FROM system_traces.sessions WHERE session_id = ?").bind(traceId));
                    Row sessionRow = sessionFuture.getUninterruptibly().one();
                    if (sessionRow != null && !sessionRow.isNull("duration")) {
                        ResultSetFuture eventFuture = session.executeAsync(statementCache.getUnchecked("SELECT * FROM system_traces.events WHERE session_id = ?").bind(traceId));
                        List<Row> eventRows = eventFuture.getUninterruptibly().all();
                        sb.append(" requestType: ").append(sessionRow.getString("request"));
                        sb.append(" coordinator: ").append(sessionRow.getInet("coordinator"));
                        sb.append(" started_at: ").append(sessionRow.getTime("started_at"));
                        sb.append(" duration: ").append(sessionRow.getInt("duration"));
                        if (!sessionRow.isNull("parameters")) {
                            sb.append("\nparameters: " + Collections.unmodifiableMap(sessionRow.getMap("parameters", String.class, String.class)));
                        }
                        for (Row eventRow : eventRows) {
                            sb.append(eventRow.getString("activity")).append(" on ").append(eventRow.getInet("source")).append("[").append(eventRow.getString("thread")).append("] at ").append(eventRow.getUUID("event_id").timestamp()).append(" (").append(eventRow.getInt("source_elapsed")).append(" elapsed)\n");
                        }
                        success = true;
                        break;
                    }
                    tries++;
                    Thread.sleep(TRACE_RETRIEVAL_MS_BETWEEN_TRIES);
                }
                if (!success) {
                    sb.append(" (retrieval timed out)");
                }
                log.info("Query trace: {}", sb);
                return null;
            });
        }
    }
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) ExecutionInfo(com.datastax.driver.core.ExecutionInfo) List(java.util.List) Row(com.datastax.driver.core.Row) UUID(java.util.UUID) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

ExecutionInfo (com.datastax.driver.core.ExecutionInfo)1 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)1 Row (com.datastax.driver.core.Row)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 List (java.util.List)1 UUID (java.util.UUID)1