Search in sources :

Example 26 with ExecutionInfo

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);
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DefaultExecutionInfo(com.datastax.oss.driver.internal.core.cql.DefaultExecutionInfo) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) ByteBuffer(java.nio.ByteBuffer) ArrayDeque(java.util.ArrayDeque) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) Rows(com.datastax.oss.protocol.internal.response.result.Rows)

Example 27 with ExecutionInfo

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);
}
Also used : ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveGraphNode(com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 28 with ExecutionInfo

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 29 with ExecutionInfo

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()));
        });
    }
}
Also used : AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) Error(com.datastax.oss.protocol.internal.response.Error) ServerError(com.datastax.oss.driver.api.core.servererrors.ServerError) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) Row(com.datastax.oss.driver.api.core.cql.Row) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 30 with ExecutionInfo

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);
        });
    }
}
Also used : AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) Row(com.datastax.oss.driver.api.core.cql.Row) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)50 Test (org.junit.Test)36 Row (com.datastax.oss.driver.api.core.cql.Row)20 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)19 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)13 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)13 ReactiveRow (com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow)12 RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)12 ContinuousAsyncResultSet (com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet)8 ReactiveResultSet (com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet)6 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)6 DefaultSession (com.datastax.oss.driver.internal.core.session.DefaultSession)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)5 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)5 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)5 ReactiveGraphNode (com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode)4 CqlSession (com.datastax.oss.driver.api.core.CqlSession)4 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)4 EmptyColumnDefinitions (com.datastax.oss.driver.internal.core.cql.EmptyColumnDefinitions)4