Skip to content

Commit 495fdda

Browse files
Add ExecutionInfo to RequestTracker callbacks
1 parent 43db6f6 commit 495fdda

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
@@ -833,7 +833,8 @@ public void onFailure(@NonNull Throwable error) {
833833
private void processResultResponse(@NonNull Result result, @Nullable Frame frame) {
834834
assert lock.isHeldByCurrentThread();
835835
try {
836-
ExecutionInfo executionInfo = createExecutionInfo(result, frame);
836+
ExecutionInfo executionInfo =
837+
createExecutionInfo().withServerResponse(result, frame).build();
837838
if (result instanceof Rows) {
838839
DseRowsMetadata rowsMetadata = (DseRowsMetadata) ((Rows) result).getMetadata();
839840
if (columnDefinitions == null) {
@@ -1458,7 +1459,7 @@ private void trackNodeError(
14581459
latencyNanos,
14591460
executionProfile,
14601461
node,
1461-
createExecutionInfo(frame),
1462+
createExecutionInfo().withServerResponse(frame).build(),
14621463
logPrefix);
14631464
}
14641465
}
@@ -1576,7 +1577,7 @@ private void completeResultSetFuture(
15761577

15771578
ExecutionInfo executionInfo = null;
15781579
if (pageOrError instanceof AsyncPagingIterable) {
1579-
executionInfo = ((AsyncPagingIterable) pageOrError).getExecutionInfo();
1580+
executionInfo = ((AsyncPagingIterable<?, ?>) pageOrError).getExecutionInfo();
15801581
} else if (pageOrError instanceof AsyncGraphResultSet) {
15811582
executionInfo = ((AsyncGraphResultSet) pageOrError).getRequestExecutionInfo();
15821583
}
@@ -1612,34 +1613,13 @@ private void completeResultSetFuture(
16121613
}
16131614

16141615
@NonNull
1615-
private ExecutionInfo createExecutionInfo(@NonNull Result result, @Nullable Frame response) {
1616-
ByteBuffer pagingState =
1617-
result instanceof Rows ? ((Rows) result).getMetadata().pagingState : null;
1618-
return new DefaultExecutionInfo(
1616+
private DefaultExecutionInfo.Builder createExecutionInfo() {
1617+
return DefaultExecutionInfo.builder(
16191618
statement,
16201619
node,
16211620
startedSpeculativeExecutionsCount.get(),
16221621
executionIndex,
16231622
errors,
1624-
pagingState,
1625-
response,
1626-
true,
1627-
session,
1628-
context,
1629-
executionProfile);
1630-
}
1631-
1632-
@NonNull
1633-
private ExecutionInfo createExecutionInfo(@Nullable Frame response) {
1634-
return new DefaultExecutionInfo(
1635-
statement,
1636-
node,
1637-
startedSpeculativeExecutionsCount.get(),
1638-
executionIndex,
1639-
errors,
1640-
null,
1641-
response,
1642-
true,
16431623
session,
16441624
context,
16451625
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
@@ -329,7 +329,18 @@ private void cancelScheduledTasks() {
329329
private void setFinalResult(
330330
Result resultMessage, Frame responseFrame, NodeResponseCallback callback) {
331331
try {
332-
ExecutionInfo executionInfo = buildExecutionInfo(callback, responseFrame);
332+
ExecutionInfo executionInfo =
333+
DefaultExecutionInfo.builder(
334+
callback.statement,
335+
callback.node,
336+
startedSpeculativeExecutionsCount.get(),
337+
callback.execution,
338+
errors,
339+
session,
340+
context,
341+
callback.executionProfile)
342+
.withServerResponse(resultMessage, responseFrame)
343+
.build();
333344
DriverExecutionProfile executionProfile =
334345
Conversions.resolveExecutionProfile(callback.statement, context);
335346
GraphProtocol subProtocol =
@@ -426,23 +437,6 @@ private void logServerWarnings(GraphStatement<?> statement, List<String> warning
426437
LOG.warn("Query '{}' generated server side warning(s): {}", statementString, warning));
427438
}
428439

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

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)