Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for additional compressors/decompressors #7978

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ require (
github.com/go-sql-driver/mysql v1.5.1-0.20210202043019-fe2230a8b20c
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/mock v1.5.0
github.com/golang/snappy v0.0.3
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.1
github.com/google/go-cmp v0.5.5
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.1.2
Expand All @@ -48,7 +48,7 @@ require (
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428
github.com/imdario/mergo v0.3.6 // indirect
github.com/jmoiron/sqlx v1.2.0
github.com/klauspost/compress v1.4.1 // indirect
github.com/klauspost/compress v1.13.0
github.com/klauspost/cpuid v1.2.0 // indirect
github.com/klauspost/pgzip v1.2.4
github.com/krishicks/yaml-patch v0.0.10
Expand All @@ -70,6 +70,7 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pborman/uuid v1.2.0
github.com/philhofer/fwd v1.0.0 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible
github.com/pires/go-proxyproto v0.0.0-20191211124218-517ecdf5bb2b
github.com/pkg/errors v0.9.1
github.com/planetscale/pargzip v0.0.0-20201116224723-90c7fc03ea8a
Expand Down Expand Up @@ -98,12 +99,12 @@ require (
go.etcd.io/etcd/pkg/v3 v3.5.0-alpha.0
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/text v0.3.5
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
golang.org/x/tools v0.1.0
golang.org/x/tools v0.1.2
google.golang.org/api v0.45.0
google.golang.org/grpc v1.37.0
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
Expand Down
17 changes: 17 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
Expand Down Expand Up @@ -478,6 +480,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.4.1 h1:8VMb5+0wMgdBykOV96DwNwKFQ+WTI4pzYURP99CcB9E=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.13.0 h1:2T7tUoQrQT+fQWdaY5rjWztFGAFwbGD04iPJg90ZiOs=
github.com/klauspost/compress v1.13.0/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/pgzip v1.2.4 h1:TQ7CNpYKovDOmqzRHKxJh0BeaBI7UdQZYc6p7pMQh1A=
Expand Down Expand Up @@ -602,6 +606,9 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/philhofer/fwd v1.0.0 h1:UbZqGr5Y38ApvM/V/jEljVxwocdweyH+vmYvRPBnbqQ=
github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/pierrec/lz4 v1.0.1 h1:w6GMGWSsCI04fTM8wQRdnW74MuJISakuUU0onU0TYB4=
github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM=
github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pires/go-proxyproto v0.0.0-20191211124218-517ecdf5bb2b h1:JPLdtNmpXbWytipbGwYz7zXZzlQNASEiFw5aGAM75us=
github.com/pires/go-proxyproto v0.0.0-20191211124218-517ecdf5bb2b/go.mod h1:Odh9VFOZJCf9G8cLW5o435Xf1J95Jw9Gw5rnCjcwzAY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -733,6 +740,7 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/z-division/go-zookeeper v0.0.0-20190128072838-6d7457066b9b h1:Itr7GbuXoM1PK/eCeNNia4Qd3ib9IgX9g9SpXgo8BwQ=
github.com/z-division/go-zookeeper v0.0.0-20190128072838-6d7457066b9b/go.mod h1:JNALoWa+nCXR8SmgLluHcBNVJgyejzpKPZk9pX2yXXE=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
Expand Down Expand Up @@ -822,6 +830,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1 h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -872,6 +882,8 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4 h1:b0LrWgu8+q7z4J+0Y3Umo5q1dL7NXBkKBWkaVkAq17E=
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -954,8 +966,11 @@ golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750 h1:ZBu6861dZq7xBnG1bn5SRU0vA8nx42at4+kP07FMTog=
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -1034,6 +1049,8 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
254 changes: 254 additions & 0 deletions go/vt/mysqlctl/compression.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
package mysqlctl
Copy link
Contributor

Choose a reason for hiding this comment

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

this file is missing the copyright notice


import (
"context"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"os/exec"
"strings"
"sync"

"github.com/klauspost/compress/zstd"
"github.com/klauspost/pgzip"
"github.com/pierrec/lz4"
"github.com/planetscale/pargzip"

"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/vterrors"
)

var (
compressionLevel = flag.Int("compression_level", 1, "What level to pass to the compressor")

errUnsupportedCompressionEngine = errors.New("unsupported engine")
errUnsupportedCompressionExtension = errors.New("unsupported extension")

// this is use by getEngineFromExtension() to figure out which engine to use in case the user didn't specify
engineExtensions = map[string][]string{
".gz": {"pgzip", "pargzip"},
".lz4": {"lz4"},
".zst": {"zstd"},
}
)

func getEngineFromExtension(extension string) (string, error) {
for ext, eng := range engineExtensions {
if ext == extension {
return eng[0], nil // we select the first supported engine in auto mode
}
}

return "", fmt.Errorf("%w \"%s\"", errUnsupportedCompressionExtension, extension)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Anywhere where you have \"%s\" in a format string, you can replace it with %q, which adds the quotes automatically and escapes the contents of the string so they always look proper inside the quotes. 👌

Copy link
Contributor Author

Choose a reason for hiding this comment

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

neat, I will change that!

}

func getExtensionFromEngine(engine string) (string, error) {
for ext, eng := range engineExtensions {
for _, e := range eng {
if e == engine {
return ext, nil
}
}
}

return "", fmt.Errorf("%w \"%s\"", errUnsupportedCompressionEngine, engine)
}

// Validates if the external decompressor exists and return its path.
func validateExternalCmd(cmd string) (string, error) {
if cmd == "" {
return "", errors.New("external command is empty")
}

return exec.LookPath(cmd)
}

func prepareExternalCompressionCmd(ctx context.Context, cmdStr string) (*exec.Cmd, error) {
cmdArgs := strings.Split(cmdStr, " ")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't perfectly cromulent; it will corrupt argument strings with quotes or escaped whitespace. I would suggest bringing https://pkg.go.dev/github.com/google/shlex as a (tiny) dependency to parse the commandline properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I will take a look at it and make the changes 👍

if len(cmdArgs) < 1 {
return nil, errors.New("external command is empty")
}

cmdPath, err := validateExternalCmd(cmdArgs[0])
if err != nil {
return nil, err
}

return exec.CommandContext(ctx, cmdPath, cmdArgs[1:]...), nil
}

// This returns a writer that writes the compressed output of the external command to the provided writer.
// It is important to wait on the WaitGroup provided to make sure that even after closing the writer,
// the command will have processed its input buffer, otherwise not all data might have been written to the target writer.
func newExternalCompressor(ctx context.Context, cmdStr string, writer io.Writer, wg *sync.WaitGroup, logger logutil.Logger) (compressor io.WriteCloser, err error) {
logger.Infof("Compressing using external command: \"%s\"", cmdStr)

cmd, err := prepareExternalCompressionCmd(ctx, cmdStr)
if err != nil {
return compressor, vterrors.Wrap(err, "unable to start external command")
}

cmd.Stdout = writer

cmdIn, err := cmd.StdinPipe()
if err != nil {
return compressor, vterrors.Wrap(err, "cannot create external ompressor stdin pipe")
}

cmdErr, err := cmd.StderrPipe()
if err != nil {
return compressor, vterrors.Wrap(err, "cannot create external ompressor stderr pipe")
}

if err := cmd.Start(); err != nil {
return compressor, vterrors.Wrap(err, "can't start external decompressor")
}

compressor = cmdIn

wg.Add(2) // one for the logger, another one for the go func below
go scanLinesToLogger("compressor stderr", cmdErr, logger, wg.Done)

go func() {
// log the exit status
if err := cmd.Wait(); err != nil {
logger.Errorf("external compressor failed: %v", err)
}
wg.Done()
}()

return
}

// This returns a reader that reads the compressed input and passes it to the external command to be decompressed. Calls to its
// Read() will return the uncompressed data until EOF.
func newExternalDecompressor(ctx context.Context, cmdStr string, reader io.Reader, logger logutil.Logger) (decompressor io.ReadCloser, err error) {
var decompressorWg sync.WaitGroup

logger.Infof("Decompressing using external command: \"%s\"", cmdStr)

cmd, err := prepareExternalCompressionCmd(ctx, cmdStr)
if err != nil {
return decompressor, vterrors.Wrap(err, "unable to start external command")
}

cmd.Stdin = reader

cmdOut, err := cmd.StdoutPipe()
if err != nil {
return decompressor, vterrors.Wrap(err, "cannot create external decompressor stdout pipe")
}

cmdErr, err := cmd.StderrPipe()
if err != nil {
return decompressor, vterrors.Wrap(err, "cannot create external decompressor stderr pipe")
}

if err := cmd.Start(); err != nil {
return decompressor, vterrors.Wrap(err, "can't start external decompressor")
}

decompressorWg.Add(1)
go scanLinesToLogger("decompressor stderr", cmdErr, logger, decompressorWg.Done)

decompressor = cmdOut

go func() {
decompressorWg.Wait()
// log the exit status
if err := cmd.Wait(); err != nil {
logger.Errorf("external compressor failed: %v", err)
}
}()

return
}

// This returns a reader that will decompress the underlying provided reader and will use the specified supported engine (or
// try to detect which one to use based on the extension if the default "auto" is used.
func newBuiltinDecompressor(engine, extension string, reader io.Reader, logger logutil.Logger) (decompressor io.ReadCloser, err error) {
if engine == "auto" {
logger.Infof("Builtin decompressor set to auto, checking which engine to decompress based on the extension")

eng, err := getEngineFromExtension(extension)
if err != nil {
return decompressor, err
}

engine = eng
}

switch engine {
case "pgzip":
d, err := pgzip.NewReader(reader)
if err != nil {
return nil, err
}
decompressor = d
case "pargzip":
err = errors.New("engine pargzip does not support decompression")
return decompressor, err
case "lz4":
decompressor = ioutil.NopCloser(lz4.NewReader(reader))
case "zstd":
d, err := zstd.NewReader(reader)
if err != nil {
return nil, err
}

decompressor = d.IOReadCloser()
default:
err = fmt.Errorf("Unkown decompressor engine: \"%s\"", engine)
return decompressor, err
}

logger.Infof("Decompressing backup using built-in engine \"%s\"", engine)

return decompressor, err
}

// This return a writer that will compress the data using the specified engine before writing to the underlying writer.
func newBuiltinCompressor(engine string, writer io.Writer, logger logutil.Logger) (compressor io.WriteCloser, err error) {
switch engine {
case "pgzip":
gzip, err := pgzip.NewWriterLevel(writer, *compressionLevel)
if err != nil {
return compressor, vterrors.Wrap(err, "cannot create gzip compressor")
}

gzip.SetConcurrency(*backupCompressBlockSize, *backupCompressBlocks)

compressor = gzip
case "pargzip":
gzip := pargzip.NewWriter(writer)
gzip.ChunkSize = *backupCompressBlockSize
gzip.Parallel = *backupCompressBlocks
gzip.CompressionLevel = *compressionLevel

compressor = gzip
case "lz4":
lz4Writer := lz4.NewWriter(writer).WithConcurrency(*backupCompressBlocks)
lz4Writer.Header = lz4.Header{
CompressionLevel: *compressionLevel,
}

compressor = lz4Writer
case "zstd":
// compressor = zstd.NewWriterLevel(writer, *compressionLevel)
zst, err := zstd.NewWriter(writer, zstd.WithEncoderLevel(zstd.EncoderLevel(*compressionLevel)))
if err != nil {
return compressor, vterrors.Wrap(err, "cannot create zstd compressor")
}

compressor = zst
default:
err = fmt.Errorf("Unkown compressor engine: \"%s\"", engine)
return compressor, err
}

logger.Infof("Compressing backup using built-in engine \"%s\"", engine)

return
}
Loading