Skip to content

Conversation

@brfrn169
Copy link
Collaborator

@brfrn169 brfrn169 commented Jun 14, 2025

Description

This PR optimizes ParallelExecutor to run a single task without parallel execution when asynchronous execution is not required.

Related issues and/or PRs

N/A

Changes made

  • Optimized ParallelExecutor to run a single task without parallel execution when asynchronous execution is not required.

Checklist

The following is a best-effort checklist. If any items in this checklist are not applicable to this PR or are dependent on other, unmerged PRs, please still mark the checkboxes after you have read and understood each item.

  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes.
  • I have considered whether similar issues could occur in other products, components, or modules if this PR is for bug fixes.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • Tests (unit, integration, etc.) have been added for the changes.
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

Additional notes (optional)

N/A

Release notes

N/A

@brfrn169 brfrn169 requested a review from Copilot June 14, 2025 16:36
@brfrn169 brfrn169 self-assigned this Jun 14, 2025
Copy link
Contributor

Copilot AI left a 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 noWait is 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();
Copy link

Copilot AI Jun 14, 2025

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.

Suggested change
verify(task, atMost(tasks.size())).run();
verify(task, atLeastOnce()).run();

Copilot uses AI. Check for mistakes.
parallelExecutor.rollbackRecords(tasks, TX_ID);

// Assert
verify(task, atMost(tasks.size())).run();
Copy link

Copilot AI Jun 14, 2025

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.

Suggested change
verify(task, atMost(tasks.size())).run();
verify(task, atLeastOnce()).run();

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@Torch3333 Torch3333 left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

Copy link
Contributor

@komamitsu komamitsu left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@brfrn169 brfrn169 merged commit 5c4c887 into master Jun 17, 2025
55 checks passed
@brfrn169 brfrn169 deleted the optimize-ParallelExecutor branch June 17, 2025 08:14
feeblefakie pushed a commit that referenced this pull request Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants