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

Fix and optimize restoration of delta snapshots #609

Merged
merged 7 commits into from
Apr 5, 2023
17 changes: 9 additions & 8 deletions pkg/snapshot/restorer/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,31 +796,32 @@ func verifySnapshotRevision(clientKV client.KVCloser, snap *brtypes.Snapshot) er
return nil
}

// getDecompressedSnapshotReadCloser passes the given ReadCloser through the
// getNormalizedSnapshotReadCloser passes the given ReadCloser through the
// snapshot decompressor if the snapshot is compressed using a compression policy.
// Also returns whether the snapshot was initially compressed or not, as well as
// If snapshot is not compressed, it returns the given ReadCloser as is.
// It also returns whether the snapshot was initially compressed or not, as well as
// the compression policy used for compressing the snapshot.
func getDecompressedSnapshotReadCloser(rc io.ReadCloser, snap *brtypes.Snapshot) (io.ReadCloser, bool, string, error) {
func getNormalizedSnapshotReadCloser(rc io.ReadCloser, snap *brtypes.Snapshot) (io.ReadCloser, bool, string, error) {
isCompressed, compressionPolicy, err := compressor.IsSnapshotCompressed(snap.CompressionSuffix)
if err != nil {
return nil, false, compressionPolicy, err
return rc, false, "", err
}

if isCompressed {
// decompress the snapshot
rc, err = compressor.DecompressSnapshot(rc, compressionPolicy)
if err != nil {
return nil, true, compressionPolicy, fmt.Errorf("unable to decompress the snapshot: %v", err)
return rc, true, compressionPolicy, fmt.Errorf("unable to decompress the snapshot: %v", err)
aaronfern marked this conversation as resolved.
Show resolved Hide resolved
}
}

return rc, true, compressionPolicy, nil
return rc, false, "", nil
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
}

func (r *Restorer) readSnapshotContentsFromReadCloser(rc io.ReadCloser, snap *brtypes.Snapshot) ([]byte, error) {
startTime := time.Now()

rc, wasCompressed, compressionPolicy, err := getDecompressedSnapshotReadCloser(rc, snap)
rc, wasCompressed, compressionPolicy, err := getNormalizedSnapshotReadCloser(rc, snap)
if err != nil {
return nil, fmt.Errorf("failed to decompress delta snapshot %s : %v", snap.SnapName, err)
}
Expand All @@ -835,7 +836,7 @@ func (r *Restorer) readSnapshotContentsFromReadCloser(rc io.ReadCloser, snap *br
if wasCompressed {
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
r.logger.Infof("successfully decompressed data of delta snapshot in %v seconds [CompressionPolicy:%v]", totalTime, compressionPolicy)
} else {
r.logger.Infof("successfully decompressed data of delta snapshot in %v seconds", totalTime)
r.logger.Infof("successfully read the data of delta snapshot in %v seconds", totalTime)
}

if bufSize <= sha256.Size {
Expand Down