Search in sources :

Example 56 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class GraphRequestHandler method onThrottleFailure.

@Override
public void onThrottleFailure(@NonNull RequestThrottlingException error) {
    DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(initialStatement, context);
    sessionMetricUpdater.incrementCounter(DefaultSessionMetric.THROTTLING_ERRORS, executionProfile.getName());
    setFinalError(initialStatement, error, null, NO_SUCCESSFUL_EXECUTION);
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile)

Example 57 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile 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 58 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class GraphSupportChecker method isPagingEnabled.

/**
 * Checks whether graph paging is available.
 *
 * <p>Graph paging is available if:
 *
 * <ol>
 *   <li>Continuous paging is generally available (this implies protocol version {@link
 *       com.datastax.dse.driver.api.core.DseProtocolVersion#DSE_V1 DSE_V1} or higher);
 *   <li>Graph paging is set to <code>ENABLED</code> or <code>AUTO</code> in the configuration
 *       with {@link DseDriverOption#GRAPH_PAGING_ENABLED};
 *   <li>If graph paging is set to <code>AUTO</code>, then a check will be performed to verify
 *       that all hosts are running DSE 6.8+; if that is the case, then graph paging will be
 *       assumed to be available.
 * </ol>
 *
 * Note that the hosts check will be done only once, then memoized; if other hosts join the
 * cluster later and do not support graph paging, the user has to manually disable graph paging.
 */
public boolean isPagingEnabled(@NonNull GraphStatement<?> graphStatement, @NonNull InternalDriverContext context) {
    DriverExecutionProfile driverExecutionProfile = Conversions.resolveExecutionProfile(graphStatement, context);
    PagingEnabledOptions pagingEnabledOptions = PagingEnabledOptions.valueOf(driverExecutionProfile.getString(DseDriverOption.GRAPH_PAGING_ENABLED));
    if (LOG.isTraceEnabled()) {
        LOG.trace("GRAPH_PAGING_ENABLED: {}", pagingEnabledOptions);
    }
    if (pagingEnabledOptions == PagingEnabledOptions.DISABLED) {
        return false;
    } else if (pagingEnabledOptions == PagingEnabledOptions.ENABLED) {
        return true;
    } else {
        return isContextGraphPagingEnabled(context);
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) PagingEnabledOptions(com.datastax.dse.driver.api.core.graph.PagingEnabledOptions)

Example 59 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class NoopMetricsFactoryTest method should_log_warning_when_metrics_enabled.

@Test
public void should_log_warning_when_metrics_enabled() {
    // given
    InternalDriverContext context = mock(InternalDriverContext.class);
    DriverConfig config = mock(DriverConfig.class);
    DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
    when(context.getSessionName()).thenReturn("MockSession");
    when(context.getConfig()).thenReturn(config);
    when(config.getDefaultProfile()).thenReturn(profile);
    when(profile.getStringList(DefaultDriverOption.METRICS_SESSION_ENABLED)).thenReturn(Collections.singletonList(DefaultSessionMetric.CQL_REQUESTS.getPath()));
    LoggerTest.LoggerSetup logger = LoggerTest.setupTestLogger(NoopMetricsFactory.class, Level.WARN);
    // when
    new NoopMetricsFactory(context);
    // then
    verify(logger.appender, times(1)).doAppend(logger.loggingEventCaptor.capture());
    assertThat(logger.loggingEventCaptor.getValue().getMessage()).isNotNull();
    assertThat(logger.loggingEventCaptor.getValue().getFormattedMessage()).contains("[MockSession] Some session-level or node-level metrics were enabled");
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Test(org.junit.Test) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest)

Example 60 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class DropwizardNodeMetricUpdaterTest method should_log_warning_when_provided_eviction_time_setting_is_too_low.

@Test
public void should_log_warning_when_provided_eviction_time_setting_is_too_low() {
    // given
    LoggerTest.LoggerSetup logger = LoggerTest.setupTestLogger(AbstractMetricUpdater.class, Level.WARN);
    Node node = mock(Node.class);
    InternalDriverContext context = mock(InternalDriverContext.class);
    DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
    DriverConfig config = mock(DriverConfig.class);
    Set<NodeMetric> enabledMetrics = Collections.singleton(DefaultNodeMetric.CQL_MESSAGES);
    Duration expireAfter = AbstractMetricUpdater.MIN_EXPIRE_AFTER.minusMinutes(1);
    // when
    when(context.getSessionName()).thenReturn("prefix");
    when(context.getConfig()).thenReturn(config);
    when(config.getDefaultProfile()).thenReturn(profile);
    when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(expireAfter);
    DropwizardNodeMetricUpdater updater = new DropwizardNodeMetricUpdater(node, context, enabledMetrics, new MetricRegistry()) {

        @Override
        protected void initializeGauge(NodeMetric metric, DriverExecutionProfile profile, Supplier<Number> supplier) {
        // do nothing
        }

        @Override
        protected void initializeCounter(NodeMetric metric, DriverExecutionProfile profile) {
        // do nothing
        }

        @Override
        protected void initializeHdrTimer(NodeMetric metric, DriverExecutionProfile profile, DriverOption highestLatency, DriverOption significantDigits, DriverOption interval) {
        // do nothing
        }
    };
    // then
    assertThat(updater.getExpireAfter()).isEqualTo(AbstractMetricUpdater.MIN_EXPIRE_AFTER);
    verify(logger.appender, timeout(500).times(1)).doAppend(logger.loggingEventCaptor.capture());
    assertThat(logger.loggingEventCaptor.getValue().getMessage()).isNotNull();
    assertThat(logger.loggingEventCaptor.getValue().getFormattedMessage()).contains(String.format("[prefix] Value too low for %s: %s. Forcing to %s instead.", DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER.getPath(), expireAfter, AbstractMetricUpdater.MIN_EXPIRE_AFTER));
}
Also used : DefaultDriverOption(com.datastax.oss.driver.api.core.config.DefaultDriverOption) DriverOption(com.datastax.oss.driver.api.core.config.DriverOption) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Node(com.datastax.oss.driver.api.core.metadata.Node) MetricRegistry(com.codahale.metrics.MetricRegistry) Duration(java.time.Duration) DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) NodeMetric(com.datastax.oss.driver.api.core.metrics.NodeMetric) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Supplier(java.util.function.Supplier) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Test(org.junit.Test)

Aggregations

DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)140 Test (org.junit.Test)81 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)29 DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)20 CqlSession (com.datastax.oss.driver.api.core.CqlSession)19 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)17 Node (com.datastax.oss.driver.api.core.metadata.Node)14 ByteBuffer (java.nio.ByteBuffer)13 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)12 Duration (java.time.Duration)11 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)10 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)10 Row (com.datastax.oss.driver.api.core.cql.Row)9 Test (org.junit.jupiter.api.Test)9 LoggerTest (com.datastax.oss.driver.internal.core.util.LoggerTest)8 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)7 NodeMetric (com.datastax.oss.driver.api.core.metrics.NodeMetric)7 Message (com.datastax.oss.protocol.internal.Message)7 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)6 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)6