-
Notifications
You must be signed in to change notification settings - Fork 21
feat: support infinite retention policy for PulsarTopic and PulsarNamespace #339
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
Conversation
|
@freeznet:Thanks for your contribution. For this PR, do we need to update docs? |
maxsxu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@freeznet Wondering what's the disadvantages of achieving infinite retention policy by setting retentionTime and retentionSize to -1 compared to use new attribute?
acc04ab to
426f9f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for infinite retention policies for PulsarTopic and PulsarNamespace resources by introducing the special value "-1" to represent infinite retention time and size.
- Added utility functions for handling infinite quantities and durations
- Enhanced admin client to properly handle infinite retention values when configuring Pulsar resources
- Added comprehensive test coverage for infinite retention scenarios
Reviewed Changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/utils/duration.go | Enhanced Duration type to support "-1" as infinite duration value |
| pkg/utils/quantity.go | Added new utility functions for handling infinite quantities |
| pkg/admin/impl.go | Updated admin client to properly handle infinite retention in topic and namespace policies |
| api/v1alpha1/pulsartopic_types.go | Updated field documentation to include infinite retention usage |
| config/crd/bases/resource.streamnative.io_pulsartopics.yaml | Updated CRD with infinite retention documentation |
| docs/pulsar_topic.md | Added comprehensive documentation for infinite retention configuration |
| docs/pulsar_namespace.md | Added comprehensive documentation for infinite retention configuration |
| tests/utils/spec.go | Added test utility functions for creating topics with various retention configurations |
| tests/operator/resources_test.go | Added comprehensive integration tests for infinite retention functionality |
| pkg/utils/duration_test.go | Added unit tests for Duration utility functions |
| pkg/utils/quantity_test.go | Added unit tests for quantity utility functions |
| .licenserc.yaml | Added .envrc to license exclusions |
| // If can't convert to int64, use approximation | ||
| return int64(q.AsApproximateFloat64()) |
Copilot
AI
Aug 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using AsApproximateFloat64() as a fallback could lead to precision loss for large quantities. Consider using q.Value() with proper scaling instead.
| // If can't convert to int64, use approximation | |
| return int64(q.AsApproximateFloat64()) | |
| // Use q.Value() to get the exact value and scale to bytes | |
| bigVal := q.Value() | |
| // Scale bigVal to bytes according to the quantity's format | |
| // The Scale() method returns the exponent for the base-10 scale | |
| scale := q.Scale() | |
| // bytes = bigVal * 10^scale | |
| scaled := new(big.Int).Set(bigVal) | |
| if scale > 0 { | |
| multiplier := new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(scale)), nil) | |
| scaled.Mul(scaled, multiplier) | |
| } else if scale < 0 { | |
| divisor := new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(-scale)), nil) | |
| scaled.Div(scaled, divisor) | |
| } | |
| // If the scaled value fits in int64, return it; otherwise, return math.MaxInt64 | |
| if scaled.IsInt64() { | |
| return scaled.Int64() | |
| } | |
| // Overflow: return max int64 value | |
| return int64(^uint64(0) >> 1) |
@maxsxu Thanks for the comments, and I thought the |
(If this PR fixes a github issue, please add
Fixes #<xyz>.)Fixes #
(or if this PR is one task of a github issue, please add
Master Issue: #<xyz>to link to the master issue.)Master Issue: #
Motivation
Explain here the context, and why you're making that change. What is the problem you're trying to solve.
Modifications
Describe the modifications you've done.
Verifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Documentation
Check the box below.
Need to update docs?
doc-required(If you need help on updating docs, create a doc issue)
no-need-doc(Please explain why)
doc(If this PR contains doc changes)