Skip to content

Conversation

@brfrn169
Copy link
Collaborator

@brfrn169 brfrn169 commented Oct 24, 2025

Description

This PR adds support for batch operations that perform multiple operations in the Transaction API.

Related issues and/or PRs

N/A

Changes made

  • Introduced a new batch() method in the CrudOperable interface that accepts a list of operations and returns batch results
  • Implemented batch operation support across all transaction types (distributed, two-phase commit, JDBC, and single CRUD)
  • Added BatchResult interface and BatchResultImpl class to encapsulate operation results
  • Removed unnecessary consistency settings from test utility methods

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

Added support for batch operations that perform multiple operations in the Transaction API.

@brfrn169 brfrn169 self-assigned this Oct 24, 2025
Copilot AI review requested due to automatic review settings October 24, 2025 00:45
@brfrn169 brfrn169 added the enhancement New feature or request label Oct 24, 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 support for batch operations in the Transaction API, enabling multiple operations to be executed together in a single batch call. The implementation includes support for both read operations (Get, Scan) and mutation operations (Put, Insert, Upsert, Update, Delete) across various transaction implementations.

Key Changes:

  • Introduced a new batch() method in the CrudOperable interface that accepts a list of operations and returns batch results
  • Implemented batch operation support across all transaction types (distributed, two-phase commit, JDBC, and single CRUD)
  • Added BatchResult interface and BatchResultImpl class to encapsulate operation results
  • Removed unnecessary consistency settings from test utility methods

Reviewed Changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated no comments.

Show a summary per file
File Description
core/src/main/java/com/scalar/db/api/CrudOperable.java Added batch() method signature and BatchResult interface to the core API
core/src/main/java/com/scalar/db/common/BatchResultImpl.java New implementation class for batch operation results
core/src/main/java/com/scalar/db/common/AbstractDistributedTransaction.java Implemented batch() and mutate() methods with operation dispatching logic
core/src/main/java/com/scalar/db/common/AbstractTwoPhaseCommitTransaction.java Implemented batch() and mutate() methods for two-phase commit transactions
core/src/main/java/com/scalar/db/common/ReadOnlyDistributedTransaction.java Added validation to prevent mutations in read-only batch operations
core/src/main/java/com/scalar/db/util/ScalarDbUtils.java Updated utility to handle Operation type instead of just Mutation
core/src/main/java/com/scalar/db/transaction/singlecrudoperation/SingleCrudOperationTransactionManager.java Implemented batch() with single operation restriction
integration-test/src/main/java/com/scalar/db/api/TwoPhaseCommitTransactionIntegrationTestBase.java Added comprehensive integration tests for batch operations and removed unnecessary consistency settings
integration-test/src/main/java/com/scalar/db/api/DistributedTransactionIntegrationTestBase.java Added integration tests for batch operations in distributed transactions
core/src/test/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitTest.java Added unit tests for batch operations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @brfrn169, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Transaction API by introducing a batch operation, enabling users to execute multiple CRUD operations efficiently within a single transaction. This new functionality streamlines interactions with the database, potentially reducing network overhead and simplifying application logic. The changes involve extending core interfaces, providing concrete implementations, and updating utility classes and error handling to support this new batch capability, ensuring robust and consistent behavior across different transaction types.

Highlights

  • New Batch Operation API: Introduced a new batch method in the CrudOperable interface, allowing multiple Operation commands (Get, Scan, Put, Insert, Upsert, Update, Delete) to be executed as a single unit within a transaction. This method returns a list of BatchResult objects, corresponding to the results of each operation.
  • BatchResult Interface and Implementation: Added a new BatchResult interface and its implementation BatchResultImpl to encapsulate the outcome of individual operations within a batch. It provides methods to retrieve the operation type and specific results for GET and SCAN operations.
  • Consolidated Mutation Handling: Refactored the mutate method implementation into AbstractDistributedTransaction and AbstractTwoPhaseCommitTransaction, centralizing the logic for handling lists of mutations. This reduces code duplication across various transaction implementations.
  • Updated ScalarDbUtils: Modified ScalarDbUtils to support copying and setting target information for a list of generic Operation objects, ensuring consistency across different operation types.
  • Error Handling and Single CRUD Transaction Support: Introduced new error codes for empty operation lists and unsupported multiple operations in single CRUD operation transactions. The SingleCrudOperationTransactionManager now explicitly restricts mutate and batch methods to a single operation.
  • Thread Safety for Scanners: Synchronized the getScanner methods within ActiveTransactionManagedDistributedTransactionManager and ActiveTransactionManagedTwoPhaseCommitTransactionManager to ensure thread safety when accessing scanners.
  • Integration Tests: Added comprehensive integration tests for the new batch functionality across various transaction managers, including scenarios with default namespaces and mixed operation types, and updated existing tests to reflect the new API.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This PR adds support for batch operations in the Transaction API. The changes are extensive, touching many interfaces and their implementations to add the batch method. The core logic is centralized in abstract classes like AbstractDistributedTransaction, which is a good design choice. The integration tests are also updated to cover the new functionality. My review includes a few suggestions to improve the Javadoc clarity and the immutability of the new BatchResultImpl class.

@brfrn169 brfrn169 requested a review from komamitsu October 24, 2025 03:33
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!
Left one question for clarification. PTAL!

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!

@brfrn169 brfrn169 requested a review from feeblefakie October 27, 2025 06:06
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 03a1c76 into master Oct 28, 2025
60 checks passed
@brfrn169 brfrn169 deleted the support-batch-in-transaction branch October 28, 2025 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants