fix: support for remote tx retry on the server side#2254
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @lvca, 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 introduces support for server-side transaction retries for remote HTTP requests by modifying the HTTP handler structure to parse and pass the request payload (as a JSON object) down to the execution logic. This allows database-related handlers to configure transaction retry attempts based on the request payload.
Highlights
- HTTP Handler Signature Update: Modified the base
AbstractServerHttpHandlerand its subclasses to accept aJSONObject payloadparameter in theexecutemethod. This allows handlers to easily access structured request body data. - Payload Parsing in Base Handler: The
AbstractServerHttpHandlernow parses the request body into aJSONObjectbefore calling the specific handler'sexecutemethod, centralizing this logic. - Server-Side Transaction Retry: Updated
DatabaseAbstractHandlerto read an optionalattemptsparameter from the request payload and pass it to thedatabase.transactionmethod, enabling server-side retries for database operations initiated via HTTP.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 is currently in preview and 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 to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces support for remote transaction retries on the server side by passing a JSONObject payload (which can contain retry attempts) to various HTTP handlers. The core logic for handling retries within transactions is updated in DatabaseAbstractHandler. The changes also include some refactoring of payload parsing in AbstractServerHttpHandler and its consumers, along with minor style adjustments like wildcard imports in several files.
My review focuses on adherence to common Java best practices and the Google Java Style Guide (for aspects like import statements), code maintainability (addressing duplication), and minor code cleanliness issues.
| import java.util.concurrent.atomic.*; | ||
| import java.util.logging.*; |
There was a problem hiding this comment.
According to the Google Java Style Guide, wildcard imports are generally discouraged except for specific cases like java.util.* or java.io.*. For java.util.concurrent.atomic and java.util.logging, it's preferable to use specific imports to improve clarity and avoid potential namespace collisions.
For java.util.concurrent.atomic.*, only AtomicReference appears to be used from this package in this file.
For java.util.logging.*, only Level appears to be used from this package in this file (as LogManager is imported from com.arcadedb.log.LogManager).
| import java.util.concurrent.atomic.*; | |
| import java.util.logging.*; | |
| import java.util.concurrent.atomic.AtomicReference; | |
| import java.util.logging.Level; |
| boolean finalAtomicTransaction = atomicTransaction; | ||
| if (activeSession != null) { | ||
| // EXECUTE THE CODE LOCKING THE CURRENT SESSION. THIS AVOIDS USING THE SAME SESSION FROM MULTIPLE THREADS AT THE SAME TIME | ||
| activeSession.execute(user, () -> { | ||
| response.set(execute(exchange, user, database)); | ||
| if (finalAtomicTransaction) { | ||
| database.transaction(() -> { | ||
| try { | ||
| response.set(execute(exchange, user, database, payload)); | ||
| } catch (Exception e) { | ||
| throw new TransactionException("Error on executing command", e); | ||
| } | ||
| }, false, attempts); | ||
| } else | ||
| response.set(execute(exchange, user, database, payload)); | ||
| return null; | ||
| }); | ||
| else | ||
| response.set(execute(exchange, user, database)); | ||
| } else { | ||
| if (finalAtomicTransaction) { | ||
| database.transaction(() -> { | ||
| try { | ||
| response.set(execute(exchange, user, database, payload)); | ||
| } catch (Exception e) { | ||
| throw new TransactionException("Error on executing command", e); | ||
| } | ||
| }, false, attempts); | ||
| } else | ||
| response.set(execute(exchange, user, database, payload)); | ||
| } |
There was a problem hiding this comment.
The logic for executing the command, potentially within a transaction, is duplicated in the if (activeSession != null) block and the else block. This makes the method harder to read and maintain.
Consider extracting the common execution logic into a private helper method. This helper method could take parameters like exchange, user, database, payload, finalAtomicTransaction, attempts, and response.
For example, a helper method could look like:
private void executeCommandWithOptionalTransaction(
HttpServerExchange exchange,
ServerSecurityUser user,
DatabaseInternal database,
JSONObject payload,
boolean isTransactional,
int attempts,
AtomicReference<ExecutionResponse> responseRef) throws Exception {
if (isTransactional && database != null) {
database.transaction(() -> {
try {
responseRef.set(execute(exchange, user, database, payload));
} catch (Exception e) {
throw new TransactionException("Error on executing command", e);
}
}, false, attempts);
} else {
responseRef.set(execute(exchange, user, database, payload));
}
}This would simplify the main execute method significantly.
| import java.io.*; | ||
| import java.net.*; | ||
| import java.util.*; | ||
| import java.util.logging.*; |
There was a problem hiding this comment.
Consistent with the Google Java Style Guide, prefer specific imports over wildcard imports for java.util.logging.*. In this file, only Level seems to be used from java.util.logging (as LogManager is imported from com.arcadedb.log.LogManager).
| import java.util.logging.*; | |
| import java.util.logging.Level; |
| import java.util.logging.Level; | ||
| import java.io.*; | ||
| import java.util.*; | ||
| import java.util.logging.*; |
There was a problem hiding this comment.
Consistent with the Google Java Style Guide, prefer specific imports over wildcard imports for java.util.logging.*. In this file, only Level seems to be used from java.util.logging (as LogManager is imported from com.arcadedb.log.LogManager).
| import java.util.logging.*; | |
| import java.util.logging.Level; |
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesFootnotes
|
About issue #2236
What does this PR do?
A brief description of the change being made with this pull request.
Motivation
What inspired you to submit this pull request?
Related issues
A list of issues either fixed, containing architectural discussions, otherwise relevant
for this Pull Request.
Additional Notes
Anything else we should know when reviewing?
Checklist
mvn clean packagecommand