From 1c9eb4996f88a0aae04fc886003c86867050f9ad Mon Sep 17 00:00:00 2001 From: Phan Le Date: Mon, 12 Aug 2024 19:55:18 -0700 Subject: [PATCH] fix(backup): skip loading the backingFile when doing backup or when user request exporting the volume without backingFile longhorn-9209 Signed-off-by: Phan Le (cherry picked from commit 449c3bde4036a0037d94eb9115bb7961f63e3c2e) --- pkg/replica/diff_disk.go | 9 +++++++-- pkg/replica/extents.go | 5 ----- pkg/replica/replica.go | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/replica/diff_disk.go b/pkg/replica/diff_disk.go index 1134a7fad..4be04ff13 100644 --- a/pkg/replica/diff_disk.go +++ b/pkg/replica/diff_disk.go @@ -20,7 +20,7 @@ type diffDisk struct { // we don't know the location yet. location []byte // list of files in grandparent, parent, child, etc order. - // index 0 is nil or backing file and index n-1 is the active write layer + // index 0 is nil, index 1 is backing file, and index n-1 is the active write layer files []types.DiffDisk sectorSize int64 // current size of the head file. @@ -372,12 +372,17 @@ func (d *diffDisk) initializeSectorLocation(value byte) { } } -func (d *diffDisk) preload() error { +func (d *diffDisk) preload(isThereBackingFile bool) error { for i, f := range d.files { if i == 0 { continue } + // Skip loading the backingFile if it exists + if i == int(backingFileIndex) && isThereBackingFile { + continue + } + if err := LoadDiffDiskLocationList(d, f, byte(i)); err != nil { return err } diff --git a/pkg/replica/extents.go b/pkg/replica/extents.go index 697f92a24..a82325fe8 100644 --- a/pkg/replica/extents.go +++ b/pkg/replica/extents.go @@ -11,11 +11,6 @@ const MaxExtentsBuffer = 1024 func LoadDiffDiskLocationList(diffDisk *diffDisk, disk types.DiffDisk, currentFileIndex byte) error { fd := disk.Fd() - // The backing file will have a Fd of 0 - if fd == 0 { - return nil - } - start := uint64(0) end := uint64(len(diffDisk.location)) * uint64(diffDisk.sectorSize) for { diff --git a/pkg/replica/replica.go b/pkg/replica/replica.go index 7e25ca5bd..ab836a8ff 100644 --- a/pkg/replica/replica.go +++ b/pkg/replica/replica.go @@ -1468,7 +1468,8 @@ func (r *Replica) Preload(includeBackingFileLayer bool) error { } else { r.volume.initializeSectorLocation(nilFileIndex) } - return r.volume.preload() + isThereBackingFile := r.info.BackingFile != nil + return r.volume.preload(isThereBackingFile) } func (r *Replica) GetDataLayout(ctx context.Context) (<-chan sparse.FileInterval, <-chan error, error) {