-
Notifications
You must be signed in to change notification settings - Fork 40
Optimize ParallelExecutor #2767
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
Conversation
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.
Pull Request Overview
This PR adds an optimization to ParallelExecutor so that single-task workloads run serially when waiting is required, and updates the test suite to verify this behavior across prepare, validate, commit, and rollback operations.
- Short-circuits parallel execution for one task when
noWaitis false. - Adds unit tests for single-task scenarios under parallel/synchronous and parallel/asynchronous configurations.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| core/src/main/java/com/scalar/db/transaction/consensuscommit/ParallelExecutor.java | Added early return to run a single task serially. |
| core/src/test/java/com/scalar/db/transaction/consensuscommit/ParallelExecutorTest.java | Added tests for single-task behavior in all executor paths. |
Comments suppressed due to low confidence (1)
core/src/test/java/com/scalar/db/transaction/consensuscommit/ParallelExecutorTest.java:104
- [nitpick] These single-task tests follow the same structure for prepare, validate, commit, and rollback; consider refactoring into a parameterized test or helper to reduce duplication.
@Test public void prepare_ParallelPreparationEnabled_SingleTaskGiven_ShouldExecuteTasksSerially()
| parallelExecutor.commitRecords(tasks, TX_ID); | ||
|
|
||
| // Assert | ||
| verify(task, atMost(tasks.size())).run(); |
Copilot
AI
Jun 14, 2025
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.
Using atMost(tasks.size()) allows zero invocations, so the test could pass even if task.run() was never called. Consider using verify(task, atLeastOnce()).run() or verify(task, timeout(...).times(1)).run() to ensure it actually executes.
| verify(task, atMost(tasks.size())).run(); | |
| verify(task, atLeastOnce()).run(); |
| parallelExecutor.rollbackRecords(tasks, TX_ID); | ||
|
|
||
| // Assert | ||
| verify(task, atMost(tasks.size())).run(); |
Copilot
AI
Jun 14, 2025
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.
As above, atMost(tasks.size()) could allow zero runs. For the asynchronous rollback test, use atLeastOnce() or a timeout-based verification to confirm the task actually executes.
| verify(task, atMost(tasks.size())).run(); | |
| verify(task, atLeastOnce()).run(); |
Torch3333
left a comment
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, thank you!
komamitsu
left a comment
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! 👍
feeblefakie
left a comment
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! Thank you!
Description
This PR optimizes
ParallelExecutorto run a single task without parallel execution when asynchronous execution is not required.Related issues and/or PRs
N/A
Changes made
ParallelExecutorto run a single task without parallel execution when asynchronous execution is not required.Checklist
Additional notes (optional)
N/A
Release notes
N/A