Skip to content

Conversation

@feeblefakie
Copy link
Contributor

This is an automated backport of the following:

Please merge this PR after all checks have passed.

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.

Summary of Changes

Hello @feeblefakie, 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 backports a crucial fix to address a behavioral issue when group commit is used in conjunction with one-phase commit. The changes ensure that the lifecycle of transactions within the group commit mechanism is correctly handled during one-phase commit attempts and executions, preventing potential inconsistencies. This also includes enabling and updating relevant test cases to validate the improved interaction between these features.

Highlights

  • Group Commit and One-Phase Commit Interaction Fix: I've implemented a fix in CommitHandlerWithGroupCommit to ensure that the group commit state is properly managed when one-phase commit operations are attempted or executed. Specifically, cancelGroupCommitIfNeeded is now called when canOnePhaseCommit throws a CommitException or when onePhaseCommitRecords is invoked, ensuring the transaction is correctly removed from the group commit queue.
  • Enabled Combined Feature Testing: Previously disabled test cases in CommitHandlerWithGroupCommitTest that combine one-phase commit and group commit functionalities have been re-enabled. This allows for comprehensive testing of the corrected behavior and validates the proper interaction between these two features.
  • Test Infrastructure Enhancements: I've introduced a new helper method, createCommitHandlerWithOnePhaseCommit, in CommitHandlerTest and overridden it in CommitHandlerWithGroupCommitTest to streamline the setup of test scenarios involving one-phase commit. Additionally, assertions have been added to verify that the groupCommitter.remove method is called as expected during one-phase commit operations within group commit tests.
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

  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

The pull request backports a fix to address the behavior of group commit with one-phase commit. The changes include modifications to CommitHandlerWithGroupCommit.java and CommitHandlerTest.java to handle exceptions and ensure proper cancellation of group commits. Additionally, tests in CommitHandlerWithGroupCommitTest.java are updated to verify the interaction with the groupCommitter when one-phase commit is enabled.

Comment on lines +61 to +67
boolean canOnePhaseCommit(Snapshot snapshot) throws CommitException {
try {
return super.canOnePhaseCommit(snapshot);
} catch (CommitException e) {
cancelGroupCommitIfNeeded(snapshot.getId());
throw e;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Wrapping the call to super.canOnePhaseCommit in a try-catch block and then re-throwing the exception after cancelling the group commit might mask the original stack trace, making debugging harder. Consider logging the caught exception before re-throwing it to preserve the context.

Suggested change
boolean canOnePhaseCommit(Snapshot snapshot) throws CommitException {
try {
return super.canOnePhaseCommit(snapshot);
} catch (CommitException e) {
cancelGroupCommitIfNeeded(snapshot.getId());
throw e;
}
boolean canOnePhaseCommit(Snapshot snapshot) throws CommitException {
try {
return super.canOnePhaseCommit(snapshot);
} catch (CommitException e) {
logger.warn("canOnePhaseCommit failed", e); // Log the exception
cancelGroupCommitIfNeeded(snapshot.getId());
throw e;
}
}

Comment on lines +93 to +96
protected CommitHandler createCommitHandlerWithOnePhaseCommit() {
return new CommitHandler(
storage, coordinator, tableMetadataManager, parallelExecutor, mutationsGrouper, true, true);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The createCommitHandlerWithOnePhaseCommit method is duplicated here and in CommitHandlerWithGroupCommitTest.java. Consider creating a single method in a common base class or utility class to avoid duplication and improve maintainability.

Comment on lines 216 to +223
@Test
public void canOnePhaseCommit_WhenOnePhaseCommitDisabled_ShouldReturnFalse() {}

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenValidationRequired_ShouldReturnFalse() {}
public void onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations()
throws CommitConflictException, UnknownTransactionStatusException, ExecutionException {
super.onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations();

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenNoWritesAndDeletes_ShouldReturnFalse() {}
// Assert
verify(groupCommitter).remove(anyId());
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    verify(groupCommitter).remove(anyId());
  }

Comment on lines 226 to +234
@Test
public void canOnePhaseCommit_WhenDeleteWithoutExistingRecord_ShouldReturnFalse() {}

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenMutationsCanBeGrouped_ShouldReturnTrue() {}
public void
onePhaseCommitRecords_WhenNoMutationExceptionThrown_ShouldThrowCommitConflictException()
throws ExecutionException {
super.onePhaseCommitRecords_WhenNoMutationExceptionThrown_ShouldThrowCommitConflictException();

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenMutationsCannotBeGrouped_ShouldReturnFalse() {}
// Assert
verify(groupCommitter).remove(anyId());
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    verify(groupCommitter).remove(anyId());
  }

Comment on lines 237 to +246
@Test
public void canOnePhaseCommit_WhenMutationsGrouperThrowsException_ShouldThrowCommitException() {}
@Override
public void
onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException()
throws ExecutionException {
super
.onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException();

@Disabled("Enabling both one-phase commit and group commit is not supported")
// Assert
verify(groupCommitter).remove(anyId());
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    verify(groupCommitter).remove(anyId());
  }

Comment on lines +289 to +294

@Test
public void
onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException() {}
@Override
public void canOnePhaseCommit_WhenMutationsCanBeGrouped_ShouldReturnTrue() throws Exception {
super.canOnePhaseCommit_WhenMutationsCanBeGrouped_ShouldReturnTrue();
groupCommitter.remove(anyId());
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    groupCommitter.remove(anyId());
  }

Comment on lines +297 to +301
@Test
@Override
public void canOnePhaseCommit_WhenMutationsCannotBeGrouped_ShouldReturnFalse() throws Exception {
super.canOnePhaseCommit_WhenMutationsCannotBeGrouped_ShouldReturnFalse();
groupCommitter.remove(anyId());
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    groupCommitter.remove(anyId());
  }

Comment on lines 304 to +313
@Test
@Override
public void
onePhaseCommitRecords_WhenExecutionExceptionThrown_ShouldThrowUnknownTransactionStatusException() {}
canOnePhaseCommit_WhenMutationsGrouperThrowsExecutionException_ShouldThrowCommitException()
throws ExecutionException {
super
.canOnePhaseCommit_WhenMutationsGrouperThrowsExecutionException_ShouldThrowCommitException();

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void commit_OnePhaseCommitted_ShouldNotThrowAnyException() {}
// Assert
verify(groupCommitter).remove(anyId());
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    verify(groupCommitter).remove(anyId());
  }

Comment on lines +316 to +322
@Test
@Override
public void commit_OnePhaseCommitted_ShouldNotThrowAnyException()
throws CommitException, UnknownTransactionStatusException {
super.commit_OnePhaseCommitted_ShouldNotThrowAnyException();
groupCommitter.remove(anyId());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    groupCommitter.remove(anyId());
  }

Comment on lines 324 to +332
@Test
@Override
public void
commit_OnePhaseCommitted_UnknownTransactionStatusExceptionThrown_ShouldThrowUnknownTransactionStatusException() {}
commit_OnePhaseCommitted_UnknownTransactionStatusExceptionThrown_ShouldThrowUnknownTransactionStatusException()
throws CommitException, UnknownTransactionStatusException {
super
.commit_OnePhaseCommitted_UnknownTransactionStatusExceptionThrown_ShouldThrowUnknownTransactionStatusException();
groupCommitter.remove(anyId());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    groupCommitter.remove(anyId());
  }

@brfrn169 brfrn169 merged commit c5aaba8 into 3.16 Jul 9, 2025
106 of 108 checks passed
@brfrn169 brfrn169 deleted the 3.16-pull-2832 branch July 9, 2025 10:21
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.

2 participants