use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class GraphRequestHandler method setFinalResult.
private void setFinalResult(Result resultMessage, Frame responseFrame, NodeResponseCallback callback) {
try {
ExecutionInfo executionInfo = buildExecutionInfo(callback, responseFrame);
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(callback.statement, context);
GraphProtocol subProtocol = GraphConversions.resolveGraphSubProtocol(callback.statement, graphSupportChecker, context);
Queue<GraphNode> graphNodes = new ArrayDeque<>();
for (List<ByteBuffer> row : ((Rows) resultMessage).getData()) {
if (subProtocol.isGraphBinary()) {
graphNodes.offer(GraphConversions.createGraphBinaryGraphNode(row, GraphRequestHandler.this.graphBinaryModule));
} else {
graphNodes.offer(GraphSONUtils.createGraphNode(row, subProtocol));
}
}
DefaultAsyncGraphResultSet resultSet = new DefaultAsyncGraphResultSet(executionInfo, graphNodes, subProtocol);
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, executionProfile, callback.node, logPrefix);
requestTracker.onSuccess(callback.statement, totalLatencyNanos, executionProfile, callback.node, logPrefix);
}
if (sessionMetricUpdater.isEnabled(DseSessionMetric.GRAPH_REQUESTS, executionProfile.getName())) {
if (completionTimeNanos == NANOTIME_NOT_MEASURED_YET) {
completionTimeNanos = System.nanoTime();
totalLatencyNanos = completionTimeNanos - startTimeNanos;
}
sessionMetricUpdater.updateTimer(DseSessionMetric.GRAPH_REQUESTS, executionProfile.getName(), totalLatencyNanos, TimeUnit.NANOSECONDS);
}
}
// log the warnings if they have NOT been disabled
if (!executionInfo.getWarnings().isEmpty() && executionProfile.getBoolean(DefaultDriverOption.REQUEST_LOG_WARNINGS) && LOG.isWarnEnabled()) {
logServerWarnings(callback.statement, executionInfo.getWarnings());
}
} catch (Throwable error) {
setFinalError(callback.statement, error, callback.node, NO_SUCCESSFUL_EXECUTION);
}
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class ReactiveGraphResultSetSubscription method toPage.
/**
* Converts the received result object into a {@link Page}.
*
* @param rs the result object to convert.
* @return a new page.
*/
@NonNull
private Page toPage(@NonNull AsyncGraphResultSet rs) {
ExecutionInfo executionInfo = rs.getRequestExecutionInfo();
Iterator<ReactiveGraphNode> results = Iterators.transform(rs.currentPage().iterator(), row -> new DefaultReactiveGraphNode(Objects.requireNonNull(row), executionInfo));
return new Page(results, rs.hasMorePages() ? rs::fetchNextPage : null);
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class ContinuousPagingReactiveIT method should_execute_reactively.
@Test
@UseDataProvider("pagingOptions")
public void should_execute_reactively(Options options) {
CqlSession session = sessionRule.session();
SimpleStatement statement = SimpleStatement.newInstance("SELECT v from test where k=?", KEY);
DriverExecutionProfile profile = options.asProfile(session);
ContinuousReactiveResultSet rs = session.executeContinuouslyReactive(statement.setExecutionProfile(profile));
List<ReactiveRow> results = Flowable.fromPublisher(rs).toList().blockingGet();
assertThat(results).hasSize(options.expectedRows);
Set<ExecutionInfo> expectedExecInfos = new LinkedHashSet<>();
for (int i = 0; i < results.size(); i++) {
ReactiveRow row = results.get(i);
assertThat(row.getInt("v")).isEqualTo(i);
expectedExecInfos.add(row.getExecutionInfo());
}
List<ExecutionInfo> execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
// DSE may send an empty page as it can't always know if it's done paging or not yet.
// See: CASSANDRA-8871. In this case, this page's execution info appears in
// rs.getExecutionInfos(), but is not present in expectedExecInfos since the page did not
// contain any rows.
assertThat(execInfos).containsAll(expectedExecInfos);
List<ColumnDefinitions> colDefs = Flowable.<ColumnDefinitions>fromPublisher(rs.getColumnDefinitions()).toList().blockingGet();
ReactiveRow first = results.get(0);
assertThat(colDefs).hasSize(1).containsExactly(first.getColumnDefinitions());
List<Boolean> wasApplied = Flowable.fromPublisher(rs.wasApplied()).toList().blockingGet();
assertThat(wasApplied).hasSize(1).containsExactly(first.wasApplied());
validateMetrics(session);
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class CqlRequestHandlerRetryTest method should_always_try_next_node_if_bootstrapping.
@Test
@UseDataProvider("allIdempotenceConfigs")
public void should_always_try_next_node_if_bootstrapping(boolean defaultIdempotence, Statement<?> statement) {
try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withDefaultIdempotence(defaultIdempotence).withResponse(node1, defaultFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message"))).withResponse(node2, defaultFrameOf(singleRow())).build()) {
CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test").handle();
assertThatStage(resultSetFuture).isSuccess(resultSet -> {
Iterator<Row> rows = resultSet.currentPage().iterator();
assertThat(rows.hasNext()).isTrue();
assertThat(rows.next().getString("message")).isEqualTo("hello, world");
ExecutionInfo executionInfo = resultSet.getExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node2);
assertThat(executionInfo.getErrors()).hasSize(1);
assertThat(executionInfo.getErrors().get(0).getKey()).isEqualTo(node1);
assertThat(executionInfo.getErrors().get(0).getValue()).isInstanceOf(BootstrappingException.class);
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getPagingState()).isNull();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
verifyNoMoreInteractions(harness.getContext().getRetryPolicy(anyString()));
});
}
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class CqlRequestHandlerRetryTest method should_ignore_error_if_idempotent_and_retry_policy_decides_so.
@Test
@UseDataProvider("failureAndIdempotent")
public void should_ignore_error_if_idempotent_and_retry_policy_decides_so(FailureScenario failureScenario, boolean defaultIdempotence, Statement<?> statement) {
RequestHandlerTestHarness.Builder harnessBuilder = RequestHandlerTestHarness.builder().withDefaultIdempotence(defaultIdempotence);
failureScenario.mockRequestError(harnessBuilder, node1);
try (RequestHandlerTestHarness harness = harnessBuilder.build()) {
failureScenario.mockRetryPolicyVerdict(harness.getContext().getRetryPolicy(anyString()), RetryVerdict.IGNORE);
CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test").handle();
assertThatStage(resultSetFuture).isSuccess(resultSet -> {
Iterator<Row> rows = resultSet.currentPage().iterator();
assertThat(rows.hasNext()).isFalse();
ExecutionInfo executionInfo = resultSet.getExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node1);
assertThat(executionInfo.getErrors()).hasSize(0);
verify(nodeMetricUpdater1).incrementCounter(failureScenario.errorMetric, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1).incrementCounter(DefaultNodeMetric.IGNORES, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1).incrementCounter(failureScenario.ignoreMetric, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1, atMost(1)).isEnabled(DefaultNodeMetric.CQL_MESSAGES, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1, atMost(1)).updateTimer(eq(DefaultNodeMetric.CQL_MESSAGES), eq(DriverExecutionProfile.DEFAULT_NAME), anyLong(), eq(TimeUnit.NANOSECONDS));
verifyNoMoreInteractions(nodeMetricUpdater1);
});
}
}
Aggregations