Search in sources :

Example 21 with DriverExecutionProfile

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

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

the class Conversions method resolveIdempotence.

public static boolean resolveIdempotence(Request request, InternalDriverContext context) {
    Boolean requestIsIdempotent = request.isIdempotent();
    DriverExecutionProfile executionProfile = resolveExecutionProfile(request, context);
    return (requestIsIdempotent == null) ? executionProfile.getBoolean(DefaultDriverOption.REQUEST_DEFAULT_IDEMPOTENCE) : requestIsIdempotent;
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile)

Example 23 with DriverExecutionProfile

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

the class CqlRequestHandler method onThrottleReady.

@Override
public void onThrottleReady(boolean wasDelayed) {
    DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(initialStatement, context);
    if (wasDelayed && // avoid call to nanoTime() if metric is disabled:
    sessionMetricUpdater.isEnabled(DefaultSessionMetric.THROTTLING_DELAY, executionProfile.getName())) {
        sessionMetricUpdater.updateTimer(DefaultSessionMetric.THROTTLING_DELAY, executionProfile.getName(), System.nanoTime() - startTimeNanos, TimeUnit.NANOSECONDS);
    }
    Queue<Node> queryPlan = this.initialStatement.getNode() != null ? new SimpleQueryPlan(this.initialStatement.getNode()) : context.getLoadBalancingPolicyWrapper().newQueryPlan(initialStatement, executionProfile.getName(), session);
    sendRequest(initialStatement, null, queryPlan, 0, 0, true);
}
Also used : SimpleQueryPlan(com.datastax.oss.driver.internal.core.util.collection.SimpleQueryPlan) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DefaultNode(com.datastax.oss.driver.internal.core.metadata.DefaultNode) Node(com.datastax.oss.driver.api.core.metadata.Node)

Example 24 with DriverExecutionProfile

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

the class CqlRequestHandler 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, -1);
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile)

Example 25 with DriverExecutionProfile

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

the class CqlRequestHandler method sendRequest.

/**
 * Sends the request to the next available node.
 *
 * @param statement The statement to execute.
 * @param retriedNode if not null, it will be attempted first before the rest of the query plan.
 * @param queryPlan the list of nodes to try (shared with all other executions)
 * @param currentExecutionIndex 0 for the initial execution, 1 for the first speculative one, etc.
 * @param retryCount the number of times that the retry policy was invoked for this execution
 *     already (note that some internal retries don't go through the policy, and therefore don't
 *     increment this counter)
 * @param scheduleNextExecution whether to schedule the next speculative execution
 */
private void sendRequest(Statement<?> statement, Node retriedNode, Queue<Node> queryPlan, int currentExecutionIndex, int retryCount, boolean scheduleNextExecution) {
    if (result.isDone()) {
        return;
    }
    Node node = retriedNode;
    DriverChannel channel = null;
    if (node == null || (channel = session.getChannel(node, logPrefix)) == null) {
        while (!result.isDone() && (node = queryPlan.poll()) != null) {
            channel = session.getChannel(node, logPrefix);
            if (channel != null) {
                break;
            } else {
                recordError(node, new NodeUnavailableException(node));
            }
        }
    }
    if (channel == null) {
        // We've reached the end of the query plan without finding any node to write to
        if (!result.isDone() && activeExecutionsCount.decrementAndGet() == 0) {
            // We're the last execution so fail the result
            setFinalError(statement, AllNodesFailedException.fromErrors(this.errors), null, -1);
        }
    } else {
        NodeResponseCallback nodeResponseCallback = new NodeResponseCallback(statement, node, queryPlan, channel, currentExecutionIndex, retryCount, scheduleNextExecution, logPrefix);
        DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(statement, context);
        Message message = Conversions.toMessage(statement, executionProfile, context);
        channel.write(message, statement.isTracing(), statement.getCustomPayload(), nodeResponseCallback).addListener(nodeResponseCallback);
    }
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) Message(com.datastax.oss.protocol.internal.Message) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DefaultNode(com.datastax.oss.driver.internal.core.metadata.DefaultNode) Node(com.datastax.oss.driver.api.core.metadata.Node) NodeUnavailableException(com.datastax.oss.driver.api.core.NodeUnavailableException)

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