Skip to content

Add column add/drop/rename events#15225

Merged
electrum merged 1 commit intotrinodb:masterfrom
djsagain:david.stryker/add-column-change-callbacks
Jan 23, 2023
Merged

Add column add/drop/rename events#15225
electrum merged 1 commit intotrinodb:masterfrom
djsagain:david.stryker/add-column-change-callbacks

Conversation

@djsagain
Copy link
Copy Markdown
Member

Add methods in SystemSecurityMetadata to provide
notification of adding, dropping and renaming columns.

Description

Additional context and related issues

Release notes

(x) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Nov 28, 2022
@djsagain djsagain requested a review from dain November 28, 2022 22:57
@djsagain djsagain force-pushed the david.stryker/add-column-change-callbacks branch from 8b98c4d to a5039cd Compare November 28, 2022 23:38
@djsagain djsagain requested a review from kokosing November 29, 2022 00:44
@djsagain djsagain force-pushed the david.stryker/add-column-change-callbacks branch from a5039cd to 39bcbaa Compare November 29, 2022 23:52
@djsagain djsagain force-pushed the david.stryker/add-column-change-callbacks branch from 39bcbaa to c1d2607 Compare January 22, 2023 14:56
Add methods in SystemSecurityMetadata to provide
notification of adding, dropping and renaming columns.
@djsagain djsagain force-pushed the david.stryker/add-column-change-callbacks branch from c1d2607 to c337861 Compare January 22, 2023 16:01
@electrum electrum self-requested a review January 23, 2023 19:45
@electrum electrum merged commit 33fdaa0 into trinodb:master Jan 23, 2023
@github-actions github-actions bot added this to the 406 milestone Jan 23, 2023
metadata.dropColumn(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), column);
if (catalogMetadata.getSecurityManagement() != CONNECTOR) {
String columnName = getColumnMetadata(session, tableHandle, column).getName();
TableMetadata tableMetadata = getTableMetadata(session, tableHandle);
Copy link
Copy Markdown
Member

@findepi findepi Feb 1, 2023

Choose a reason for hiding this comment

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

@djsstarburst

It seems it doesn't work for some connectors.
For example, with Hive connector, metadata.dropColumn sets the SemiTransactionalHiveMetastore into EXCLUSIVE_OPERATION_BUFFERED state and then getTableMetadata fails

io.trino.testing.QueryFailedException: Unsupported combination of operations in a single transaction

	at io.trino.testing.AbstractTestingTrinoClient.execute(AbstractTestingTrinoClient.java:122)
	at io.trino.testing.DistributedQueryRunner.execute(DistributedQueryRunner.java:490)
	at io.trino.testing.QueryAssertions.assertUpdate(QueryAssertions.java:71)
	at io.trino.testing.AbstractTestQueryFramework.assertUpdate(AbstractTestQueryFramework.java:365)
	at io.trino.testing.AbstractTestQueryFramework.assertUpdate(AbstractTestQueryFramework.java:360)
	at io.trino.testing.BaseConnectorTest.testAddAndDropColumnName(BaseConnectorTest.java:4308)
	at io.trino.testing.BaseConnectorTest.testAddAndDropColumnName(BaseConnectorTest.java:4286)
...

	Suppressed: java.lang.Exception: SQL: ALTER TABLE tcn_lowercaseh3yyp7xswo DROP COLUMN lowercase
		at io.trino.testing.DistributedQueryRunner.execute(DistributedQueryRunner.java:493)
		... 29 more
Caused by: io.trino.spi.TrinoException: Unsupported combination of operations in a single transaction
	at io.trino.plugin.hive.metastore.SemiTransactionalHiveMetastore.checkReadable(SemiTransactionalHiveMetastore.java:2357)
	at io.trino.plugin.hive.metastore.SemiTransactionalHiveMetastore.getTable(SemiTransactionalHiveMetastore.java:244)
	at io.trino.plugin.hive.HiveMetadata.doGetTableMetadata(HiveMetadata.java:583)
	at io.trino.plugin.hive.HiveMetadata.getTableMetadata(HiveMetadata.java:569)
	at io.trino.plugin.hive.HiveMetadata.getTableMetadata(HiveMetadata.java:563)
	at io.trino.plugin.base.classloader.ClassLoaderSafeConnectorMetadata.getTableMetadata(ClassLoaderSafeConnectorMetadata.java:263)
...
	at io.trino.metadata.MetadataManager.getTableMetadata(MetadataManager.java:450)
	at io.trino.metadata.MetadataManager.dropColumn(MetadataManager.java:763)
	at io.trino.execution.DropColumnTask.execute(DropColumnTask.java:99)

String columnName = getColumnMetadata(session, tableHandle, column).getName();
TableMetadata tableMetadata = getTableMetadata(session, tableHandle);
CatalogSchemaTableName sourceTableName = new CatalogSchemaTableName(catalogHandle.getCatalogName(), tableMetadata.getTable());
systemSecurityMetadata.columnDropped(session, sourceTableName, columnName);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this may be problematic from transaction perspective.
what if we dispatch the systemSecurityMetadata.columnDropped event but the transaction doesn't get committed eventually and we end up still having the column?

credits to @losipiuk for thinking about that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

a bit related, but vice versa, a failure here will cause Trino transaction failure even if the connector applied the changes immediately (many do). This led to #12535, see #12535 (comment) for explanation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Notice that problem also exists for other systemSecurityMetadata notification methods too, like alter table rename

@findepi
Copy link
Copy Markdown
Member

findepi commented Feb 6, 2023

Per offline discussion, I propose a temporary revert #15984.
Of course, we can also fix the functionality, if a fix exists, but generally I would prefer the master branch to be always release-ready.

findepi added a commit that referenced this pull request Feb 6, 2023
This reverts commit 33fdaa0.

The current implementation has the following problems:

- does not work for Hive connector with `hive.security=system`
  (#15225 (comment))
- notifications are propagated even if transaction doesn't end up committing
  the DDL changes (#15225 (comment))
- notification propagation may disrupt transaction finish even if changes already
  applied in the external system (#12535 (comment)),
  for any connector that's using SYSTEM security (Iceberg, Delta with system security, or any JDBC connector)
findepi added a commit that referenced this pull request Feb 8, 2023
This reverts commit 33fdaa0.

The current implementation has the following problems:

- does not work for Hive connector with `hive.security=system`
  (#15225 (comment))
- notifications are propagated even if transaction doesn't end up committing
  the DDL changes (#15225 (comment))
- notification propagation may disrupt transaction finish even if changes already
  applied in the external system (#12535 (comment)),
  for any connector that's using SYSTEM security (Iceberg, Delta with system security, or any JDBC connector)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants