Skip to content
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

If volume is delinquent, switch owner of volume/engine/replica to share manager CR's owner (backport #3004) #3005

Merged
merged 1 commit into from
Jul 24, 2024
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
19 changes: 12 additions & 7 deletions controller/engine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2296,22 +2296,27 @@ func (ec *EngineController) isResponsibleFor(e *longhorn.Engine, defaultEngineIm
err = errors.Wrap(err, "error while checking isResponsibleFor")
}()

// If a regular RWX is delinquent, try to switch ownership quickly to the node of the newly created share-manager pod
isDelinquent, err := ec.ds.IsNodeDelinquent(e.Status.OwnerID, e.Spec.VolumeName)
// If a regular RWX is delinquent, try to switch ownership quickly to the owner node of the share manager CR
isOwnerNodeDelinquent, err := ec.ds.IsNodeDelinquent(e.Status.OwnerID, e.Spec.VolumeName)
if err != nil {
return false, err
}
if isDelinquent {
pod, err := ec.ds.GetPodRO(ec.namespace, types.GetShareManagerPodNameFromShareManagerName(e.Spec.VolumeName))
isSpecNodeDelinquent, err := ec.ds.IsNodeDelinquent(e.Spec.NodeID, e.Spec.VolumeName)
if err != nil {
return false, err
}
preferredOwnerID := e.Spec.NodeID
if isOwnerNodeDelinquent || isSpecNodeDelinquent {
sm, err := ec.ds.GetShareManager(e.Spec.VolumeName)
if err != nil && !apierrors.IsNotFound(err) {
return false, err
}
if pod != nil && ec.controllerID == pod.Spec.NodeName {
return true, nil
if sm != nil {
preferredOwnerID = sm.Status.OwnerID
}
}

isResponsible := isControllerResponsibleFor(ec.controllerID, ec.ds, e.Name, e.Spec.NodeID, e.Status.OwnerID)
isResponsible := isControllerResponsibleFor(ec.controllerID, ec.ds, e.Name, preferredOwnerID, e.Status.OwnerID)

// The engine is not running, the owner node doesn't need to have e.Status.CurrentImage
// Fall back to the default logic where we pick a running node to be the owner
Expand Down
19 changes: 12 additions & 7 deletions controller/replica_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,22 +918,27 @@ func (rc *ReplicaController) enqueueAllRebuildingReplicaOnCurrentNode() {
}

func (rc *ReplicaController) isResponsibleFor(r *longhorn.Replica) (bool, error) {
// If a regular RWX is delinquent, try to switch ownership quickly to the node of the newly created share-manager pod
isDelinquent, err := rc.ds.IsNodeDelinquent(r.Status.OwnerID, r.Spec.VolumeName)
// If a regular RWX is delinquent, try to switch ownership quickly to the owner node of the share manager CR
isOwnerNodeDelinquent, err := rc.ds.IsNodeDelinquent(r.Status.OwnerID, r.Spec.VolumeName)
if err != nil {
return false, err
}
if isDelinquent {
pod, err := rc.ds.GetPodRO(rc.namespace, types.GetShareManagerPodNameFromShareManagerName(r.Spec.VolumeName))
isSpecNodeDelinquent, err := rc.ds.IsNodeDelinquent(r.Spec.NodeID, r.Spec.VolumeName)
if err != nil {
return false, err
}
preferredOwnerID := r.Spec.NodeID
if isOwnerNodeDelinquent || isSpecNodeDelinquent {
sm, err := rc.ds.GetShareManager(r.Spec.VolumeName)
if err != nil && !apierrors.IsNotFound(err) {
return false, err
}
if pod != nil && rc.controllerID == pod.Spec.NodeName {
return true, nil
if sm != nil {
preferredOwnerID = sm.Status.OwnerID
}
}

return isControllerResponsibleFor(rc.controllerID, rc.ds, r.Name, r.Spec.NodeID, r.Status.OwnerID), nil
return isControllerResponsibleFor(rc.controllerID, rc.ds, r.Name, preferredOwnerID, r.Status.OwnerID), nil
}

func hasMatchingReplica(replica *longhorn.Replica, replicas map[string]*longhorn.Replica) bool {
Expand Down
19 changes: 12 additions & 7 deletions controller/volume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4362,22 +4362,27 @@ func (c *VolumeController) isResponsibleFor(v *longhorn.Volume, defaultEngineIma
err = errors.Wrap(err, "error while checking isResponsibleFor")
}()

// If a regular RWX is delinquent, try to switch ownership quickly to the node of the newly created share-manager pod
isDelinquent, err := c.ds.IsNodeDelinquent(v.Status.OwnerID, v.Name)
// If a regular RWX is delinquent, try to switch ownership quickly to the owner node of the share manager CR
isOwnerNodeDelinquent, err := c.ds.IsNodeDelinquent(v.Status.OwnerID, v.Name)
if err != nil {
return false, err
}
if isDelinquent {
pod, err := c.ds.GetPodRO(v.Namespace, types.GetShareManagerPodNameFromShareManagerName(v.Name))
isSpecNodeDelinquent, err := c.ds.IsNodeDelinquent(v.Spec.NodeID, v.Name)
if err != nil {
return false, err
}
preferredOwnerID := v.Spec.NodeID
if isOwnerNodeDelinquent || isSpecNodeDelinquent {
sm, err := c.ds.GetShareManager(v.Name)
if err != nil && !apierrors.IsNotFound(err) {
return false, err
}
if pod != nil && c.controllerID == pod.Spec.NodeName {
return true, nil
if sm != nil {
preferredOwnerID = sm.Status.OwnerID
}
}

isResponsible := isControllerResponsibleFor(c.controllerID, c.ds, v.Name, v.Spec.NodeID, v.Status.OwnerID)
isResponsible := isControllerResponsibleFor(c.controllerID, c.ds, v.Name, preferredOwnerID, v.Status.OwnerID)

if types.IsDataEngineV1(v.Spec.DataEngine) {
readyNodesWithDefaultEI, err := c.ds.ListReadyNodesContainingEngineImageRO(defaultEngineImage)
Expand Down