Skip to content

Commit

Permalink
server: Change zlib compression level (#47387)
Browse files Browse the repository at this point in the history
close #47278
  • Loading branch information
dveeden authored Oct 3, 2023
1 parent 95378e5 commit ddee0a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion server/internal/packetio.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,13 @@ func (cw *compressedWriter) Flush() error {
// https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_compression_packet.html
// suggests a MIN_COMPRESS_LENGTH of 50.
minCompressLength := 50
zlibCompressDefaultLevel := 6
data := cw.buf.Bytes()
cw.buf.Reset()

switch cw.compressionAlgorithm {
case mysql.CompressionZlib:
w, err = zlib.NewWriterLevel(&payload, zlib.HuffmanOnly)
w, err = zlib.NewWriterLevel(&payload, zlibCompressDefaultLevel)
case mysql.CompressionZstd:
w, err = zstd.NewWriter(&payload, zstd.WithEncoderLevel(cw.zstdLevel))
default:
Expand Down
4 changes: 2 additions & 2 deletions server/internal/packetio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ func TestCompressedWriterLong(t *testing.T) {
cw.Flush()

// Header:
// 3c 00 00 Compressed length: 60
// 18 00 00 Compressed length: 24
// 00 Packetnr: 0
// 45 00 00 Uncompressed length: 69
compressedLength := []byte{0x3c, 0x0, 0x0}
compressedLength := []byte{0x18, 0x0, 0x0}
packetNr := []byte{0x0}
uncompressedLength := []byte{0x45, 0x0, 0x0}
require.Equal(t, compressedLength, testdata.Bytes()[:3])
Expand Down

0 comments on commit ddee0a5

Please sign in to comment.