Skip to content

Commit

Permalink
Fixes possible negative jitter (opensearch-project#78)
Browse files Browse the repository at this point in the history
Signed-off-by: Drew Baugher <46505179+dbbaughe@users.noreply.github.com>
  • Loading branch information
dbbaughe committed Nov 1, 2021
1 parent 79061d3 commit 58a8a18
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ boolean reschedule(ScheduledJobParameter jobParameter, JobSchedulingInfo jobInfo
double jitter = jobParameter.getJitter() == null ? 0d : jobParameter.getJitter();
jitter = jitter > jitterLimit ? jitterLimit : jitter;
jitter = jitter < 0 ? 0 : jitter;
long jitterMillis = Math.round(Randomness.get().nextLong() % interval.toMillis() * jitter);
long randomLong = Randomness.get().nextLong();
if (randomLong == Long.MIN_VALUE) randomLong += 17; // to ensure the * -1 below doesn't fail to change to positive
long randomPositiveLong = randomLong < 0 ? randomLong * -1 : randomLong;
long jitterMillis = Math.round(randomPositiveLong % interval.toMillis() * jitter);
if (jitter > 0) {
log.info("Will delay {} miliseconds for next execution of job {}", jitterMillis, jobParameter.getName());
}
Expand Down

0 comments on commit 58a8a18

Please sign in to comment.