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

bug: fix string float conversion #980

Merged
Merged
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
9 changes: 5 additions & 4 deletions pkg/local/capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,13 @@ func getLoopDeviceCapacity() []*StorageCapacity {
log.Errorf("getLoopDevice: failed to get totalcapacity: %v. err: %v", totalBytes, err)
return nil
}
percent := 0.9
percentFraction := 0.9
if types.GlobalConfigVar.LocalSparseTotalAvailablePercent != "" {
p, _ := strconv.Atoi(types.GlobalConfigVar.LocalSparseTotalAvailablePercent)
percent = float64(p)
if p, err := strconv.ParseFloat(types.GlobalConfigVar.LocalSparseTotalAvailablePercent, 32); err == nil && p < 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this variable is named "Percent", I would not expect it to be less than 1.

Also, for sparse files, over 100% should also be acceptable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just the space available in a directory, not the sparse-file specific.

Copy link
Contributor

Choose a reason for hiding this comment

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

"percent" means 1/100, which is different from implementation. Should we fix this? Either change the semantic or the name of this env to avoid confusions.

percentFraction = p
}
}
totalAvailableBytes = int64(float64(totalBytes) * percent)
totalAvailableBytes = int64(float64(totalBytes) * percentFraction)
} else {
totalGi, err := strconv.Atoi(types.GlobalConfigVar.LocalSparseTotalGi)
if err != nil {
Expand Down