From 8c23346f55c3ec113a95fdbe2b124b224e44d307 Mon Sep 17 00:00:00 2001 From: Derek Su Date: Thu, 6 Jul 2023 12:06:55 +0800 Subject: [PATCH] Fix strict-local volume restore stuck in attaching state For a volume being restored, the spec.nodeID is empyty but the status.ownerID is set. Thus, set r.Spec.HardNodeAffinity to volume.status.ownerID instead. Longhorn 6239 Signed-off-by: Derek Su --- controller/volume_controller.go | 11 +++++++---- types/types.go | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/controller/volume_controller.go b/controller/volume_controller.go index 58edeb02a9..3f1f7fcc03 100644 --- a/controller/volume_controller.go +++ b/controller/volume_controller.go @@ -1208,11 +1208,14 @@ func (vc *VolumeController) ReconcileVolumeState(v *longhorn.Volume, es map[stri continue } if v.Spec.DataLocality == longhorn.DataLocalityStrictLocal { - if v.Spec.NodeID == "" { - continue + if v.Status.RestoreRequired { + r.Spec.HardNodeAffinity = v.Status.OwnerID + } else { + if v.Spec.NodeID == "" { + continue + } + r.Spec.HardNodeAffinity = v.Spec.NodeID } - - r.Spec.HardNodeAffinity = v.Spec.NodeID } scheduledReplica, multiError, err := vc.scheduler.ScheduleReplica(r, rs, v) diff --git a/types/types.go b/types/types.go index 9f41e156e5..490135582a 100644 --- a/types/types.go +++ b/types/types.go @@ -239,7 +239,7 @@ const ( ) // SettingsRelatedToVolume should match the items in datastore.GetLabelsForVolumesFollowsGlobalSettings -// TODO: May need to add the data locality check +// TODO: May need to add the data locality check var SettingsRelatedToVolume = map[string]string{ string(SettingNameReplicaAutoBalance): LonghornLabelValueIgnored, string(SettingNameSnapshotDataIntegrity): LonghornLabelValueIgnored, @@ -807,7 +807,8 @@ type DiskSpecWithName struct { // UnmarshalToDisks input format should be: // `[{"path":"/mnt/disk1","allowScheduling":false}, -// {"path":"/mnt/disk2","allowScheduling":false,"storageReserved":1024,"tags":["ssd","fast"]}]` +// +// {"path":"/mnt/disk2","allowScheduling":false,"storageReserved":1024,"tags":["ssd","fast"]}]` func UnmarshalToDisks(s string) (ret []DiskSpecWithName, err error) { if err := json.Unmarshal([]byte(s), &ret); err != nil { return nil, err