-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Run tasks in the determinsitic task queue upto a cutoff time #100655
Run tasks in the determinsitic task queue upto a cutoff time #100655
Conversation
Pinging @elastic/es-distributed (Team:Distributed) |
deterministicTaskQueue.scheduleAt( | ||
elapsed.millis() * 2, | ||
() -> setDataNodeCountTaskQueue.submitTask(randomAlphaOfLength(5), new SetDataNodeCountTask(recoverAfterNodes), null) | ||
); | ||
deterministicTaskQueue.advanceTime(); | ||
deterministicTaskQueue.runAllRunnableTasks(); | ||
deterministicTaskQueue.runTasksUpToTimeInOrder(elapsed.millis() * 2); |
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.
This usage seems to suggest a scheduleAtAndRunUpTo
method. Let me know if you think so as well. Happy to iterate.
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.
I'm not sure it's that common a pattern elsewhere, but that still seems like a reasonable thing to add indeed.
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.
Great. I added the method and used it here and in two other places.
public void runTasksUpToTimeInOrder(long timeInMillis) { | ||
runAllRunnableTasks(); | ||
while (nextDeferredTaskExecutionTimeMillis <= timeInMillis) { | ||
advanceTime(); |
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.
This might be slightly trappy: if there is no task scheduled at timeInMillis
then this method returns leaving the current time earlier than requested. Should we advance currentTime
to timeInMillis
in that case?
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.
Yeah I think you are right. It feels more natural the current time is at the specified time once the method runs. I updated accordingly.
deterministicTaskQueue.scheduleAt( | ||
elapsed.millis() * 2, | ||
() -> setDataNodeCountTaskQueue.submitTask(randomAlphaOfLength(5), new SetDataNodeCountTask(recoverAfterNodes), null) | ||
); | ||
deterministicTaskQueue.advanceTime(); | ||
deterministicTaskQueue.runAllRunnableTasks(); | ||
deterministicTaskQueue.runTasksUpToTimeInOrder(elapsed.millis() * 2); |
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.
I'm not sure it's that common a pattern elsewhere, but that still seems like a reasonable thing to add indeed.
|
||
taskQueue.runTasksUpToTimeInOrder(cutoffTimeInMillis); | ||
assertThat(seenNumbers, equalTo(IntStream.range(0, nRunnableTasks + nDeferredTasksUptoCutoff).boxed().collect(Collectors.toSet()))); | ||
assertThat(taskQueue.getCurrentTimeMillis(), lessThanOrEqualTo(cutoffTimeInMillis)); |
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.
Test looks good apart from this (see previous comment) - can we make this an equality assertion?
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.
LGTM
Relates: #99994 (comment)