From 95de656d4c31d3a801f8a0b0634da47ba91e6b0a Mon Sep 17 00:00:00 2001 From: Phan Le Date: Mon, 18 Sep 2023 13:44:51 -0700 Subject: [PATCH] Fix bug two active engine when volume migrating Only switch the new engine to active if we finish cleaning up the extra engines longhorn-6642 Signed-off-by: Phan Le (cherry picked from commit eb1602c2eee20318f3343202ea87a4c67550358e) --- controller/volume_controller.go | 2 ++ datastore/longhorn.go | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/controller/volume_controller.go b/controller/volume_controller.go index a7a9a5a7c4..f3dfebd733 100644 --- a/controller/volume_controller.go +++ b/controller/volume_controller.go @@ -3802,6 +3802,8 @@ func (c *VolumeController) processMigration(v *longhorn.Volume, es map[string]*l } } + currentEngine.Spec.Active = true + // cleanupCorruptedOrStaleReplicas() will take care of old replicas if err := c.switchActiveReplicas(rs, func(r *longhorn.Replica, engineName string) bool { return r.Spec.EngineName == engineName diff --git a/datastore/longhorn.go b/datastore/longhorn.go index 9216a490cf..19299dcb9e 100644 --- a/datastore/longhorn.go +++ b/datastore/longhorn.go @@ -968,7 +968,12 @@ func GetCurrentEngineAndExtras(v *longhorn.Volume, es map[string]*longhorn.Engin if currentEngine == nil { logrus.Warnf("failed to directly pick up the current one from multiple engines for volume %v, fall back to detect the new current engine, "+ "current node %v, desire node %v", v.Name, v.Status.CurrentNodeID, v.Spec.NodeID) - return GetNewCurrentEngineAndExtras(v, es) + newCurrentEngine, extras, err := GetNewCurrentEngineAndExtras(v, es) + if err != nil { + return nil, nil, err + } + newCurrentEngine.Spec.Active = true + return newCurrentEngine, extras, nil } return } @@ -988,7 +993,6 @@ func GetNewCurrentEngineAndExtras(v *longhorn.Volume, es map[string]*longhorn.En return nil, nil, fmt.Errorf("BUG: found the second new active engine %v besides %v", e.Name, currentEngine.Name) } currentEngine = e - currentEngine.Spec.Active = true } else { extras = append(extras, e) }