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

Retention: switch number of days type uint16 -> float32 #883

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Al2Klimov
Copy link
Member

This allows specifying less than a day as threshold. That is especially useful if history doesn't mattter as much as disk space.

I want my large (ref/NC/820479) test setup to run over WE w/o running out of disk space. So I built this.

@Al2Klimov Al2Klimov added enhancement New feature or request area/history labels Jan 24, 2025
@cla-bot cla-bot bot added the cla/signed label Jan 24, 2025
@@ -156,7 +157,7 @@ func (r *Retention) Start(ctx context.Context) error {
errs := make(chan error, 1)

for _, stmt := range RetentionStatements {
var days uint16
var days float32
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
var days float32
var days float64

I guess we can allow ourselves this much precision. Same applies to all cases where float32 is being used.

Later on, you have even casted it to float64 to match math.Modf.

olderThan := tick.Time
wholeDays, dayFraction := math.Modf(float64(days))

if wholeDays > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Can this be negative? Above in line 171/172 it is already checked if days < 1.

Btw, you may want to change the abort constraint to days < 0 as otherwise you cannot use half days, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can this be negative?

I guess you answered your own question:

Above in line 171/172 it is already checked if days < 1.

So no, it can't be.

(If I understand you correctly.)

Copy link
Contributor

@julianbrost julianbrost left a comment

Choose a reason for hiding this comment

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

If I remember correctly, that config attribute only exists in this way instead of being a standard time.Duration because the largest unit time.ParseDuration is hours and you'd have to configure large non-obvious values for realistic use-cases. An alternative could be to allow more advanced duration strings like for example history: 1y, then the change would also provide some real-world improvement.

And another thing to consider: could allowing very small values conflict with writing the history? Like could this trigger foreign key errors because the referenced row was already deleted? The minimum of 1 day might actually provide some safety margin there.

Comment on lines +186 to +195
olderThan := tick.Time
wholeDays, dayFraction := math.Modf(float64(days))

if wholeDays > 0 {
olderThan = olderThan.AddDate(0, 0, -int(wholeDays))
}

if dayFraction > 0 {
olderThan = olderThan.Add(-time.Duration(dayFraction * float64(24*time.Hour)))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this actually do something more useful than just days * 24 * time.Hour? Yes, there's a slight difference with DST changes, but does it even do something useful then?

Copy link
Member Author

Choose a reason for hiding this comment

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

IIRC, only a limited number of days fit into time.Duration. I'm working around that limitation here.

This allows specifying less than a day as threshold.  That is especially useful if history doesn't mattter as much as disk space.
@Al2Klimov
Copy link
Member Author

The minimum of 1 day might actually provide some safety margin there.

E.g 1h safety margin would also do it.

@Al2Klimov
Copy link
Member Author

BUT then I'd tell users to increase the threshold.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants