Skip to content

Conversation

@bogdantruta-firebolt
Copy link
Contributor

@bogdantruta-firebolt bogdantruta-firebolt commented Oct 28, 2025

Added support for transactions for Firebolt Core.
Firebolt Core does not support multiple transactions, that's why some integration tests are not being run on Core, but it supports one transaction at a time, with commit and rollback. Also it seems to support running queries outside of active transactions.
Also changed the default behavior on close to rollback any pending transactions so Core will not remain in a broken state due to pending transactions.

@bogdantruta-firebolt bogdantruta-firebolt requested a review from a team as a code owner October 28, 2025 08:14
* @param fireboltStatementService statement service to inject
* @throws SQLException if connection fails
*/
@TestOnly
Copy link
Contributor

Choose a reason for hiding this comment

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

I've seen @VisibleForTesting before but not this one. Does it do the same thing? If so let't keep the @VisibleForTesting instead. From what I know the sonar will fail if it sees actual prod code that tries to use a method annotated with @VisibleForTesting. I don't know about this annotation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That annotation is from a google package not present in this project. I was suggested this annotation by Intellij, but I thought that this only marks the constructor as being for tests for us, not for the compiler/Sonar. Do you think I should add the google package with @VisibleForTesting?

Copy link
Contributor

@ptiurin ptiurin left a comment

Choose a reason for hiding this comment

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

apart from this looks good

Comment on lines +275 to +289
public void ensureTransactionForQueryExecution() throws SQLException {
validateConnectionIsNotClose();
if (sessionProperties.getTransactionId() == null) {
inTransaction = false;
}

if (executingTransactionCommand || autoCommit) {
return;
}

if (!inTransaction) {
executingTransactionCommand = true;
try (Statement statement = createStatement()) {
statement.execute("BEGIN TRANSACTION");
inTransaction = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Outside of the scope of this PR, but is this thread-safe? Can there be a case where connection is shared across threads and one of them starts a transaction, but we check before the transaction id is updated and so set the inTransaction to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good one, didn't think of it. To be safe I can move the rollback inside the synchronized block, but I don't think this should happen since only one thread should run the close and it should be after running all queries. Plus I don't think JDBC is assumed to be used with more than one thread and just one connection

@sonarqubecloud
Copy link

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.

4 participants