Search in sources :

Example 1 with NodeUnavailableException

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

the class CqlPrepareHandler method sendRequest.

private void sendRequest(PrepareRequest request, Node node, int retryCount) {
    if (result.isDone()) {
        return;
    }
    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) {
        setFinalError(AllNodesFailedException.fromErrors(this.errors));
    } else {
        InitialPrepareCallback initialPrepareCallback = new InitialPrepareCallback(request, node, channel, retryCount);
        Prepare message = toPrepareMessage(request);
        channel.write(message, false, request.getCustomPayload(), initialPrepareCallback).addListener(initialPrepareCallback);
    }
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) NodeUnavailableException(com.datastax.oss.driver.api.core.NodeUnavailableException) Prepare(com.datastax.oss.protocol.internal.request.Prepare)

Example 2 with NodeUnavailableException

use of com.datastax.oss.driver.api.core.NodeUnavailableException 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)

Example 3 with NodeUnavailableException

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

the class GraphRequestHandler method sendRequest.

/**
 * Sends the request to the next available node.
 *
 * @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(GraphStatement<?> 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, NO_SUCCESSFUL_EXECUTION);
        }
    } else {
        NodeResponseCallback nodeResponseCallback = new NodeResponseCallback(statement, node, queryPlan, channel, currentExecutionIndex, retryCount, scheduleNextExecution, logPrefix);
        DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(statement, context);
        GraphProtocol graphSubProtocol = GraphConversions.resolveGraphSubProtocol(statement, graphSupportChecker, context);
        Message message = GraphConversions.createMessageFromGraphStatement(statement, graphSubProtocol, executionProfile, context, graphBinaryModule);
        Map<String, ByteBuffer> customPayload = GraphConversions.createCustomPayload(statement, graphSubProtocol, executionProfile, context, graphBinaryModule);
        channel.write(message, statement.isTracing(), customPayload, 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) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) 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) ByteBuffer(java.nio.ByteBuffer)

Aggregations

NodeUnavailableException (com.datastax.oss.driver.api.core.NodeUnavailableException)3 DriverChannel (com.datastax.oss.driver.internal.core.channel.DriverChannel)3 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)2 Node (com.datastax.oss.driver.api.core.metadata.Node)2 DefaultNode (com.datastax.oss.driver.internal.core.metadata.DefaultNode)2 Message (com.datastax.oss.protocol.internal.Message)2 GraphNode (com.datastax.dse.driver.api.core.graph.GraphNode)1 Prepare (com.datastax.oss.protocol.internal.request.Prepare)1 ByteBuffer (java.nio.ByteBuffer)1