Skip to content

Commit

Permalink
Go back to logging on failed stateless decoder creation
Browse files Browse the repository at this point in the history
And do it as a JiT allocation

Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Oct 22, 2024
1 parent 3a12360 commit e7191f0
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions go/mysql/binlog_event_compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package mysql
import (
"bytes"
"encoding/binary"
"fmt"
"io"
"sync"

Expand Down Expand Up @@ -92,14 +91,6 @@ var (
statefulDecoderPool = &decoderPool{}
)

func init() {
var err error
statelessDecoder, err = zstd.NewReader(nil, zstd.WithDecoderConcurrency(0))
if err != nil { // Should only happen e.g. due to ENOMEM
panic(fmt.Errorf("failed to create stateless decoder: %v", err))
}
}

type TransactionPayload struct {
size uint64
compressionType uint64
Expand Down Expand Up @@ -305,6 +296,13 @@ func (tp *TransactionPayload) decompress() error {
}

// Process smaller payloads using only in-memory buffers.
if statelessDecoder == nil { // Should only need to be done once
var err error
statelessDecoder, err = zstd.NewReader(nil, zstd.WithDecoderConcurrency(0))
if err != nil { // Should only happen e.g. due to ENOMEM
return vterrors.Wrap(err, "failed to create stateless decoder")
}
}
decompressedBytes := make([]byte, 0, tp.uncompressedSize) // Perform a single pre-allocation
decompressedBytes, err := statelessDecoder.DecodeAll(tp.payload, decompressedBytes[:0])
if err != nil {
Expand Down

0 comments on commit e7191f0

Please sign in to comment.