Search in sources :

Example 11 with Message

use of com.datastax.oss.protocol.internal.Message in project java-driver by datastax.

the class ProfileIT method assertServerSideCl.

private void assertServerSideCl(ConsistencyLevel expectedCl) {
    List<QueryLog> queryLogs = SIMULACRON_RULE.cluster().getLogs().getQueryLogs();
    QueryLog lastLog = queryLogs.get(queryLogs.size() - 1);
    Message message = lastLog.getFrame().message;
    assertThat(message).isInstanceOf(Execute.class);
    Execute queryExecute = (Execute) message;
    assertThat(queryExecute.options.consistency).isEqualTo(expectedCl.getProtocolCode());
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Execute(com.datastax.oss.protocol.internal.request.Execute) QueryLog(com.datastax.oss.simulacron.common.cluster.QueryLog)

Example 12 with Message

use of com.datastax.oss.protocol.internal.Message 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)

Example 13 with Message

use of com.datastax.oss.protocol.internal.Message in project java-driver by datastax.

the class InFlightHandler method channelRead.

@Override
@SuppressWarnings("NonAtomicVolatileUpdate")
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    Frame responseFrame = (Frame) msg;
    int streamId = responseFrame.streamId;
    if (streamId < 0) {
        Message event = responseFrame.message;
        if (eventCallback == null) {
            LOG.debug("[{}] Received event {} but no callback was registered", logPrefix, event);
        } else {
            LOG.debug("[{}] Received event {}, notifying callback", logPrefix, event);
            try {
                eventCallback.onEvent(event);
            } catch (Throwable t) {
                Loggers.warnWithException(LOG, "[{}] Unexpected error while invoking event handler", logPrefix, t);
            }
        }
    } else {
        boolean wasInFlight = true;
        ResponseCallback callback = inFlight.get(streamId);
        if (callback == null) {
            wasInFlight = false;
            callback = orphaned.get(streamId);
            if (callback == null) {
                LOG.trace("[{}] Got response on unknown stream id {}, skipping", logPrefix, streamId);
                return;
            }
        }
        try {
            if (callback.isLastResponse(responseFrame)) {
                LOG.debug("[{}] Got last response on {} stream id {}, completing and releasing", logPrefix, wasInFlight ? "in-flight" : "orphaned", streamId);
                release(streamId, ctx);
            } else {
                LOG.trace("[{}] Got non-last response on {} stream id {}, still holding", logPrefix, wasInFlight ? "in-flight" : "orphaned", streamId);
            }
            if (wasInFlight) {
                callback.onResponse(responseFrame);
            }
        } catch (Throwable t) {
            if (wasInFlight) {
                fail(callback, new IllegalArgumentException("Unexpected error while invoking response handler", t));
            } else {
                // Assume the callback is already completed, so it's better to log
                Loggers.warnWithException(LOG, "[{}] Unexpected error while invoking response handler on stream id {}", logPrefix, t, streamId);
            }
        }
    }
}
Also used : Frame(com.datastax.oss.protocol.internal.Frame) RequestMessage(com.datastax.oss.driver.internal.core.channel.DriverChannel.RequestMessage) Message(com.datastax.oss.protocol.internal.Message)

Example 14 with Message

use of com.datastax.oss.protocol.internal.Message in project java-driver by datastax.

the class SimpleStatementSimulacronIT method should_use_consistencies.

@Test
public void should_use_consistencies() {
    SimpleStatement st = SimpleStatement.builder("SELECT * FROM test where k = ?").setConsistencyLevel(DefaultConsistencyLevel.TWO).setSerialConsistencyLevel(DefaultConsistencyLevel.LOCAL_SERIAL).build();
    SESSION_RULE.session().execute(st);
    List<QueryLog> logs = SIMULACRON_RULE.cluster().getLogs().getQueryLogs();
    assertThat(logs).hasSize(1);
    QueryLog log = logs.get(0);
    Message message = log.getFrame().message;
    assertThat(message).isInstanceOf(Query.class);
    Query query = (Query) message;
    assertThat(query.options.consistency).isEqualTo(DefaultConsistencyLevel.TWO.getProtocolCode());
    assertThat(query.options.serialConsistency).isEqualTo(DefaultConsistencyLevel.LOCAL_SERIAL.getProtocolCode());
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Query(com.datastax.oss.protocol.internal.request.Query) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) QueryLog(com.datastax.oss.simulacron.common.cluster.QueryLog) Test(org.junit.Test)

Aggregations

Message (com.datastax.oss.protocol.internal.Message)14 Test (org.junit.Test)8 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)7 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)5 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)5 RawBytesQuery (com.datastax.dse.protocol.internal.request.RawBytesQuery)5 Execute (com.datastax.oss.protocol.internal.request.Execute)4 Query (com.datastax.oss.protocol.internal.request.Query)4 QueryLog (com.datastax.oss.simulacron.common.cluster.QueryLog)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)4 ByteBuffer (java.nio.ByteBuffer)4 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)3 ScriptGraphStatement (com.datastax.dse.driver.api.core.graph.ScriptGraphStatement)2 CqlSession (com.datastax.oss.driver.api.core.CqlSession)2 NodeUnavailableException (com.datastax.oss.driver.api.core.NodeUnavailableException)2 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)2 Node (com.datastax.oss.driver.api.core.metadata.Node)2 DriverChannel (com.datastax.oss.driver.internal.core.channel.DriverChannel)2 DefaultNode (com.datastax.oss.driver.internal.core.metadata.DefaultNode)2 GraphNode (com.datastax.dse.driver.api.core.graph.GraphNode)1