-
Notifications
You must be signed in to change notification settings - Fork 110
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
base: main
Are you sure you want to change the base?
Conversation
This allows the server to figure out whether to commit or not
TransactionalRequest.Builder transactionRequest = TransactionalRequest.newBuilder() | ||
.setEnableAutoCommitRequest(EnableAutoCommitRequest.newBuilder().build()); | ||
// wait here for response | ||
final TransactionalResponse response = serverConnection.sendRequest(transactionRequest.build()); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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