Skip to content

Allow enabling autoCommit without an active transaction #3477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ScottDugas
Copy link
Collaborator

This changes the client so that it sends a request to enable autoCommit when it is enabled on the client, rather than calling commit directly. By doing so, the server can determine whether it wants to commit or not based on whether it has an active transaction.

Fixes: #3473

This allows the server to figure out whether to commit or not
@ScottDugas ScottDugas added the bug fix Change that fixes a bug label Jul 8, 2025
@ScottDugas ScottDugas requested a review from ohadzeliger July 8, 2025 17:43
TransactionalRequest.Builder transactionRequest = TransactionalRequest.newBuilder()
.setEnableAutoCommitRequest(EnableAutoCommitRequest.newBuilder().build());
// wait here for response
final TransactionalResponse response = serverConnection.sendRequest(transactionRequest.build());
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to clarify: This request will always be sent prior to closing the stateful connection, and so (for the time being) can be considered an equivalent of "connection about to be orderly closed", right?
It is feasible that in the future we will use this same request to signify the change to the state of the connection (since I think we will change the protocol to be only using the "stateful" path to better sync the state of the connection between client and server).

connection.commit();
connection.setAutoCommit(true);
try (RelationalStatement statement = connection.createStatement()) {
RelationalResultSet resultSet = statement.executeQuery("SELECT * FROM test_table");
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this would be more exhaustive with another insert after the setAutoCommit(true)?

@@ -371,6 +371,16 @@ public void transactionalRollback(TransactionalToken token) throws SQLException
token.getConnection().rollback();
}

public void enableAutoCommit(TransactionalToken token) throws SQLException {
// we don't actually call setAutoCommit(false) until an operation happens, so if there is no token
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that - aligning this towards the future, where the client connection state will be in sync with the server-side connection state (TransactionalRequestHandler) - the logic of looking at the token should reside in the TransactionalRequestHandler.
FRL would be a simpler, stateless pass through to the EmbeddedConnection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix Change that fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enabling autoCommit against server without active transaction throws an error
2 participants