amalsaidov opened a new pull request, #4929: URL: https://github.com/apache/bookkeeper/pull/4929
### Motivation `Backoff.decorrelatedJittered` is meant to produce a decorrelated jitter stream where each backoff is drawn from a range up to 3x the previously selected value, capped at `maxMs` (see the method javadoc and http://www.awsarchitectureblog.com/2015/03/backoff.html). The conversion of the previous backoff into nanoseconds has its `TimeUnit` arguments swapped: ```java long lastNanos = TimeUnit.MILLISECONDS.convert(lastMs, TimeUnit.NANOSECONDS); ``` `TimeUnit.MILLISECONDS.convert(d, NANOSECONDS)` interprets `d` as nanoseconds and returns milliseconds, so it computes `lastMs / 1_000_000`. Since `lastMs` is already in milliseconds, `lastNanos` collapses to 0 for any sub-second backoff. With `lastNanos` stuck at 0, `randRange = abs(lastNanos * 3 - startNanos)` is always `startNanos`, so every emitted backoff stays in `[startMs, 2 * startMs)` no matter how many steps elapse. The stream never grows toward `maxMs` and the decorrelation the strategy is supposed to provide is lost. The other jitter strategies in the same class (`exponentialJittered`, `equalJittered`) convert ms to ns correctly with `TimeUnit.NANOSECONDS.convert(..., MILLISECONDS)`. ### Changes - `Backoff.decorrelatedJittered`: convert the previous backoff from milliseconds to nanoseconds using `TimeUnit.NANOSECONDS.convert(lastMs, TimeUnit.MILLISECONDS)`, matching how `startMs`/`maxMs` are converted a few lines above. - Added `TestBackoff.testDecorrelatedJitteredGrowsBeyondStart`, which fails before the fix (every backoff capped below `2 * startMs`, observed max 19 for `startMs=10, maxMs=10000`) and passes after. Verified by building and testing only the affected module: ``` mvn -pl bookkeeper-common -am test -Dtest=TestBackoff ``` AI-assisted; directed, reviewed and tested by the author. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
