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());
}
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);
}
}
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);
}
}
}
}
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());
}
Aggregations