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

Sort zmount workloads in descending order #2017

Merged
merged 3 commits into from
Aug 7, 2023
Merged

Conversation

AbdelrahmanElawady
Copy link
Contributor

Sort zmount workloads so larger disks get assigned first.

Related: #2016

if err != nil {
return 0, err
}
data, ok := dataI.(*zos.ZMount)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at this point it should be called zmount instead of data

if !ok {
return 0, errors.New("not a zmount")
}
return data.Size, nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zmount.Size after the rename

}
data, ok := dataI.(*zos.ZMount)
if !ok {
return 0, errors.New("not a zmount")
Copy link
Collaborator

@xmonader xmonader Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be curious to see the raw data included here in the error, also the message should get improved instead of not a zmount

log.Error().Err(err).Stringer("id", workloads[j].ID).Msg("failed to get zmount size")
}

return sizeI > sizeJ
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we depend on sizeI and sizeJ while they're supposed to be the zero value returns of getZmountSize in case of errors? I believe each branch after the error check should return a bool (e.g false in the first case and true in the 2nd one)

Copy link
Collaborator

@xmonader xmonader Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, maybe extract the code to sort ZMount workloads into its own function, so it could be easily tested

Copy link
Member

@muhamadazmy muhamadazmy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job. Just few minor comments

@@ -867,10 +868,44 @@ func (e *NativeEngine) uninstallDeployment(ctx context.Context, dl *gridtypes.De

}

func getZmountSize(wl *gridtypes.WorkloadWithID) (gridtypes.Unit, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func getZmountSize(wl *gridtypes.WorkloadWithID) (gridtypes.Unit, error) {
func getZmountSize(wl *gridtypes.Workload) (gridtypes.Unit, error) {

you don't need to pass the wrapper type WorloadWithID

@@ -867,10 +868,44 @@ func (e *NativeEngine) uninstallDeployment(ctx context.Context, dl *gridtypes.De

}

func getZmountSize(wl *gridtypes.WorkloadWithID) (gridtypes.Unit, error) {
dataI, err := wl.WorkloadData()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use the I suffix, data is enough. It add no value to the variable name

Suggested change
dataI, err := wl.WorkloadData()
data, err := wl.WorkloadData()

sort.Slice(workloads, func(i, j int) bool {
sizeI, err := getZmountSize(workloads[i])
if err != nil {
log.Error().Err(err).Stringer("id", workloads[i].ID).Msg("failed to get zmount size")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i get why you log but i think it's not needed here. I won't show an error in the node logs because of wrong user data. This can confuse operators to see node giving errors that might make them think something wrong with the node itself while it's actual just user data that is wrong and that it was handled.

I would personally not log it.

sizeJ, err := getZmountSize(workloads[j])
if err != nil {
log.Error().Err(err).Stringer("id", workloads[j].ID).Msg("failed to get zmount size")
return true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do u return true here but false in the first case ? just wondering. I think you should return false always in case if both elements are equal.

@muhamadazmy muhamadazmy merged commit d151e9c into main Aug 7, 2023
@muhamadazmy muhamadazmy deleted the sort-disk-workloads branch August 7, 2023 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants