-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add rollback action for CTAS destination table #27702
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,7 +137,7 @@ public class DefaultJdbcMetadata | |
| private final boolean precalculateStatisticsForPushdown; | ||
| private final Set<JdbcQueryEventListener> jdbcQueryEventListeners; | ||
|
|
||
| private final List<Runnable> rollbackActions = new ArrayList<>(); | ||
| protected final List<Runnable> rollbackActions = new ArrayList<>(); | ||
findinpath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public DefaultJdbcMetadata( | ||
| JdbcClient jdbcClient, | ||
|
|
@@ -1199,7 +1199,7 @@ public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, Con | |
| if (replace) { | ||
| throw new TrinoException(NOT_SUPPORTED, "This connector does not support replacing tables"); | ||
| } | ||
| JdbcOutputTableHandle handle = jdbcClient.beginCreateTable(session, tableMetadata); | ||
| JdbcOutputTableHandle handle = jdbcClient.beginCreateTable(session, tableMetadata, rollbackActions::add); | ||
| rollbackActions.add(() -> jdbcClient.rollbackCreateTable(session, handle)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we had rollback here. do we rollback twice now?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the responsibilities are now blurred, aren't they?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
now, yes. But I think the name is ok since we are inside the "createTable" method, that's is fair to have a rollback method like "rollbackCreateTable", it just our implementation only do cleanups of temporary table. Ideally if we could do the cleanup of target table inside this method as well @findinpath #27848 the method is going to split such cleanups into two methods(we already do), but finally, I think that's more elegant that we should only has one rollback methods for "createTable", caller don't care or needs to know the cleanups table is "temporary" or not
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While rolling back the creation of the destination table is characteristic only for CTAS statements, rolling back the creation of a temporary table can occur on any DML statement. |
||
| return handle; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,7 +210,7 @@ default void setTableProperties(ConnectorSession session, JdbcTableHandle handle | |
|
|
||
| void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata); | ||
|
|
||
| JdbcOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata); | ||
| JdbcOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Consumer<Runnable> rollbackActionConsumer); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
more importantly, this is a rather odd abstraction and doesn't seem necessary.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
+1
We are entering a situation where it is unclear when it is safe to roll back the target table during CTAS. For example, in
For now, this works as a solution, but I believe we could evolve the API to shift the responsibility back to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Included in however, the name may still be imperfect -- #27702 (comment)
I made the same mistake. It's not FTE-related despite the code making it look so.
It's unclear why destination table is created there. I think it might be possible to defer that statement until later.
That was also my intention. when i saw the beginMerge flow. We create high number of tables there, and someone needs to clean them up if we fail mid-way. |
||
|
|
||
| void commitCreateTable(ConnectorSession session, JdbcOutputTableHandle handle, Set<Long> pageSinkIds); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -220,7 +220,7 @@ public void createTable(ConnectorSession session, ConnectorTableMetadata tableMe | |
| if (saveMode == REPLACE) { | ||
| throw new TrinoException(NOT_SUPPORTED, "This connector does not support replacing tables"); | ||
| } | ||
| igniteClient.beginCreateTable(session, tableMetadata); | ||
| igniteClient.beginCreateTable(session, tableMetadata, _ -> {}); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. document why it's ok to ignore a rollback action |
||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -232,7 +232,7 @@ public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, Con | |
| if (replace) { | ||
| throw new TrinoException(NOT_SUPPORTED, "This connector does not support replacing tables"); | ||
| } | ||
| return igniteClient.beginCreateTable(session, tableMetadata); | ||
| return igniteClient.beginCreateTable(session, tableMetadata, rollbackActions::add); | ||
findinpath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
|
|
||
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.
rollbackTableCreation/rollbackCreateTable