Skip to content

Commit d5a79a7

Browse files
Add ExecutionInfo to RequestTracker callbacks
1 parent 92b6eee commit d5a79a7

File tree

9 files changed

+393
-257
lines changed

9 files changed

+393
-257
lines changed

core/src/main/java/com/datastax/dse/driver/api/core/graph/GraphExecutionInfo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
package com.datastax.dse.driver.api.core.graph;
1919

2020
import com.datastax.oss.driver.api.core.DefaultProtocolVersion;
21+
import com.datastax.oss.driver.api.core.config.DriverExecutionProfile;
2122
import com.datastax.oss.driver.api.core.metadata.Node;
2223
import com.datastax.oss.driver.api.core.specex.SpeculativeExecutionPolicy;
24+
import edu.umd.cs.findbugs.annotations.Nullable;
2325
import java.nio.ByteBuffer;
2426
import java.util.List;
2527
import java.util.Map;
@@ -37,6 +39,12 @@ public interface GraphExecutionInfo {
3739
/** The statement that was executed. */
3840
GraphStatement<?> getStatement();
3941

42+
/** @return Execution profile applied when executing given request. */
43+
@Nullable
44+
default DriverExecutionProfile getExecutionProfile() {
45+
return null;
46+
}
47+
4048
/** The node that was used as a coordinator to successfully complete the query. */
4149
Node getCoordinator();
4250

core/src/main/java/com/datastax/dse/driver/internal/core/cql/continuous/ContinuousRequestHandlerBase.java

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,8 @@ public void onFailure(@NonNull Throwable error) {
834834
private void processResultResponse(@NonNull Result result, @Nullable Frame frame) {
835835
assert lock.isHeldByCurrentThread();
836836
try {
837-
ExecutionInfo executionInfo = createExecutionInfo(result, frame);
837+
ExecutionInfo executionInfo =
838+
createExecutionInfo().withServerResponse(result, frame).build();
838839
if (result instanceof Rows) {
839840
DseRowsMetadata rowsMetadata = (DseRowsMetadata) ((Rows) result).getMetadata();
840841
if (columnDefinitions == null) {
@@ -1459,7 +1460,7 @@ private void trackNodeError(
14591460
latencyNanos,
14601461
executionProfile,
14611462
node,
1462-
createExecutionInfo(frame),
1463+
createExecutionInfo().withServerResponse(frame).build(),
14631464
logPrefix);
14641465
}
14651466
}
@@ -1577,7 +1578,7 @@ private void completeResultSetFuture(
15771578

15781579
ExecutionInfo executionInfo = null;
15791580
if (pageOrError instanceof AsyncPagingIterable) {
1580-
executionInfo = ((AsyncPagingIterable) pageOrError).getExecutionInfo();
1581+
executionInfo = ((AsyncPagingIterable<?, ?>) pageOrError).getExecutionInfo();
15811582
} else if (pageOrError instanceof AsyncGraphResultSet) {
15821583
executionInfo = ((AsyncGraphResultSet) pageOrError).getRequestExecutionInfo();
15831584
}
@@ -1613,34 +1614,13 @@ private void completeResultSetFuture(
16131614
}
16141615

16151616
@NonNull
1616-
private ExecutionInfo createExecutionInfo(@NonNull Result result, @Nullable Frame response) {
1617-
ByteBuffer pagingState =
1618-
result instanceof Rows ? ((Rows) result).getMetadata().pagingState : null;
1619-
return new DefaultExecutionInfo(
1617+
private DefaultExecutionInfo.Builder createExecutionInfo() {
1618+
return DefaultExecutionInfo.builder(
16201619
statement,
16211620
node,
16221621
startedSpeculativeExecutionsCount.get(),
16231622
executionIndex,
16241623
errors,
1625-
pagingState,
1626-
response,
1627-
true,
1628-
session,
1629-
context,
1630-
executionProfile);
1631-
}
1632-
1633-
@NonNull
1634-
private ExecutionInfo createExecutionInfo(@Nullable Frame response) {
1635-
return new DefaultExecutionInfo(
1636-
statement,
1637-
node,
1638-
startedSpeculativeExecutionsCount.get(),
1639-
executionIndex,
1640-
errors,
1641-
null,
1642-
response,
1643-
true,
16441624
session,
16451625
context,
16461626
executionProfile);

core/src/main/java/com/datastax/dse/driver/internal/core/graph/GraphExecutionInfoConverter.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.datastax.dse.driver.internal.core.graph;
1919

2020
import com.datastax.dse.driver.api.core.graph.GraphStatement;
21+
import com.datastax.oss.driver.api.core.config.DriverExecutionProfile;
2122
import com.datastax.oss.driver.api.core.cql.ExecutionInfo;
2223
import com.datastax.oss.driver.api.core.cql.QueryTrace;
2324
import com.datastax.oss.driver.api.core.cql.Statement;
@@ -62,6 +63,11 @@ public Statement<?> getStatement() {
6263
throw new ClassCastException("GraphStatement cannot be cast to Statement");
6364
}
6465

66+
@Override
67+
public DriverExecutionProfile getExecutionProfile() {
68+
return graphExecutionInfo.getExecutionProfile();
69+
}
70+
6571
@Nullable
6672
@Override
6773
public Node getCoordinator() {
@@ -146,6 +152,11 @@ public GraphStatement<?> getStatement() {
146152
return (GraphStatement<?>) executionInfo.getRequest();
147153
}
148154

155+
@Override
156+
public DriverExecutionProfile getExecutionProfile() {
157+
return executionInfo.getExecutionProfile();
158+
}
159+
149160
@Override
150161
public Node getCoordinator() {
151162
return executionInfo.getCoordinator();

core/src/main/java/com/datastax/dse/driver/internal/core/graph/GraphRequestHandler.java

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,18 @@ private void cancelScheduledTasks() {
330330
private void setFinalResult(
331331
Result resultMessage, Frame responseFrame, NodeResponseCallback callback) {
332332
try {
333-
ExecutionInfo executionInfo = buildExecutionInfo(callback, responseFrame);
333+
ExecutionInfo executionInfo =
334+
DefaultExecutionInfo.builder(
335+
callback.statement,
336+
callback.node,
337+
startedSpeculativeExecutionsCount.get(),
338+
callback.execution,
339+
errors,
340+
session,
341+
context,
342+
callback.executionProfile)
343+
.withServerResponse(resultMessage, responseFrame)
344+
.build();
334345
DriverExecutionProfile executionProfile =
335346
Conversions.resolveExecutionProfile(callback.statement, context);
336347
GraphProtocol subProtocol =
@@ -427,23 +438,6 @@ private void logServerWarnings(GraphStatement<?> statement, List<String> warning
427438
LOG.warn("Query '{}' generated server side warning(s): {}", statementString, warning));
428439
}
429440

430-
private ExecutionInfo buildExecutionInfo(NodeResponseCallback callback, Frame responseFrame) {
431-
DriverExecutionProfile executionProfile =
432-
Conversions.resolveExecutionProfile(callback.statement, context);
433-
return new DefaultExecutionInfo(
434-
callback.statement,
435-
callback.node,
436-
startedSpeculativeExecutionsCount.get(),
437-
callback.execution,
438-
errors,
439-
null,
440-
responseFrame,
441-
true,
442-
session,
443-
context,
444-
executionProfile);
445-
}
446-
447441
@Override
448442
public void onThrottleFailure(@NonNull RequestThrottlingException error) {
449443
DriverExecutionProfile executionProfile =
@@ -458,18 +452,16 @@ private void setFinalError(
458452
DriverExecutionProfile executionProfile =
459453
Conversions.resolveExecutionProfile(statement, context);
460454
ExecutionInfo executionInfo =
461-
new DefaultExecutionInfo(
462-
statement,
463-
node,
464-
startedSpeculativeExecutionsCount.get(),
465-
execution,
466-
errors,
467-
null,
468-
null,
469-
true,
470-
session,
471-
context,
472-
executionProfile);
455+
DefaultExecutionInfo.builder(
456+
statement,
457+
node,
458+
startedSpeculativeExecutionsCount.get(),
459+
execution,
460+
errors,
461+
session,
462+
context,
463+
executionProfile)
464+
.build();
473465
if (error instanceof DriverException) {
474466
((DriverException) error).setExecutionInfo(executionInfo);
475467
}

core/src/main/java/com/datastax/oss/driver/api/core/cql/ExecutionInfo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.datastax.oss.driver.api.core.DriverException;
2222
import com.datastax.oss.driver.api.core.RequestThrottlingException;
2323
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
24+
import com.datastax.oss.driver.api.core.config.DriverExecutionProfile;
2425
import com.datastax.oss.driver.api.core.detach.AttachmentPoint;
2526
import com.datastax.oss.driver.api.core.metadata.Node;
2627
import com.datastax.oss.driver.api.core.retry.RetryDecision;
@@ -66,6 +67,12 @@ default Request getRequest() {
6667
@Deprecated
6768
Statement<?> getStatement();
6869

70+
/** @return Execution profile applied when executing given request. */
71+
@Nullable
72+
default DriverExecutionProfile getExecutionProfile() {
73+
return null;
74+
}
75+
6976
/**
7077
* The node that acted as a coordinator for the query.
7178
*

0 commit comments

Comments
 (0)