Skip to content
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

Merged
merged 2 commits into from
Oct 12, 2023

Conversation

ywangd
Copy link
Member

@ywangd ywangd commented Oct 11, 2023

Relates: #99994 (comment)

@ywangd ywangd added >test Issues or PRs that are addressing/adding tests :Distributed Indexing/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. v8.12.0 labels Oct 11, 2023
@ywangd ywangd requested a review from DaveCTurner October 11, 2023 06:23
@elasticsearchmachine elasticsearchmachine added the Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label Oct 11, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

Comment on lines 393 to 397
deterministicTaskQueue.scheduleAt(
elapsed.millis() * 2,
() -> setDataNodeCountTaskQueue.submitTask(randomAlphaOfLength(5), new SetDataNodeCountTask(recoverAfterNodes), null)
);
deterministicTaskQueue.advanceTime();
deterministicTaskQueue.runAllRunnableTasks();
deterministicTaskQueue.runTasksUpToTimeInOrder(elapsed.millis() * 2);
Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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();
Copy link
Contributor

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?

Copy link
Member Author

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.

Comment on lines 393 to 397
deterministicTaskQueue.scheduleAt(
elapsed.millis() * 2,
() -> setDataNodeCountTaskQueue.submitTask(randomAlphaOfLength(5), new SetDataNodeCountTask(recoverAfterNodes), null)
);
deterministicTaskQueue.advanceTime();
deterministicTaskQueue.runAllRunnableTasks();
deterministicTaskQueue.runTasksUpToTimeInOrder(elapsed.millis() * 2);
Copy link
Contributor

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));
Copy link
Contributor

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?

@ywangd ywangd requested a review from DaveCTurner October 11, 2023 09:54
Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ywangd ywangd merged commit d210461 into elastic:main Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Indexing/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. >test Issues or PRs that are addressing/adding tests v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants