Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,27 @@ protected abstract ResultSetT createResultSet(

@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())) {
session
.getMetricUpdater()
.updateTimer(
DefaultSessionMetric.THROTTLING_DELAY,
executionProfile.getName(),
System.nanoTime() - startTimeNanos,
TimeUnit.NANOSECONDS);
try {
DriverExecutionProfile executionProfile =
Conversions.resolveExecutionProfile(initialStatement, context);
if (wasDelayed
// avoid call to nanoTime() if metric is disabled:
&& sessionMetricUpdater.isEnabled(
DefaultSessionMetric.THROTTLING_DELAY, executionProfile.getName())) {
session
.getMetricUpdater()
.updateTimer(
DefaultSessionMetric.THROTTLING_DELAY,
executionProfile.getName(),
System.nanoTime() - startTimeNanos,
TimeUnit.NANOSECONDS);
}
activeExecutionsCount.incrementAndGet();
sendRequest(initialStatement, null, 0, 0, specExecEnabled);
} catch (Throwable error) {
abortGlobalRequestOrChosenCallback(error);
throttler.signalError(this, error);
}
activeExecutionsCount.incrementAndGet();
sendRequest(initialStatement, null, 0, 0, specExecEnabled);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,29 @@ public class GraphRequestHandler implements Throttled {

@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);
try {
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 =
initialStatement.getNode() != null
? new SimpleQueryPlan(initialStatement.getNode())
: context
.getLoadBalancingPolicyWrapper()
.newQueryPlan(initialStatement, executionProfile.getName(), session);
sendRequest(initialStatement, null, queryPlan, 0, 0, true);
} catch (Throwable error) {
setFinalError(initialStatement, error, null, NO_SUCCESSFUL_EXECUTION);
}
Queue<Node> queryPlan =
initialStatement.getNode() != null
? new SimpleQueryPlan(initialStatement.getNode())
: context
.getLoadBalancingPolicyWrapper()
.newQueryPlan(initialStatement, executionProfile.getName(), session);
sendRequest(initialStatement, null, queryPlan, 0, 0, true);
}

public CompletionStage<AsyncGraphResultSet> handle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,22 @@ protected CqlPrepareHandler(

@Override
public void onThrottleReady(boolean wasDelayed) {
DriverExecutionProfile executionProfile =
Conversions.resolveExecutionProfile(initialRequest, context);
if (wasDelayed) {
session
.getMetricUpdater()
.updateTimer(
DefaultSessionMetric.THROTTLING_DELAY,
executionProfile.getName(),
System.nanoTime() - startTimeNanos,
TimeUnit.NANOSECONDS);
try {
DriverExecutionProfile executionProfile =
Conversions.resolveExecutionProfile(initialRequest, context);
if (wasDelayed) {
session
.getMetricUpdater()
.updateTimer(
DefaultSessionMetric.THROTTLING_DELAY,
executionProfile.getName(),
System.nanoTime() - startTimeNanos,
TimeUnit.NANOSECONDS);
}
sendRequest(initialRequest, null, 0);
} catch (Throwable error) {
setFinalError(error);
}
sendRequest(initialRequest, null, 0);
}

public CompletableFuture<PreparedStatement> handle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,27 +212,31 @@ protected CqlRequestHandler(

@Override
public void onThrottleReady(boolean wasDelayed) {
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;
if (this.initialStatement.getNode() != null) {
queryPlan = new SimpleQueryPlan(this.initialStatement.getNode());
} else {
queryPlan =
context
.getLoadBalancingPolicyWrapper()
.newQueryPlan(initialStatement, executionProfile.getName(), session);
}
try {
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;
if (this.initialStatement.getNode() != null) {
queryPlan = new SimpleQueryPlan(this.initialStatement.getNode());
} else {
queryPlan =
context
.getLoadBalancingPolicyWrapper()
.newQueryPlan(initialStatement, executionProfile.getName(), session);
}

sendRequest(initialStatement, null, queryPlan, 0, 0, true);
sendRequest(initialStatement, null, queryPlan, 0, 0, true);
} catch (Throwable error) {
setFinalError(initialStatement, error, null, -1);
}
}

public CompletionStage<AsyncResultSet> handle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import static com.datastax.oss.driver.Assertions.assertThat;
import static com.datastax.oss.driver.Assertions.assertThatStage;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -58,6 +60,28 @@

public class CqlRequestHandlerTest extends CqlRequestHandlerTestBase {

@Test
public void should_fail_future_if_throttled_request_setup_throws() {
RuntimeException expected = new RuntimeException("mock query plan failure");
try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().build()) {
when(harness
.getContext()
.getLoadBalancingPolicyWrapper()
.newQueryPlan(any(), anyString(), any()))
.thenThrow(expected);

CompletionStage<AsyncResultSet> resultSetFuture =
new CqlRequestHandler(
UNDEFINED_IDEMPOTENCE_STATEMENT,
harness.getSession(),
harness.getContext(),
"test")
.handle();

assertThatStage(resultSetFuture).isFailed(error -> assertThat(error).isSameAs(expected));
}
}

@Test
public void should_complete_result_if_first_node_replies_immediately() {
try (RequestHandlerTestHarness harness =
Expand Down