use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class CqlRequestHandler method setFinalResult.
private void setFinalResult(Result resultMessage, Frame responseFrame, boolean schemaInAgreement, NodeResponseCallback callback) {
try {
ExecutionInfo executionInfo = buildExecutionInfo(callback, resultMessage, responseFrame, schemaInAgreement);
AsyncResultSet resultSet = Conversions.toResultSet(resultMessage, executionInfo, session, context);
if (result.complete(resultSet)) {
cancelScheduledTasks();
throttler.signalSuccess(this);
// Only call nanoTime() if we're actually going to use it
long completionTimeNanos = NANOTIME_NOT_MEASURED_YET, totalLatencyNanos = NANOTIME_NOT_MEASURED_YET;
if (!(requestTracker instanceof NoopRequestTracker)) {
completionTimeNanos = System.nanoTime();
totalLatencyNanos = completionTimeNanos - startTimeNanos;
long nodeLatencyNanos = completionTimeNanos - callback.nodeStartTimeNanos;
requestTracker.onNodeSuccess(callback.statement, nodeLatencyNanos, callback.executionProfile, callback.node, logPrefix);
requestTracker.onSuccess(callback.statement, totalLatencyNanos, callback.executionProfile, callback.node, logPrefix);
}
if (sessionMetricUpdater.isEnabled(DefaultSessionMetric.CQL_REQUESTS, callback.executionProfile.getName())) {
if (completionTimeNanos == NANOTIME_NOT_MEASURED_YET) {
completionTimeNanos = System.nanoTime();
totalLatencyNanos = completionTimeNanos - startTimeNanos;
}
sessionMetricUpdater.updateTimer(DefaultSessionMetric.CQL_REQUESTS, callback.executionProfile.getName(), totalLatencyNanos, TimeUnit.NANOSECONDS);
}
}
// log the warnings if they have NOT been disabled
if (!executionInfo.getWarnings().isEmpty() && callback.executionProfile.getBoolean(DefaultDriverOption.REQUEST_LOG_WARNINGS) && LOG.isWarnEnabled()) {
logServerWarnings(callback.statement, callback.executionProfile, executionInfo.getWarnings());
}
} catch (Throwable error) {
setFinalError(callback.statement, error, callback.node, -1);
}
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class DefaultReactiveResultSetIT method should_write.
@Test
public void should_write() {
SimpleStatement statement = SimpleStatement.builder("INSERT INTO test_reactive_write (pk, cc, v) VALUES (?, ?, ?)").addPositionalValue(0).addPositionalValue(1).addPositionalValue(2).setExecutionProfile(sessionRule.slowProfile()).build();
ReactiveResultSet rs = sessionRule.session().executeReactive(statement);
List<ReactiveRow> results = Flowable.fromPublisher(rs).toList().blockingGet();
assertThat(results).isEmpty();
List<ExecutionInfo> execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
assertThat(execInfos).hasSize(1);
List<ColumnDefinitions> colDefs = Flowable.<ColumnDefinitions>fromPublisher(rs.getColumnDefinitions()).toList().blockingGet();
assertThat(colDefs).hasSize(1).containsExactly(EmptyColumnDefinitions.INSTANCE);
List<Boolean> wasApplied = Flowable.fromPublisher(rs.wasApplied()).toList().blockingGet();
assertThat(wasApplied).hasSize(1).containsExactly(true);
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class DefaultReactiveResultSetIT method should_write_batch_cas.
@Test
public void should_write_batch_cas() {
BatchStatement batch = createCASBatch();
CqlSession session = sessionRule.session();
// execute batch for the first time: all inserts should succeed and the server should return
// only one acknowledgement row with just the [applied] column = true
ReactiveResultSet rs = session.executeReactive(batch);
List<ReactiveRow> results = Flowable.fromPublisher(rs).toList().blockingGet();
assertThat(results).hasSize(1);
ReactiveRow row = results.get(0);
assertThat(row.getExecutionInfo()).isNotNull();
assertThat(row.getColumnDefinitions()).hasSize(1);
assertThat(row.wasApplied()).isTrue();
assertThat(row.getBoolean("[applied]")).isTrue();
List<ExecutionInfo> execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
assertThat(execInfos).hasSize(1).containsExactly(row.getExecutionInfo());
List<ColumnDefinitions> colDefs = Flowable.<ColumnDefinitions>fromPublisher(rs.getColumnDefinitions()).toList().blockingGet();
assertThat(colDefs).hasSize(1).containsExactly(row.getColumnDefinitions());
List<Boolean> wasApplied = Flowable.fromPublisher(rs.wasApplied()).toList().blockingGet();
assertThat(wasApplied).hasSize(1).containsExactly(row.wasApplied());
// delete 5 out of 10 rows
partiallyDeleteInsertedRows();
// re-execute same statement: server should return 5 rows for the 5 failed inserts, each one
// with [applied] = false
rs = session.executeReactive(batch);
results = Flowable.fromPublisher(rs).toList().blockingGet();
assertThat(results).hasSize(5);
for (int i = 0; i < 5; i++) {
row = results.get(i);
assertThat(row.getExecutionInfo()).isNotNull();
assertThat(row.getColumnDefinitions()).hasSize(4);
assertThat(row.wasApplied()).isFalse();
assertThat(row.getBoolean("[applied]")).isFalse();
assertThat(row.getInt("pk")).isEqualTo(0);
assertThat(row.getInt("cc")).isEqualTo(i);
assertThat(row.getInt("v")).isEqualTo(i + 1);
}
execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
assertThat(execInfos).hasSize(1).containsExactly(row.getExecutionInfo());
colDefs = Flowable.<ColumnDefinitions>fromPublisher(rs.getColumnDefinitions()).toList().blockingGet();
assertThat(colDefs).hasSize(1).containsExactly(row.getColumnDefinitions());
wasApplied = Flowable.fromPublisher(rs.wasApplied()).toList().blockingGet();
assertThat(wasApplied).hasSize(1).containsExactly(row.wasApplied());
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class ExecutionInfoWarningsIT method should_execute_query_and_not_log_server_side_warnings.
@Test
@CassandraRequirement(min = "3.0")
public void should_execute_query_and_not_log_server_side_warnings() {
final String query = "SELECT count(*) FROM test;";
Statement<?> st = SimpleStatement.builder(query).setExecutionProfileName("log-disabled").build();
ResultSet result = sessionRule.session().execute(st);
ExecutionInfo executionInfo = result.getExecutionInfo();
assertThat(executionInfo).isNotNull();
List<String> warnings = executionInfo.getWarnings();
assertThat(warnings).isNotEmpty();
String warning = warnings.get(0);
assertThat(warning).isEqualTo("Aggregation query used without partition key");
// verify the log was NOT generated
verify(appender, timeout(500).times(0)).doAppend(loggingEventCaptor.capture());
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class ExceptionIT method should_expose_execution_info_on_exceptions.
@Test
public void should_expose_execution_info_on_exceptions() {
// Given
SIMULACRON_RULE.cluster().node(0).prime(when(QUERY_STRING).then(unavailable(com.datastax.oss.simulacron.common.codec.ConsistencyLevel.ONE, 1, 0)));
SIMULACRON_RULE.cluster().node(1).prime(when(QUERY_STRING).then(PrimeDsl.invalid("Mock error message")));
// Then
assertThatThrownBy(() -> SESSION_RULE.session().execute(QUERY_STRING)).isInstanceOf(InvalidQueryException.class).satisfies(exception -> {
ExecutionInfo info = ((InvalidQueryException) exception).getExecutionInfo();
assertThat(info).isNotNull();
assertThat(info.getCoordinator().getEndPoint().resolve()).isEqualTo(SIMULACRON_RULE.cluster().node(1).inetSocketAddress());
assertThat(((SimpleStatement) info.getRequest()).getQuery()).isEqualTo(QUERY_STRING);
// specex disabled => the initial execution completed the response
assertThat(info.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(info.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(info.getTracingId()).isNull();
assertThat(info.getPagingState()).isNull();
assertThat(info.getIncomingPayload()).isEmpty();
assertThat(info.getWarnings()).isEmpty();
assertThat(info.isSchemaInAgreement()).isTrue();
assertThat(info.getResponseSizeInBytes()).isEqualTo(info.getCompressedResponseSizeInBytes()).isEqualTo(-1);
List<Map.Entry<Node, Throwable>> errors = info.getErrors();
assertThat(errors).hasSize(1);
Map.Entry<Node, Throwable> entry0 = errors.get(0);
assertThat(entry0.getKey().getEndPoint().resolve()).isEqualTo(SIMULACRON_RULE.cluster().node(0).inetSocketAddress());
Throwable node0Exception = entry0.getValue();
assertThat(node0Exception).isInstanceOf(UnavailableException.class);
// ExecutionInfo is not exposed for retried errors
assertThat(((UnavailableException) node0Exception).getExecutionInfo()).isNull();
});
}
Aggregations