Fix rollback after statement fail in non-autocommit transaction#23247
Conversation
| 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.
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.
Thanks for the comment, I also struggled here for a while. Fixed as your suggestion.
3617d8d to
c52de8c
Compare
c52de8c to
6107623
Compare
6107623 to
c5e36a2
Compare
c5e36a2 to
036171d
Compare
tdcmeehan
left a comment
There was a problem hiding this comment.
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
| @@ -618,6 +618,9 @@ public void checkCanRevokeRoles(ConnectorTransactionHandle transactionHandle, Co | |||
| public void checkCanSetRole(ConnectorTransactionHandle transaction, ConnectorIdentity identity, AccessControlContext context, String role, String catalogName) | |||
| { | |||
| SemiTransactionalHiveMetastore metastore = getMetastore(transaction); | |||
There was a problem hiding this comment.
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.
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.
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.
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
| @@ -618,6 +618,9 @@ public void checkCanRevokeRoles(ConnectorTransactionHandle transactionHandle, Co | |||
| public void checkCanSetRole(ConnectorTransactionHandle transaction, ConnectorIdentity identity, AccessControlContext context, String role, String catalogName) | |||
| { | |||
| SemiTransactionalHiveMetastore metastore = getMetastore(transaction); | |||
There was a problem hiding this comment.
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.
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.
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 |
72abe0f to
55570d8
Compare
ZacBlanco
left a comment
There was a problem hiding this comment.
Two minor things, otherwise LGTM
| assertUpdate("drop table if exists test_non_autocommit_table"); | ||
| } | ||
| catch (Exception e) { | ||
| // ignored for connector compatibility |
There was a problem hiding this comment.
What does "for connector compatibility imply" here? Do some connectors behave differently?
There was a problem hiding this comment.
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.
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