use of com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker in project java-driver by datastax.
the class CqlRequestHandlerTrackerTest method should_not_invoke_noop_request_tracker.
@Test
public void should_not_invoke_noop_request_tracker() {
try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withDefaultIdempotence(true).withResponse(node1, defaultFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message"))).withResponse(node2, defaultFrameOf(singleRow())).build()) {
RequestTracker requestTracker = spy(new NoopRequestTracker(harness.getContext()));
when(harness.getContext().getRequestTracker()).thenReturn(requestTracker);
CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
assertThatStage(resultSetFuture).isSuccess(resultSet -> verifyNoMoreInteractions(requestTracker));
}
}
use of com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker 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);
}
}
use of com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker 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);
}
}
use of com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker in project java-driver by datastax.
the class GraphRequestHandler method setFinalError.
private void setFinalError(GraphStatement<?> statement, Throwable error, Node node, int execution) {
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(statement, context);
if (error instanceof DriverException) {
((DriverException) error).setExecutionInfo(new DefaultExecutionInfo(statement, node, startedSpeculativeExecutionsCount.get(), execution, errors, null, null, true, session, context, executionProfile));
}
if (result.completeExceptionally(error)) {
cancelScheduledTasks();
if (!(requestTracker instanceof NoopRequestTracker)) {
long latencyNanos = System.nanoTime() - startTimeNanos;
requestTracker.onError(statement, error, latencyNanos, executionProfile, node, logPrefix);
}
if (error instanceof DriverTimeoutException) {
throttler.signalTimeout(this);
sessionMetricUpdater.incrementCounter(DseSessionMetric.GRAPH_CLIENT_TIMEOUTS, executionProfile.getName());
} else if (!(error instanceof RequestThrottlingException)) {
throttler.signalError(this, error);
}
}
}
use of com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker in project java-driver by datastax.
the class CqlRequestHandler method setFinalError.
private void setFinalError(Statement<?> statement, Throwable error, Node node, int execution) {
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(statement, context);
if (error instanceof DriverException) {
((DriverException) error).setExecutionInfo(new DefaultExecutionInfo(statement, node, startedSpeculativeExecutionsCount.get(), execution, errors, null, null, true, session, context, executionProfile));
}
if (result.completeExceptionally(error)) {
cancelScheduledTasks();
if (!(requestTracker instanceof NoopRequestTracker)) {
long latencyNanos = System.nanoTime() - startTimeNanos;
requestTracker.onError(statement, error, latencyNanos, executionProfile, node, logPrefix);
}
if (error instanceof DriverTimeoutException) {
throttler.signalTimeout(this);
sessionMetricUpdater.incrementCounter(DefaultSessionMetric.CQL_CLIENT_TIMEOUTS, executionProfile.getName());
} else if (!(error instanceof RequestThrottlingException)) {
throttler.signalError(this, error);
}
}
}
Aggregations