Skip to content

Commit

Permalink
fix(backup): skip loading the backingFile when doing backup or when u…
Browse files Browse the repository at this point in the history
…ser request

exporting the volume without backingFile

longhorn-9209

Signed-off-by: Phan Le <phan.le@suse.com>
(cherry picked from commit 449c3bd)
  • Loading branch information
PhanLe1010 authored and derekbit committed Aug 14, 2024
1 parent 53c6d3e commit 6367c0b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
9 changes: 7 additions & 2 deletions pkg/replica/diff_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/replica/extents.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/replica/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,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) {
Expand Down

0 comments on commit 6367c0b

Please sign in to comment.