Skip to content

Commit

Permalink
Refactor updateReplicaLogRequested()
Browse files Browse the repository at this point in the history
Longhorn 3957

Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit committed Nov 25, 2022
1 parent 6504800 commit bcd70a0
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions controller/volume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,20 @@ func (vc *VolumeController) getAutoBalancedReplicasSetting(v *longhorn.Volume) (
return setting, errors.Wrapf(err, "replica auto-balance is disabled")
}

func (vc *VolumeController) updateReplicaLogRequested(e *longhorn.Engine, rs map[string]*longhorn.Replica) {
needReplicaLogs := false
for _, r := range rs {
if r.Spec.LogRequested && r.Status.LogFetched {
r.Spec.LogRequested = false
}
needReplicaLogs = needReplicaLogs || r.Spec.LogRequested
rs[r.Name] = r
}
if e.Spec.LogRequested && e.Status.LogFetched && !needReplicaLogs {
e.Spec.LogRequested = false
}
}

// ReconcileVolumeState handles the attaching and detaching of volume
func (vc *VolumeController) ReconcileVolumeState(v *longhorn.Volume, es map[string]*longhorn.Engine, rs map[string]*longhorn.Replica) (err error) {
defer func() {
Expand Down Expand Up @@ -1124,17 +1138,7 @@ func (vc *VolumeController) ReconcileVolumeState(v *longhorn.Volume, es map[stri
}
}

needReplicaLogs := false
for _, r := range rs {
if r.Spec.LogRequested && r.Status.LogFetched {
r.Spec.LogRequested = false
}
needReplicaLogs = needReplicaLogs || r.Spec.LogRequested
rs[r.Name] = r
}
if e.Spec.LogRequested && e.Status.LogFetched && !needReplicaLogs {
e.Spec.LogRequested = false
}
vc.updateReplicaLogRequested(e, rs)

scheduled := true
aggregatedReplicaScheduledError := util.NewMultiError()
Expand Down

0 comments on commit bcd70a0

Please sign in to comment.