Skip to content

Commit 6373907

Browse files
committed
JAVA-1830: Surface response frame size in ExecutionInfo
1 parent 44de062 commit 6373907

5 files changed

Lines changed: 59 additions & 0 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 4.0.0-alpha4 (in progress)
66

7+
- [improvement] JAVA-1830: Surface response frame size in ExecutionInfo
78
- [improvement] JAVA-1853: Add newValue(Object...) to TupleType and UserDefinedType
89
- [improvement] JAVA-1815: Reorganize configuration into basic/advanced categories
910
- [improvement] JAVA-1848: Add logs to DefaultRetryPolicy

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.datastax.oss.driver.api.core.DefaultProtocolVersion;
1919
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
2020
import com.datastax.oss.driver.api.core.metadata.Node;
21+
import com.datastax.oss.driver.api.core.retry.RetryDecision;
2122
import com.datastax.oss.driver.api.core.session.Request;
2223
import com.datastax.oss.driver.api.core.session.Session;
2324
import com.datastax.oss.driver.api.core.specex.SpeculativeExecutionPolicy;
@@ -147,4 +148,31 @@ default QueryTrace getQueryTrace() {
147148
BlockingOperation.checkNotDriverThread();
148149
return CompletableFutures.getUninterruptibly(getQueryTraceAsync());
149150
}
151+
152+
/**
153+
* The size of the binary response in bytes.
154+
*
155+
* <p>This is the size of the protocol-level frame (including the frame header) before it was
156+
* decoded by the driver, but after decompression (if compression is enabled).
157+
*
158+
* <p>If the information is not available (for example if this execution info comes from an {@link
159+
* RetryDecision#IGNORE IGNORE} decision of the retry policy), this method returns -1.
160+
*
161+
* @see #getCompressedResponseSizeInBytes()
162+
*/
163+
int getResponseSizeInBytes();
164+
165+
/**
166+
* The size of the compressed binary response in bytes.
167+
*
168+
* <p>This is the size of the protocol-level frame (including the frame header) as it came in the
169+
* TCP response, before decompression and decoding by the driver.
170+
*
171+
* <p>If compression is disabled, or if the information is not available (for example if this
172+
* execution info comes from an {@link RetryDecision#IGNORE IGNORE} decision of the retry policy),
173+
* this method returns -1.
174+
*
175+
* @see #getResponseSizeInBytes()
176+
*/
177+
int getCompressedResponseSizeInBytes();
150178
}

core/src/main/java/com/datastax/oss/driver/internal/core/cql/DefaultExecutionInfo.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class DefaultExecutionInfo implements ExecutionInfo {
4242
private final List<Map.Entry<Node, Throwable>> errors;
4343
private final ByteBuffer pagingState;
4444
private final UUID tracingId;
45+
private final int responseSizeInBytes;
46+
private final int compressedResponseSizeInBytes;
4547
private final List<String> warnings;
4648
private final Map<String, ByteBuffer> customPayload;
4749
private final boolean schemaInAgreement;
@@ -69,6 +71,8 @@ public DefaultExecutionInfo(
6971
this.pagingState = pagingState;
7072

7173
this.tracingId = (frame == null) ? null : frame.tracingId;
74+
this.responseSizeInBytes = (frame == null) ? -1 : frame.size;
75+
this.compressedResponseSizeInBytes = (frame == null) ? -1 : frame.compressedSize;
7276
// Note: the collections returned by the protocol layer are already unmodifiable
7377
this.warnings = (frame == null) ? Collections.emptyList() : frame.warnings;
7478
this.customPayload = (frame == null) ? Collections.emptyMap() : frame.customPayload;
@@ -139,4 +143,14 @@ public CompletionStage<QueryTrace> getQueryTraceAsync() {
139143
return new QueryTraceFetcher(tracingId, session, context, configProfile).fetch();
140144
}
141145
}
146+
147+
@Override
148+
public int getResponseSizeInBytes() {
149+
return responseSizeInBytes;
150+
}
151+
152+
@Override
153+
public int getCompressedResponseSizeInBytes() {
154+
return compressedResponseSizeInBytes;
155+
}
142156
}

integration-tests/src/test/java/com/datastax/oss/driver/api/core/compression/DirectCompressionIT.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.assertj.core.api.Assertions.offset;
2020

2121
import com.datastax.oss.driver.api.core.CqlSession;
22+
import com.datastax.oss.driver.api.core.cql.ExecutionInfo;
2223
import com.datastax.oss.driver.api.core.cql.ResultSet;
2324
import com.datastax.oss.driver.api.core.cql.Row;
2425
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
@@ -90,6 +91,13 @@ private void createAndCheckCluster(String compressorOption) {
9091
assertThat(row.getString("t")).isEqualTo("foo");
9192
assertThat(row.getInt("i")).isEqualTo(42);
9293
assertThat(row.getFloat("f")).isEqualTo(24.03f, offset(0.1f));
94+
95+
ExecutionInfo executionInfo = rs.getExecutionInfo();
96+
// There's not much more we can check without hard-coding sizes.
97+
// We are testing with small responses, so the compressed payload is not even guaranteed to be
98+
// smaller.
99+
assertThat(executionInfo.getResponseSizeInBytes()).isGreaterThan(0);
100+
assertThat(executionInfo.getCompressedResponseSizeInBytes()).isGreaterThan(0);
93101
}
94102
}
95103
}

integration-tests/src/test/java/com/datastax/oss/driver/api/core/compression/HeapCompressionIT.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.assertj.core.api.Assertions.offset;
2020

2121
import com.datastax.oss.driver.api.core.CqlSession;
22+
import com.datastax.oss.driver.api.core.cql.ExecutionInfo;
2223
import com.datastax.oss.driver.api.core.cql.ResultSet;
2324
import com.datastax.oss.driver.api.core.cql.Row;
2425
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
@@ -93,6 +94,13 @@ private void createAndCheckCluster(String compressorOption) {
9394
assertThat(row.getString("t")).isEqualTo("foo");
9495
assertThat(row.getInt("i")).isEqualTo(42);
9596
assertThat(row.getFloat("f")).isEqualTo(24.03f, offset(0.1f));
97+
98+
ExecutionInfo executionInfo = rs.getExecutionInfo();
99+
// There's not much more we can check without hard-coding sizes.
100+
// We are testing with small responses, so the compressed payload is not even guaranteed to be
101+
// smaller.
102+
assertThat(executionInfo.getResponseSizeInBytes()).isGreaterThan(0);
103+
assertThat(executionInfo.getCompressedResponseSizeInBytes()).isGreaterThan(0);
96104
}
97105
}
98106
}

0 commit comments

Comments
 (0)