This is an automated email from the ASF dual-hosted git repository.
joaoreis pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-gocql-driver.git
The following commit(s) were added to refs/heads/trunk by this push:
new 0089073b Prevent setting a compression flag in a frame header when
native proto v5 is being used
0089073b is described below
commit 0089073b21049a32fa380f4b626752378896de86
Author: Bohdan <[email protected]>
AuthorDate: Tue Nov 18 12:37:39 2025 +0200
Prevent setting a compression flag in a frame header when native proto v5
is being used
Previously, during frame construction, the driver was setting the frame
compression flag for each frame if a compressor is set in the ClusterConfig.
However, for the Native Protocol 5 version the compression flag is deprecated.
While Cassandra 4.0 just ignores this flag, some other third-party applications
that rely on v5 proto could experience errors as the body of the frame is not
actually compressed.
Now it adds the compression flag only if the compressor is set and proto
version < 5.
Patch by Bohdan Siryk; Reviewed by João Reis for CASSGO-98
---
CHANGELOG.md | 1 +
frame.go | 2 +-
frame_test.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9a1eab05..cd327073 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ and this project adheres to [Semantic
Versioning](https://semver.org/spec/v2.0.0
- Prevent panic with queries during session init (CASSGO-92)
- Return correct values from RowData (CASSGO-95)
+- Prevent setting a compression flag in a frame header when native proto v5 is
being used (CASSGO-98)
## [2.0.0]
diff --git a/frame.go b/frame.go
index 403da877..e86c538c 100644
--- a/frame.go
+++ b/frame.go
@@ -393,7 +393,7 @@ func newFramer(compressor Compressor, version byte, r
*RegisteredTypes) *framer
types: r,
}
var flags byte
- if compressor != nil {
+ if compressor != nil && version < protoVersion5 {
flags |= flagCompress
}
diff --git a/frame_test.go b/frame_test.go
index e7a8bb4b..26430beb 100644
--- a/frame_test.go
+++ b/frame_test.go
@@ -34,6 +34,8 @@ import (
"reflect"
"testing"
+ "github.com/apache/cassandra-gocql-driver/v2/lz4"
+ "github.com/apache/cassandra-gocql-driver/v2/snappy"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -836,3 +838,58 @@ func BenchmarkFramerReadCol_Set(b *testing.B) {
_ = framer.readCol(&col, nil, true, "", "")
}
}
+
+func Test_newFrame_compressionFlag(t *testing.T) {
+ tests := []struct {
+ name string
+ protoVersion protoVersion
+ compressor Compressor
+ expectedFlags byte
+ }{
+ {
+ name: "proto3-nil-compressor",
+ protoVersion: protoVersion3,
+ compressor: nil,
+ expectedFlags: 0, // no flags
+ },
+ {
+ name: "proto3-snappy-compressor",
+ protoVersion: protoVersion3,
+ compressor: snappy.SnappyCompressor{},
+ expectedFlags: 0b1, // compressions is enabled
+ },
+ {
+ name: "proto4-nil-compressor",
+ protoVersion: protoVersion4,
+ compressor: nil,
+ expectedFlags: 0,
+ },
+ {
+ name: "proto4-snappy-compressor",
+ protoVersion: protoVersion4,
+ compressor: snappy.SnappyCompressor{},
+ expectedFlags: 0b1,
+ },
+ {
+ name: "proto5-nil-compressor",
+ protoVersion: protoVersion5,
+ compressor: nil,
+ expectedFlags: 0,
+ },
+ {
+ // In protocol v5 compression happens on the segment
level (v5 new frame format). The body of the frame (envelope)
+ // is not compressed, so we don't have to set
compression flag in the frame header
+ name:
"proto5-lz4-compressor-no-compression-flag",
+ protoVersion: protoVersion5,
+ compressor: lz4.LZ4Compressor{},
+ expectedFlags: 0,
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ f := newFramer(test.compressor,
byte(test.protoVersion), GlobalTypes)
+ require.Equal(t, test.expectedFlags, f.flags)
+ })
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]