Skip to content
Merged
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
4 changes: 3 additions & 1 deletion changelog/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
## Changelog

### 3.5.0 (in progress)
### 3.5.0 (In progress)

- [improvement] JAVA-1448: TokenAwarePolicy should respect child policy ordering.
- [bug] JAVA-1751: Include defaultTimestamp length in encodedSize for protocol version >= 3.
- [bug] JAVA-1770: Fix message size when using Custom Payload.


### 3.4.0
Expand Down
11 changes: 3 additions & 8 deletions driver-core/src/main/java/com/datastax/driver/core/CBUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,17 @@ public static byte[] readBytes(ByteBuf cb) {
}
}

public static void writeBytes(byte[] bytes, ByteBuf cb) {
public static void writeShortBytes(byte[] bytes, ByteBuf cb) {
cb.writeShort(bytes.length);
cb.writeBytes(bytes);
}

public static void writeBytes(ByteBuffer bytes, ByteBuf cb) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unused methods, while they might be useful in future, would be easy to reimplement them.

cb.writeShort(bytes.remaining());
cb.writeBytes(bytes.duplicate());
}

public static int sizeOfBytes(byte[] bytes) {
public static int sizeOfShortBytes(byte[] bytes) {
return 2 + bytes.length;
}

public static int sizeOfBytes(ByteBuffer bytes) {
return 2 + bytes.remaining();
return 4 + bytes.remaining();
}

public static Map<String, ByteBuffer> readBytesMap(ByteBuf cb) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ protected void encode(ChannelHandlerContext ctx, Request request, List<Object> o
}

coder.encode(request, body, protocolVersion);
if (body.capacity() != messageSize) {
logger.warn("Detected buffer resizing while encoding {} message ({} => {}), " +
"this is a driver bug " +
"(ultimately it does not affect the query, but leads to a small inefficiency)",
request.type, messageSize, body.capacity());
}
out.add(Frame.create(protocolVersion, request.type.opcode, request.getStreamId(), flags, body));
}
}
Expand Down
14 changes: 7 additions & 7 deletions driver-core/src/main/java/com/datastax/driver/core/Requests.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,17 @@ static class Execute extends Message.Request {
static final Message.Coder<Execute> coder = new Message.Coder<Execute>() {
@Override
public void encode(Execute msg, ByteBuf dest, ProtocolVersion version) {
CBUtil.writeBytes(msg.statementId.bytes, dest);
CBUtil.writeShortBytes(msg.statementId.bytes, dest);
if (ProtocolFeature.PREPARED_METADATA_CHANGES.isSupportedBy(version))
CBUtil.writeBytes(msg.resultMetadataId.bytes, dest);
CBUtil.writeShortBytes(msg.resultMetadataId.bytes, dest);
msg.options.encode(dest, version);
}

@Override
public int encodedSize(Execute msg, ProtocolVersion version) {
int size = CBUtil.sizeOfBytes(msg.statementId.bytes);
int size = CBUtil.sizeOfShortBytes(msg.statementId.bytes);
if (ProtocolFeature.PREPARED_METADATA_CHANGES.isSupportedBy(version))
size += CBUtil.sizeOfBytes(msg.resultMetadataId.bytes);
size += CBUtil.sizeOfShortBytes(msg.resultMetadataId.bytes);
size += msg.options.encodedSize(version);
return size;
}
Expand Down Expand Up @@ -402,7 +402,7 @@ int encodedSize(ProtocolVersion version) {
size += CBUtil.sizeOfValue(pagingState);
if (flags.contains(QueryFlag.SERIAL_CONSISTENCY))
size += CBUtil.sizeOfConsistencyLevel(serialConsistency);
if (version == ProtocolVersion.V3 && flags.contains(QueryFlag.DEFAULT_TIMESTAMP))
if (version.compareTo(ProtocolVersion.V3) >= 0 && flags.contains(QueryFlag.DEFAULT_TIMESTAMP))
size += 8;
return size;
default:
Expand Down Expand Up @@ -434,7 +434,7 @@ public void encode(Batch msg, ByteBuf dest, ProtocolVersion version) {
if (q instanceof String)
CBUtil.writeLongString((String) q, dest);
else
CBUtil.writeBytes(((MD5Digest) q).bytes, dest);
CBUtil.writeShortBytes(((MD5Digest) q).bytes, dest);

CBUtil.writeValueList(msg.values.get(i), dest);
}
Expand All @@ -449,7 +449,7 @@ public int encodedSize(Batch msg, ProtocolVersion version) {
Object q = msg.queryOrIdList.get(i);
size += 1 + (q instanceof String
? CBUtil.sizeOfLongString((String) q)
: CBUtil.sizeOfBytes(((MD5Digest) q).bytes));
: CBUtil.sizeOfShortBytes(((MD5Digest) q).bytes));

size += CBUtil.sizeOfValueList(msg.values.get(i));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ public void should_print_log_message_when_level_trace() throws Exception {
session().execute(statement);
String logs = appender.waitAndGet(10000);
assertThat(logs)
.contains("Sending payload: {k1:0x010203, k2:0x040506} (20 bytes total)")
.contains("Received payload: {k1:0x010203, k2:0x040506} (20 bytes total)");
.contains("Sending payload: {k1:0x010203, k2:0x040506} (24 bytes total)")
.contains("Received payload: {k1:0x010203, k2:0x040506} (24 bytes total)");
} finally {
logger.setLevel(null);
logger.removeAppender(appender);
Expand Down