-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Fix rollback after statement fail in non-autocommit transaction #23247
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
Conversation
presto-hive/src/test/java/com/facebook/presto/hive/TestHiveIntegrationSmokeTest.java
Outdated
Show resolved
Hide resolved
presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedSmokeTestBase.java
Outdated
Show resolved
Hide resolved
| import static com.facebook.presto.spark.util.PrestoSparkUtils.getActionResultWithTimeout; | ||
| import static com.facebook.presto.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR; | ||
| import static com.facebook.presto.spi.StandardErrorCode.INVALID_SESSION_PROPERTY; | ||
| import static com.facebook.presto.sql.QueryUtil.isRollBack; |
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.
This couples to a new package & module. Probably not worth it for the trivial method you're importing.
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.
Thanks for the comment, I also struggled here for a while. Fixed as your suggestion.
3617d8d to
c52de8c
Compare
presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedSmokeTestBase.java
Outdated
Show resolved
Hide resolved
presto-hive/src/test/java/com/facebook/presto/hive/TestHiveIntegrationSmokeTest.java
Outdated
Show resolved
Hide resolved
c52de8c to
6107623
Compare
6107623 to
c5e36a2
Compare
c5e36a2 to
036171d
Compare
tdcmeehan
left a comment
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.
It seems like ignoreTransactionState is more like isRollingBack. Do you think that's an accurate way of describing it?
My thought is, we may want to support other statements in the future for this situation (such as |
036171d to
929a1d5
Compare
|
Can you resolve the conflicts? |
929a1d5 to
58ff869
Compare
Sure, the conflicts are resolved! |
58ff869 to
b622a94
Compare
b622a94 to
6903d3e
Compare
6903d3e to
ac9fd7e
Compare
| @Override | ||
| public void checkCanSetRole(ConnectorTransactionHandle transaction, ConnectorIdentity identity, AccessControlContext context, String role, String catalogName) | ||
| { | ||
| SemiTransactionalHiveMetastore metastore = getMetastore(transaction); |
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.
Can you help me understand why we need to check for null as part of this bug fix?
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.
When a statement in a non-autocommit transaction fails, InMemoryTransactionManager.abortInternal() is triggered, which causes the relevant hive connector transaction manager to clean up it's corresponding connector transaction. However, the transaction in InMemoryTransactionManager is just marked as failed, but not removed, referring to https://github.com/prestodb/presto/blob/master/presto-main/src/main/java/com/facebook/presto/execution/QueryStateMachine.java#L918.
Therefore, if we do not check the null value here, an NPE exception will be encountered when executing the rollback statement.
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.
If it's possible for metastore to be null, then shouldn't we check everywhere that we call metastore? and also label it as @Nullable?
|
@tdcmeehan and @hantangwangd any update on the above PR since its been open for about 5 months now and if we can merge and close it ? |
|
@hantangwangd, to move this one towards merge-ready, when you have time would you rebase and resolve the file conflicts? |
|
Sure, I will rebase and resolve the conflicts later this day. @steveburnett @justrelax19 |
ac9fd7e to
73b0a76
Compare
ZacBlanco
left a comment
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 mostly agree with Tim's thought from his comment here
But I also understand your reasoning in the response. Can we add a well-written javadoc which explains the meaning and use of this field so that it's clearer to developers the intention of this name? isRollback seems clear to me, but isIgnoreTransactionState does not
| @Override | ||
| public void checkCanSetRole(ConnectorTransactionHandle transaction, ConnectorIdentity identity, AccessControlContext context, String role, String catalogName) | ||
| { | ||
| SemiTransactionalHiveMetastore metastore = getMetastore(transaction); |
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.
If it's possible for metastore to be null, then shouldn't we check everywhere that we call metastore? and also label it as @Nullable?
| { | ||
| TransactionalMetadata metadata = hiveTransactionManager.get(transaction); | ||
| return metadata.getMetastore(); | ||
| return metadata == null ? null : metadata.getMetastore(); |
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 we should annotate this method with @Nullable if we are making the return behavior like this, or return Optional<SemiTransactionalHiveMetastore>
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.
Good suggestion, I have changed the method to return an Optional<SemiTransactionalHiveMetastore>, and check everywhere we call getMetastore(transaction). Please take a look when convenient!
73b0a76 to
0a51e30
Compare
Thanks for the feedback, I agree with you that |
presto-main-base/src/main/java/com/facebook/presto/dispatcher/DispatchManager.java
Outdated
Show resolved
Hide resolved
72abe0f to
55570d8
Compare
ZacBlanco
left a comment
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.
Two minor things, otherwise LGTM
presto-hive/src/main/java/com/facebook/presto/hive/security/SqlStandardAccessControl.java
Outdated
Show resolved
Hide resolved
presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedSmokeTestBase.java
Outdated
Show resolved
Hide resolved
presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestDistributedQueries.java
Outdated
Show resolved
Hide resolved
| assertUpdate("drop table if exists test_non_autocommit_table"); | ||
| } | ||
| catch (Exception e) { | ||
| // ignored for connector compatibility |
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.
What does "for connector compatibility imply" here? Do some connectors behave differently?
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.
Nice catch! Originally, I put the test case into AbstractTestIntegrationSmokeTest, and then found that its subclass TestJdbcIntegrationSmokeTest doesn't support table deletion, so I added this logic for compatibility.
Then I moved this test case to AbstractTestDistributedQueries, since there are much more subclasses of AbstractTestIntegrationSmokeTest that should ignore this test case because they don't support creating tables.
After recheck the subclasses, I found there is no need to add this logic for compatibility in AbstractTestDistributedQueries. So now it's removed again!
a295c86 to
9c7359e
Compare
ZacBlanco
left a comment
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.
Thanks for this fix! LGTM
9c7359e to
9d25512
Compare
Description
This PR fix the session corruption cause by a failed statement in non-autocommit transaction, enable executing
rollbackto end the aborted transaction block.Motivation
Fix: #23246
Test Plan
AbstractTestDistributedQueriesto simulate the scenarios described in Session is completely corrupted by the failed statement in a non-autocommit transaction #23246Contributor checklist
Release Notes