Skip to content

Improve migration #1878

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

Merged
merged 2 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions cmd/incusd/migrate_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func newMigrationSource(inst instance.Instance, stateful bool, instanceOnly bool
func (s *migrationSourceWs) Do(state *state.State, migrateOp *operations.Operation) error {
l := logger.AddContext(logger.Ctx{"project": s.instance.Project().Name, "instance": s.instance.Name(), "live": s.live, "clusterMoveSourceName": s.clusterMoveSourceName, "push": s.pushOperationURL != ""})

ctx, cancel := context.WithTimeout(context.TODO(), time.Second*10)
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*30)
defer cancel()

l.Debug("Waiting for migration control connection on source")
Expand Down Expand Up @@ -216,7 +216,7 @@ func newMigrationSink(args *migrationSinkArgs) (*migrationSink, error) {
func (c *migrationSink) Do(state *state.State, instOp *operationlock.InstanceOperation) error {
l := logger.AddContext(logger.Ctx{"project": c.instance.Project().Name, "instance": c.instance.Name(), "live": c.live, "clusterMoveSourceName": c.clusterMoveSourceName, "push": c.push})

ctx, cancel := context.WithTimeout(context.TODO(), time.Second*10)
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*30)
defer cancel()

l.Debug("Waiting for migration control connection on target")
Expand Down
4 changes: 2 additions & 2 deletions cmd/incusd/migrate_storage_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func newStorageMigrationSource(volumeOnly bool, pushTarget *api.StorageVolumePos
func (s *migrationSourceWs) DoStorage(state *state.State, projectName string, poolName string, volName string, migrateOp *operations.Operation) error {
l := logger.AddContext(logger.Ctx{"project": projectName, "pool": poolName, "volume": volName, "push": s.pushOperationURL != ""})

ctx, cancel := context.WithTimeout(state.ShutdownCtx, time.Second*10)
ctx, cancel := context.WithTimeout(state.ShutdownCtx, time.Second*30)
defer cancel()

l.Info("Waiting for migration connections on source")
Expand Down Expand Up @@ -289,7 +289,7 @@ func newStorageMigrationSink(args *migrationSinkArgs) (*migrationSink, error) {
func (c *migrationSink) DoStorage(state *state.State, projectName string, poolName string, req *api.StorageVolumesPost, op *operations.Operation) error {
l := logger.AddContext(logger.Ctx{"project": projectName, "pool": poolName, "volume": req.Name, "push": c.push})

ctx, cancel := context.WithTimeout(state.ShutdownCtx, time.Second*10)
ctx, cancel := context.WithTimeout(state.ShutdownCtx, time.Second*30)
defer cancel()

l.Info("Waiting for migration connections on target")
Expand Down
14 changes: 10 additions & 4 deletions internal/server/instance/drivers/driver_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -6714,6 +6714,7 @@ func (d *qemu) MigrateSend(args instance.MigrateSendArgs) error {
}

clusterMove := args.ClusterMoveSourceName != ""
remoteClusterMove := clusterMove && pool.Driver().Info().Remote
storageMove := args.StoragePool != ""

// The refresh argument passed to MigrationTypes() is always set
Expand Down Expand Up @@ -6762,12 +6763,17 @@ func (d *qemu) MigrateSend(args instance.MigrateSendArgs) error {

for i := range srcConfig.Snapshots {
offerHeader.SnapshotNames = append(offerHeader.SnapshotNames, srcConfig.Snapshots[i].Name)
snapSize, err := storagePools.CalculateVolumeSnapshotSize(d.Project().Name, pool, contentType, storageDrivers.VolumeTypeVM, d.Name(), srcConfig.Snapshots[i].Name)
if err != nil {
return err

// Calculating snapshot size can be very slow, skip unless absolutely needed.
if !remoteClusterMove || storageMove {
snapSize, err := storagePools.CalculateVolumeSnapshotSize(d.Project().Name, pool, contentType, storageDrivers.VolumeTypeVM, d.Name(), srcConfig.Snapshots[i].Name)
if err != nil {
return err
}

srcConfig.Snapshots[i].Config["size"] = fmt.Sprintf("%d", snapSize)
}

srcConfig.Snapshots[i].Config["size"] = fmt.Sprintf("%d", snapSize)
offerHeader.Snapshots = append(offerHeader.Snapshots, instance.SnapshotToProtobuf(srcConfig.Snapshots[i]))
}
}
Expand Down
Loading