Repository navigation
Round refill-based expiration up to whole milliseconds - #644
Merged
vladimir-bukhtoyarov merged 1 commit intoOct 26, 2026
Merged
Conversation
Fixes bucket4j#643. Generated-by: OpenAI Codex
Collaborator
|
Good catch, I will look at weekend |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused rounding change addresses the defect safely and has targeted regression coverage, with no blocking issues identified.
No open issues 🎉
What changed in this PR
Fixes #643 by rounding refill-based expiration up to whole milliseconds, preventing distributed bucket state from expiring before refill completes.
Changes:
- Uses division and remainder to round up safely, including at
Long.MAX_VALUEnanoseconds. - Adds ten regression and control cases covering refill styles, rounding boundaries, retention, and full buckets.
| File | Description |
|---|---|
bucket4j-core/src/test/java/io/github/bucket4j/distributed/expiration/BasedOnTimeForRefillingBucketUpToMaxExpirationAfterWriteStrategyTest.java |
Adds regression tests and unchanged-behavior checks. |
bucket4j-core/src/main/java/io/github/bucket4j/distributed/expiration/BasedOnTimeForRefillingBucketUpToMaxExpirationAfterWriteStrategy.java |
Rounds fractional refill milliseconds up while preserving retention and minimum TTL behavior. |
Review effort: Balanced
Collaborator
|
Will be released in few days |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #643.
The refill-based expiration strategy truncates fractional milliseconds, so a bucket needing 1,999,999 ns to refill gets a 1 ms TTL and can expire before its consumed token is restored. Round the refill delay up without adding to the nanosecond value, avoiding overflow at
Long.MAX_VALUE.Exact-millisecond delays, the keep-after-refill setting, the minimum 1 ms TTL, and serialization stay unchanged. Adds ten regression/control cases for greedy and interval refills, boundaries, a full bucket, and a nonzero retention setting.
Validation on OpenJDK 17:
./mvnw --no-transfer-progress -B -pl bucket4j-core -am clean package: 1,012 tests, no failures/errors/skips.-pl bucket4j-core -am -amd clean package): 34 modules succeed; 3,736 tests run, with 8 Cassandra errors and no assertion failures. The same eight compatibility-checker configuration errors reproduce at base959d97cin the two affected methods. They are unrelated to the expiration change. The reactor stops before Memcached.-pl bucket4j-memcached -am -Dtest=MemcachedTest -Dsurefire.failIfNoSpecifiedTests=false package).git diff --check: passed.AI disclosure: OpenAI Codex performed the investigation, implementation, test execution, and drafted this description. The original core regressions were also independently checked by a separate AI review; this is not a human review.