Search in sources :

Example 1 with NoopRequestTracker

use of com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker in project java-driver by datastax.

the class CqlRequestHandlerTrackerTest method should_not_invoke_noop_request_tracker.

@Test
public void should_not_invoke_noop_request_tracker() {
    try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withDefaultIdempotence(true).withResponse(node1, defaultFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message"))).withResponse(node2, defaultFrameOf(singleRow())).build()) {
        RequestTracker requestTracker = spy(new NoopRequestTracker(harness.getContext()));
        when(harness.getContext().getRequestTracker()).thenReturn(requestTracker);
        CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
        assertThatStage(resultSetFuture).isSuccess(resultSet -> verifyNoMoreInteractions(requestTracker));
    }
}
Also used : AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) Error(com.datastax.oss.protocol.internal.response.Error) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) RequestTracker(com.datastax.oss.driver.api.core.tracker.RequestTracker) Test(org.junit.Test)

Example 2 with NoopRequestTracker

use of com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker in project java-driver by datastax.

the class DefaultDriverContext method buildRequestTracker.

protected RequestTracker buildRequestTracker(RequestTracker requestTrackerFromBuilder) {
    List<RequestTracker> trackers = new ArrayList<>();
    if (requestTrackerFromBuilder != null) {
        trackers.add(requestTrackerFromBuilder);
    }
    for (LoadBalancingPolicy lbp : this.getLoadBalancingPolicies().values()) {
        lbp.getRequestTracker().ifPresent(trackers::add);
    }
    DefaultDriverOption newOption = DefaultDriverOption.REQUEST_TRACKER_CLASSES;
    @SuppressWarnings("deprecation") DefaultDriverOption legacyOption = DefaultDriverOption.REQUEST_TRACKER_CLASS;
    DriverExecutionProfile profile = config.getDefaultProfile();
    if (profile.isDefined(newOption)) {
        trackers.addAll(Reflection.buildFromConfigList(this, newOption, RequestTracker.class, "com.datastax.oss.driver.internal.core.tracker"));
    }
    if (profile.isDefined(legacyOption)) {
        LOG.warn("Option {} has been deprecated and will be removed in a future release; please use option {} instead.", legacyOption, newOption);
        Reflection.buildFromConfig(this, legacyOption, RequestTracker.class, "com.datastax.oss.driver.internal.core.tracker").ifPresent(trackers::add);
    }
    if (trackers.isEmpty()) {
        return new NoopRequestTracker(this);
    } else if (trackers.size() == 1) {
        return trackers.get(0);
    } else {
        return new MultiplexingRequestTracker(trackers);
    }
}
Also used : LoadBalancingPolicy(com.datastax.oss.driver.api.core.loadbalancing.LoadBalancingPolicy) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DefaultDriverOption(com.datastax.oss.driver.api.core.config.DefaultDriverOption) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) ArrayList(java.util.ArrayList) MultiplexingRequestTracker(com.datastax.oss.driver.internal.core.tracker.MultiplexingRequestTracker) RequestTracker(com.datastax.oss.driver.api.core.tracker.RequestTracker) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) MultiplexingRequestTracker(com.datastax.oss.driver.internal.core.tracker.MultiplexingRequestTracker)

Example 3 with NoopRequestTracker

use of com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker 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 4 with NoopRequestTracker

use of com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker in project java-driver by datastax.

the class GraphRequestHandler method setFinalError.

private void setFinalError(GraphStatement<?> statement, Throwable error, Node node, int execution) {
    DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(statement, context);
    if (error instanceof DriverException) {
        ((DriverException) error).setExecutionInfo(new DefaultExecutionInfo(statement, node, startedSpeculativeExecutionsCount.get(), execution, errors, null, null, true, session, context, executionProfile));
    }
    if (result.completeExceptionally(error)) {
        cancelScheduledTasks();
        if (!(requestTracker instanceof NoopRequestTracker)) {
            long latencyNanos = System.nanoTime() - startTimeNanos;
            requestTracker.onError(statement, error, latencyNanos, executionProfile, node, logPrefix);
        }
        if (error instanceof DriverTimeoutException) {
            throttler.signalTimeout(this);
            sessionMetricUpdater.incrementCounter(DseSessionMetric.GRAPH_CLIENT_TIMEOUTS, executionProfile.getName());
        } else if (!(error instanceof RequestThrottlingException)) {
            throttler.signalError(this, error);
        }
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) DefaultExecutionInfo(com.datastax.oss.driver.internal.core.cql.DefaultExecutionInfo) DriverException(com.datastax.oss.driver.api.core.DriverException) RequestThrottlingException(com.datastax.oss.driver.api.core.RequestThrottlingException)

Example 5 with NoopRequestTracker

use of com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker in project java-driver by datastax.

the class CqlRequestHandler method setFinalError.

private void setFinalError(Statement<?> statement, Throwable error, Node node, int execution) {
    DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(statement, context);
    if (error instanceof DriverException) {
        ((DriverException) error).setExecutionInfo(new DefaultExecutionInfo(statement, node, startedSpeculativeExecutionsCount.get(), execution, errors, null, null, true, session, context, executionProfile));
    }
    if (result.completeExceptionally(error)) {
        cancelScheduledTasks();
        if (!(requestTracker instanceof NoopRequestTracker)) {
            long latencyNanos = System.nanoTime() - startTimeNanos;
            requestTracker.onError(statement, error, latencyNanos, executionProfile, node, logPrefix);
        }
        if (error instanceof DriverTimeoutException) {
            throttler.signalTimeout(this);
            sessionMetricUpdater.incrementCounter(DefaultSessionMetric.CQL_CLIENT_TIMEOUTS, executionProfile.getName());
        } else if (!(error instanceof RequestThrottlingException)) {
            throttler.signalError(this, error);
        }
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) DriverException(com.datastax.oss.driver.api.core.DriverException) RequestThrottlingException(com.datastax.oss.driver.api.core.RequestThrottlingException)

Aggregations

NoopRequestTracker (com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker)6 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)4 DriverException (com.datastax.oss.driver.api.core.DriverException)2 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)2 RequestThrottlingException (com.datastax.oss.driver.api.core.RequestThrottlingException)2 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)2 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)2 RequestTracker (com.datastax.oss.driver.api.core.tracker.RequestTracker)2 DefaultExecutionInfo (com.datastax.oss.driver.internal.core.cql.DefaultExecutionInfo)2 GraphNode (com.datastax.dse.driver.api.core.graph.GraphNode)1 DefaultDriverOption (com.datastax.oss.driver.api.core.config.DefaultDriverOption)1 LoadBalancingPolicy (com.datastax.oss.driver.api.core.loadbalancing.LoadBalancingPolicy)1 MultiplexingRequestTracker (com.datastax.oss.driver.internal.core.tracker.MultiplexingRequestTracker)1 Error (com.datastax.oss.protocol.internal.response.Error)1 Rows (com.datastax.oss.protocol.internal.response.result.Rows)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1