mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Sentry: always use "best speed" compression for save and remove the option.
PiperOrigin-RevId: 195835861 Change-Id: Ib696b1b571a6b061725a33c535cd7215fe518b97
This commit is contained in:
@@ -50,11 +50,6 @@ type SaveOpts struct {
|
||||
// Metadata is save metadata.
|
||||
Metadata map[string]string
|
||||
|
||||
// CompressionLevel is the compression level to use.
|
||||
//
|
||||
// See statefile.NewWriter for details.
|
||||
CompressionLevel int
|
||||
|
||||
// Callback is called prior to unpause, with any save error.
|
||||
Callback func(err error)
|
||||
}
|
||||
@@ -76,7 +71,7 @@ func (opts SaveOpts) Save(k *kernel.Kernel, w *watchdog.Watchdog) error {
|
||||
addSaveMetadata(opts.Metadata)
|
||||
|
||||
// Open the statefile.
|
||||
wc, err := statefile.NewWriter(opts.Destination, opts.Key, opts.Metadata, opts.CompressionLevel)
|
||||
wc, err := statefile.NewWriter(opts.Destination, opts.Key, opts.Metadata)
|
||||
if err != nil {
|
||||
err = ErrStateFile{err}
|
||||
} else {
|
||||
|
||||
@@ -45,6 +45,7 @@ package statefile
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/flate"
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
@@ -86,7 +87,7 @@ var ErrMetadataInvalid = fmt.Errorf("metadata invalid, can't start with _")
|
||||
// NewWriter returns a state data writer for a statefile.
|
||||
//
|
||||
// Note that the returned WriteCloser must be closed.
|
||||
func NewWriter(w io.Writer, key []byte, metadata map[string]string, compressionLevel int) (io.WriteCloser, error) {
|
||||
func NewWriter(w io.Writer, key []byte, metadata map[string]string) (io.WriteCloser, error) {
|
||||
if metadata == nil {
|
||||
metadata = make(map[string]string)
|
||||
}
|
||||
@@ -140,8 +141,11 @@ func NewWriter(w io.Writer, key []byte, metadata map[string]string, compressionL
|
||||
|
||||
w = hashio.NewWriter(w, h)
|
||||
|
||||
// Wrap in compression.
|
||||
return compressio.NewWriter(w, compressionChunkSize, compressionLevel)
|
||||
// Wrap in compression. We always use "best speed" mode here. When using
|
||||
// "best compression" mode, there is usually only a little gain in file
|
||||
// size reduction, which translate to even smaller gain in restore
|
||||
// latency reduction, while inccuring much more CPU usage at save time.
|
||||
return compressio.NewWriter(w, compressionChunkSize, flate.BestSpeed)
|
||||
}
|
||||
|
||||
// MetadataUnsafe reads out the metadata from a state file without verifying any
|
||||
|
||||
@@ -16,7 +16,6 @@ package statefile
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/flate"
|
||||
crand "crypto/rand"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
@@ -89,7 +88,7 @@ func TestStatefile(t *testing.T) {
|
||||
var bufDecoded bytes.Buffer
|
||||
|
||||
// Do all the writing.
|
||||
w, err := NewWriter(&bufEncoded, key, c.metadata, flate.BestSpeed)
|
||||
w, err := NewWriter(&bufEncoded, key, c.metadata)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating writer: got %v, expected nil", err)
|
||||
}
|
||||
@@ -195,7 +194,7 @@ func benchmark(b *testing.B, size int, write bool, compressible bool) {
|
||||
var stateBuf bytes.Buffer
|
||||
writeState := func() {
|
||||
stateBuf.Reset()
|
||||
w, err := NewWriter(&stateBuf, key, nil, flate.BestSpeed)
|
||||
w, err := NewWriter(&stateBuf, key, nil)
|
||||
if err != nil {
|
||||
b.Fatalf("error creating writer: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user