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;
});
}
}
}
Aggregations