Skip to content

Commit

Permalink
Merge pull request #12983 from roosterfish/custom_sv_order
Browse files Browse the repository at this point in the history
Storage: Pass custom storage volume snapshots in the right order
  • Loading branch information
tomponline authored Feb 29, 2024
2 parents 6706c52 + 28c2dad commit fd7d44e
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions lxd/storage/backend_lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1279,17 +1279,6 @@ func (b *lxdBackend) RefreshCustomVolume(projectName string, srcProjectName stri
srcConfig.VolumeSnapshots = nil
}

targetSnaps, err := VolumeDBSnapshotsGet(b, projectName, volName, drivers.VolumeTypeCustom)
if err != nil {
return err
}

targetSnapshots := make([]drivers.Volume, 0, len(targetSnaps))
for _, targetSnap := range targetSnaps {
snapshotStorageName := project.StorageVolume(projectName, targetSnap.Name)
targetSnapshots = append(targetSnapshots, b.GetVolume(drivers.VolumeTypeCustom, contentType, snapshotStorageName, targetSnap.Config))
}

revert := revert.New()
defer revert.Fail()

Expand All @@ -1306,6 +1295,12 @@ func (b *lxdBackend) RefreshCustomVolume(projectName string, srcProjectName stri
})
}

// Get a list of already existing snapshots on the target volume.
targetSnaps, err := VolumeDBSnapshotsGet(b, projectName, volName, drivers.VolumeTypeCustom)
if err != nil {
return err
}

targetSnapshotsComparable := make([]ComparableSnapshot, 0, len(targetSnaps))
for _, targetSnap := range targetSnaps {
_, targetSnapName, _ := api.GetParentAndSnapshotName(targetSnap.Name)
Expand Down Expand Up @@ -1372,13 +1367,25 @@ func (b *lxdBackend) RefreshCustomVolume(projectName string, srcProjectName stri

revert.Add(func() { _ = VolumeDBDelete(b, projectName, newSnapshotName, vol.Type()) })

// Extend the list of target snaphots to not require loading all of them again from DB.
targetSnapshots = append(targetSnapshots, targetSnapVol)

// Extend the list of snapshots that require refresh.
srcSnapVols = append(srcSnapVols, srcSnap.Name)
}

// Reload the final target volume's snapshots.
// Some snapshots might have been removed from the target volume if they aren't anymore present on the source volume.
// Other snapshots might require a refresh if they have been deleted from the target volume in the meantime.
// Get the snapshots directly from the database to ensure they are in the right order.
targetSnaps, err := VolumeDBSnapshotsGet(b, projectName, volName, drivers.VolumeTypeCustom)
if err != nil {
return err
}

targetSnapshots := make([]drivers.Volume, 0, len(targetSnaps))
for _, targetSnap := range targetSnaps {
snapshotStorageName := project.StorageVolume(projectName, targetSnap.Name)
targetSnapshots = append(targetSnapshots, b.GetVolume(drivers.VolumeTypeCustom, contentType, snapshotStorageName, targetSnap.Config))
}

volCopy := drivers.NewVolumeCopy(vol, targetSnapshots...)
srcVolCopy := drivers.NewVolumeCopy(srcVol, sourceSnapshots...)

Expand Down

0 comments on commit fd7d44e

Please sign in to comment.