Skip to content

Revised Tx Logic#3074

Merged
robfrank merged 8 commits intomainfrom
fix/grpc-tx-updates
Dec 27, 2025
Merged

Revised Tx Logic#3074
robfrank merged 8 commits intomainfrom
fix/grpc-tx-updates

Conversation

@robfrank
Copy link
Collaborator

copy of #3073

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @robfrank, 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 revises the transaction handling mechanism within the gRPC service. The primary goal is to ensure that ArcadeDB's thread-local transactions are managed correctly in a multi-threaded gRPC environment. This is achieved by associating each active transaction with a dedicated single-thread executor, guaranteeing that all operations pertaining to that transaction are executed sequentially on its designated thread. This change enhances the reliability and correctness of transactional operations exposed via the gRPC API.

Highlights

  • Thread-Affinity for Transactions: Introduced TransactionContext with a dedicated single-thread executor to ensure all operations for a given ArcadeDB transaction (which are thread-local) run on the same thread.
  • Refactored Transaction Management: The activeTransactions map now stores TransactionContext objects, centralizing transaction state and execution.
  • Improved executeCommand Logic: The executeCommand method was refactored to executeCommandInternal to properly handle commands within existing external transactions by submitting them to the transaction's dedicated thread.
  • Robust Transaction Lifecycle: beginTransaction, commitTransaction, and rollbackTransaction methods were updated to perform their respective operations on the dedicated transaction thread, ensuring correct thread-local behavior and proper executor shutdown.
  • Enhanced Result Handling: Adjusted executeCommandInternal and executeQuery to correctly process both element-based records and scalar/projection results from database commands.
  • Maven Configuration Updates: Added .gitignore files for Maven extensions and configured grpc/pom.xml to ignore the protobuf-maven-plugin:generate goal in Eclipse (m2e).

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

@mergify
Copy link
Contributor

mergify bot commented Dec 26, 2025

🧪 CI Insights

Here's what we observed from your CI run for 45ddfe5.

🟢 All jobs passed!

But CI Insights is watching 👀

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 pull request introduces a significant and well-thought-out revision of the transaction handling logic to ensure thread affinity, which is critical for ArcadeDB's thread-local transactions. The use of a TransactionContext with a single-threaded executor for each transaction is a robust solution. The changes are consistently applied across beginTransaction, commitTransaction, rollbackTransaction, and executeCommand. The refactoring of result set processing logic and removal of convertResultToGrpcRecord also improves clarity. I've identified a few areas for improvement, including a potential resource leak and opportunities to reduce code duplication, which are detailed in the comments. Overall, this is a high-quality change that improves the stability and correctness of the gRPC service.

Comment on lines 928 to 935
} catch (Throwable t) {
Throwable cause = (t instanceof ExecutionException && t.getCause() != null) ? t.getCause() : t;
LogManager.instance()
.log(this, Level.FINE, "beginTransaction(): FAILED db=%s user=%s err=%s", reqDb, (user != null ? user : "<none>"),
t.toString(), t);
LogManager.instance().log(this, Level.SEVERE, "Error beginning transaction: %s", t, t.getMessage());
responseObserver.onError(Status.INTERNAL.withDescription("Failed to begin transaction: " + t.getMessage()).asException());
cause.toString(), cause);
LogManager.instance().log(this, Level.SEVERE, "Error beginning transaction: %s", cause, cause.getMessage());
responseObserver.onError(Status.INTERNAL.withDescription("Failed to begin transaction: " + cause.getMessage()).asException());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The catch block for beginTransaction does not shut down the ExecutorService inside the TransactionContext if an error occurs after its creation. This will cause a thread leak. To fix this, you should ensure txCtx.shutdown() is called on failure. This can be achieved by declaring TransactionContext txCtx = null; before the try block, and then in this catch block, adding a check if (txCtx != null) { txCtx.shutdown(); }.

Comment on lines 166 to 169
try {
txCtx.db.rollback();
} catch (Exception ignore) {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

In the close() method, an exception during txCtx.db.rollback() is silently ignored. This can hide underlying problems during shutdown. It's better to log such failures, even if the shutdown process must continue.

            try {
              txCtx.db.rollback();
            } catch (Exception e) {
              LogManager.instance().log(this, Level.WARNING, "Failed to rollback transaction %s during shutdown", e, txCtx.txId);
            }

@codacy-production
Copy link

codacy-production bot commented Dec 26, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.05%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (768e0ed) 77237 49479 64.06%
Head commit (45ddfe5) 77237 (+0) 49521 (+42) 64.12% (+0.05%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3074) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Address three issues identified by Gemini Code Assist in PR #3074:

1. HIGH: Fix thread leak in beginTransaction()
   - Move TransactionContext declaration outside try block
   - Add txCtx.shutdown() in catch block to clean up executor on failure

2. MEDIUM: Add logging for rollback exceptions in close()
   - Replace silent catch with WARNING-level log message
   - Helps diagnose shutdown issues instead of hiding them

3. MEDIUM: Merge duplicate catch blocks in executeCommand()
   - Consolidate ExecutionException and Exception handlers
   - Single block handles cause unwrapping for both cases

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
<protobuf-maven-plugin.version>4.1.1</protobuf-maven-plugin.version>
<grpc.version>1.77.0</grpc.version>
<protoc.version>4.32.0</protoc.version>
<protoc.version>4.33.0</protoc.version>
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have versions as properties, to easily manage upgrades

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

my fault on rebasing. These are properties, btw :)

@robfrank robfrank merged commit 8ee158d into main Dec 27, 2025
20 of 25 checks passed
@robfrank robfrank mentioned this pull request Dec 27, 2025
2 tasks
@robfrank robfrank added this to the 25.12.1 milestone Dec 27, 2025
robfrank added a commit that referenced this pull request Feb 11, 2026
Co-authored-by: Oleg Cohen <[email protected]>
(cherry picked from commit 8ee158d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants