Java 类com.datastax.driver.core.QueryTrace 实例源码

项目:cassandra-probe    文件:TestCQLQueryProbe.java   
public void logExecutionInfo(String prefix, ExecutionInfo executionInfo) {
    if (executionInfo != null) {
        StringBuilder msg = new StringBuilder("\n" + prefix);
        msg.append(String.format("\nHost (queried): %s\n", executionInfo.getQueriedHost().toString()));

        for (Host host : executionInfo.getTriedHosts()) {
            msg.append(String.format("Host (tried): %s\n", host.toString()));
        }

        QueryTrace queryTrace = executionInfo.getQueryTrace();
        if (queryTrace != null) {
            msg.append(String.format("Trace id: %s\n\n", queryTrace.getTraceId()));
            msg.append(String.format("%-80s | %-12s | %-20s | %-12s\n", "activity", "timestamp", "source", "source_elapsed"));
            msg.append(String.format("---------------------------------------------------------------------------------+--------------+----------------------+--------------\n"));
            for (QueryTrace.Event event : queryTrace.getEvents()) {
                msg.append(String.format("%80s | %12s | %20s | %12s\n", event.getDescription(), format.format(event.getTimestamp()), event.getSource(), event.getSourceElapsedMicros()));
            }
            LOG.info(msg.toString());
        } else {
            LOG.warn("Query Trace is null\n" + msg);
        }
    } else {
        LOG.warn("Null execution info");
    }
}
项目:hecuba    文件:DataStaxBasedSharedHecubaClientManager.java   
private void write(String query, Object... values) {
    logger.debug("query = {} : values = {}", query, values);
    PreparedStatement stmt = writeStatementCache.getUnchecked(query);

    BoundStatement bind = stmt.bind(values);
    ResultSet rs = session.execute(bind);

    ExecutionInfo executionInfo = rs.getExecutionInfo();
    Host queriedHost = executionInfo.getQueriedHost();
    logger.debug("queried host = {}", queriedHost);

    if (tracingEnabled) {
        QueryTrace queryTrace = executionInfo.getQueryTrace();
        if (queryTrace != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("{}", toString(queryTrace));
            }
        }
    }
}
项目:hecuba    文件:DataStaxBasedSharedHecubaClientManager.java   
private String toString(QueryTrace queryTrace) {
    StringBuilder builder = new StringBuilder();

    builder.append("Trace id: ").append(queryTrace.getTraceId());
    builder.append(String.format("%-38s | %-12s | %-10s | %-12s\n", "activity", "timestamp", "source",
            "source_elapsed"));
    builder.append("---------------------------------------+--------------+------------+--------------");

    for (QueryTrace.Event event : queryTrace.getEvents()) {
        builder.append(String.format("%38s | %12s | %10s | %12s\n", event.getDescription(),
                DATE_FORMATTER.print(event.getTimestamp()), event.getSource(),
                event.getSourceElapsedMicros()));
    }

    return builder.toString();
}
项目:cassandra-health-check    文件:CassandraHealthCheck.java   
public int healthCheck() {
    final Statement health = QueryBuilder.select().all().from(HEALTHCHECK_KEYSPACE_NAME, "healthcheck")
            .where(eq("healthkey", "healthy"));
    health.setConsistencyLevel(ConsistencyLevel.ALL);
    health.enableTracing();
    QueryTrace queryTrace;
    cluster.register(new LoggingLatencyTracker());
    try {
        final ResultSet results = session.execute(health);
        final ExecutionInfo executionInfo = results.getExecutionInfo();
        queryTrace = executionInfo.getQueryTrace();
    } catch (NoHostAvailableException e) {
        LOG.error("No hosts available", e);
        return 2;
    }
    if (retryPolicy.getLastDecision() != null) {
        LOG.warn("Could not query all hosts");
        if (queryTrace != null) {
            final Set<InetAddress> missingHosts = new HashSet<>(hosts.size());
            for (Host host : hosts) {
                missingHosts.add(host.getSocketAddress().getAddress());
            }
            for (QueryTrace.Event event : queryTrace.getEvents()) {
                missingHosts.remove(event.getSource());
                LOG.debug("description={} elapsed={} source={} micros={}",
                        event.getDescription(),
                        millis2Date(event.getTimestamp()),
                        event.getSource(),
                        event.getSourceElapsedMicros());
            }
            if (!missingHosts.isEmpty()) {
                LOG.error("Missing log entries from these hosts: {}", missingHosts);
            }
        }
        return 1;
    }
    return 0;
}
项目:Simba    文件:CassandraHandler.java   
public ResultSet getRowWithTracing(String keyspace, String table,
        String key, ConsistencyLevel level) {

    Query select = QueryBuilder.select().all().from(keyspace, table)
            .where(QueryBuilder.eq(KEY, key)).setConsistencyLevel(level)
            .enableTracing();

    ResultSet results = session.execute(select);
    ExecutionInfo executionInfo = results.getExecutionInfo();
    System.out.printf("Host (queried): %s\n", executionInfo
            .getQueriedHost().toString());
    for (Host host : executionInfo.getTriedHosts()) {
        System.out.printf("Host (tried): %s\n", host.toString());
    }
    QueryTrace queryTrace = executionInfo.getQueryTrace();
    System.out.printf("Trace id: %s\n\n", queryTrace.getTraceId());
    System.out.printf("%-38s | %-12s | %-10s | %-12s\n", "activity",
            "timestamp", "source", "source_elapsed");
    System.out
            .println("---------------------------------------+--------------+------------+--------------");
    for (QueryTrace.Event event : queryTrace.getEvents()) {
        System.out.printf("%38s | %12s | %10s | %12s\n",
                event.getDescription(), new Date(event.getTimestamp()),
                event.getSource(), event.getSourceElapsedMicros());
    }
    select.disableTracing();
    return results;
}
项目:hecuba    文件:DataStaxBasedSharedHecubaClientManager.java   
private CassandraResultSet<K, String> read(String query, DataType keyType, DataType columnType,
        Map<String, DataType> valueTypes, Object... values) {
    logger.debug("query = {} : values = {}", query, values);
    PreparedStatement stmt = readStatementCache.getUnchecked(query);

    BoundStatement bind = stmt.bind(values);

    if (statementFetchSize > 0) {
        bind.setFetchSize(statementFetchSize);
    } else {
        bind.setFetchSize(Integer.MAX_VALUE);
    }

    long startTimeNanos = System.nanoTime();
    ResultSet rs = session.execute(bind);
    long durationNanos = System.nanoTime() - startTimeNanos;

    ExecutionInfo executionInfo = rs.getExecutionInfo();
    Host queriedHost = executionInfo.getQueriedHost();
    logger.debug("queried host = {}", queriedHost);

    if (tracingEnabled) {
        QueryTrace queryTrace = executionInfo.getQueryTrace();
        if (queryTrace != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("{}", toString(queryTrace));
            }
        }
    }

    return new DataStaxCassandraResultSet<K>(rs, ObjectUtils.defaultIfNull(keyType, this.keyType),
            columnType, valueTypes, durationNanos);
}
项目:Simba    文件:CassandraHandler.java   
public void putRowWithTracing(String keyspace, String tableName,
        String rowKey, Integer version, List<ColumnData> values,
        ConsistencyLevel level) {

    StringBuilder command = new StringBuilder();
    StringBuilder vals = new StringBuilder();

    command.append("INSERT INTO ")
            .append((keyspace == null) ? keyspaceName : keyspace)
            .append(".").append(tableName).append(" (").append(KEY)
            .append(",").append(VERSION).append(",").append(DELETED)
            .append(",");

    ColumnData pair = values.get(0);
    command.append(pair.getColumn());
    vals.append(pair.getValue());

    for (int i = 1; i < values.size(); i++) {
        pair = values.get(i);
        command.append(",").append(pair.getColumn());
        vals.append(",").append(pair.getValue());
    }

    command.append(") VALUES (").append("'" + rowKey + "',")
            .append(version + ",").append("false,").append(vals.toString())
            .append(");");
    LOG.debug(command.toString());

    SimpleStatement ss = new SimpleStatement(command.toString());
    Query insert = QueryBuilder.batch(ss).setConsistencyLevel(level)
            .enableTracing();

    ResultSet results = session.execute(insert);
    ExecutionInfo executionInfo = results.getExecutionInfo();
    System.out.printf("Host (queried): %s\n", executionInfo
            .getQueriedHost().toString());
    for (Host host : executionInfo.getTriedHosts()) {
        System.out.printf("Host (tried): %s\n", host.toString());
    }
    QueryTrace queryTrace = executionInfo.getQueryTrace();
    System.out.printf("Trace id: %s\n\n", queryTrace.getTraceId());
    System.out.printf("%-38s | %-12s | %-10s | %-12s\n", "activity",
            "timestamp", "source", "source_elapsed");
    System.out
            .println("---------------------------------------+--------------+------------+--------------");
    for (QueryTrace.Event event : queryTrace.getEvents()) {
        System.out.printf("%38s | %12s | %10s | %12s\n",
                event.getDescription(), new Date(event.getTimestamp()),
                event.getSource(), event.getSourceElapsedMicros());
    }
    insert.disableTracing();

}