-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Support drop iceberg table when metadata or snapshot is missing and refactor code for delta-lake #15065
Support drop iceberg table when metadata or snapshot is missing and refactor code for delta-lake #15065
Conversation
bd6d342
to
604b6c9
Compare
604b6c9
to
2ab0747
Compare
core/trino-main/src/main/java/io/trino/testing/TestingMetadata.java
Outdated
Show resolved
Hide resolved
core/trino-spi/src/main/java/io/trino/spi/connector/ConnectorMetadata.java
Outdated
Show resolved
Hide resolved
if (!(e.getCause() instanceof FileNotFoundException)) { | ||
throw e; | ||
} | ||
LOG.warn("Failed to load table " + schemaTableName, e); |
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.
Why is the exception being swallowed?
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.
Because we do not want to fail when FileNotFoundException
exception occurs instead we want to drop the table from metastore and delete table location directory.
plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestTransactionLogAccess.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestTransactionLogAccess.java
Outdated
Show resolved
Hide resolved
4234827
to
eedddc1
Compare
core/trino-spi/src/main/java/io/trino/spi/connector/ConnectorMetadata.java
Show resolved
Hide resolved
@@ -346,6 +348,12 @@ public IcebergTableHandle getTableHandle( | |||
catch (TableNotFoundException e) { | |||
return null; | |||
} | |||
catch (Exception e) { | |||
if (e.getCause() instanceof FileNotFoundException) { | |||
throw new TrinoException(METADATA_NOT_FOUND, "Metadata not found in metadata location for table " + tableName, e); |
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'm not positive this will always be a FileNotFoundException. If you're using S3 for example it's probably something like an AmazonServiceException with an error code "Specified key does not exist"
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.
Modified the exception catch to handle S3 exception. Verified GCP and ADLS exceptions as well.
@@ -1399,6 +1407,12 @@ public void dropTable(ConnectorSession session, ConnectorTableHandle tableHandle | |||
catalog.dropTable(session, ((IcebergTableHandle) tableHandle).getSchemaTableName()); | |||
} | |||
|
|||
@Override | |||
public void dropTable(ConnectorSession session, SchemaTableName schemaTableName) |
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 still validate that the table exists here, and throw a TableNotFound exception if it doesn't
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.
Respective catalog call will take care of validating the table exists.
core/trino-spi/src/main/java/io/trino/spi/StandardErrorCode.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/execution/DropTableTask.java
Outdated
Show resolved
Hide resolved
Could you update PR title to reflect Delta Lake connector? |
* | ||
* @throws RuntimeException if the table cannot be dropped | ||
*/ | ||
void dropTable(Session session, QualifiedObjectName tableName); |
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.
We want this method to replace the old one, void dropTable(Session session, TableHandle tableHandle)
.
So it would be good to
- make ConnectorMetadata change backward compatibility
- apply changes to
DropTableTask
Doing this would reveal that the old drop handles redirections whereas the new drop-by-name cannot do that.
The MetadataManager could follow redirects as needed, but I am concerned this is not the right place to add that logic.
Also, decoupling ConnectorMetadata.redirectTable
and ConnectorMetadata.dropTable
calls makes it impossible to make a non-racy implementation.
I am leaving towards introducing a non-void return type here, so that drop-by-name can either declare success or return a redirection.
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.
@martint wdyt?
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 looks unresolved. @krvikash @findinpath do you have a plan here?
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.
perhaps something like this (rough idea, not polished up)
DropResult dropTable(Session session, QualifiedObjectName tableName);
sealed class DropResult
permits DropSuccess, DropRedirected
class DropSuccess { .. } // singleton (can this be an enum?)
records DropRedirected(CatalogSchemaTableName target) {}
BaseTable table = null; | ||
try { | ||
table = (BaseTable) loadTable(session, schemaTableName); | ||
validateTableCanBeDropped(table); |
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 the metadata file is not found, Then we won't be able to get the table properties and validate if the table can be dropped. How to handle this?
7dc64a3
to
649ccd0
Compare
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java
Outdated
Show resolved
Hide resolved
da95d64
to
62b2221
Compare
7cc24be
to
7375027
Compare
try { | ||
redirectionAwareTableHandle = metadata.getRedirectionAwareTableHandle(session, originalTableName); | ||
} | ||
catch (TrinoException e) { |
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.
why is this exception-driven?
what potential exceptions are we ignoring here?
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 want to check the exception which fails with the METADATA_NOT_FOUND
error.
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.
We should probably rethink here the way we obtain the tableName
. We don't need actually the full tableHandle
for dropping the table, right?
Swallowing the exception gets us to the state of adding the DropResult
, DropRedirected
and DropSuccess
classes and extra logic in MetadataManager
.
I think the approach to solve this issue should be thought over.
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 want to check the exception which fails with the
METADATA_NOT_FOUND
error.
metadata.dropTable
must support such case anyway
what does it currently throw?
core/trino-main/src/main/java/io/trino/execution/DropTableTask.java
Outdated
Show resolved
Hide resolved
* | ||
* @throws RuntimeException if the table cannot be dropped | ||
*/ | ||
void dropTable(Session session, QualifiedObjectName tableName); |
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 looks unresolved. @krvikash @findinpath do you have a plan here?
e127e6e
to
038d833
Compare
core/trino-spi/src/main/java/io/trino/spi/connector/ConnectorMetadata.java
Show resolved
Hide resolved
core/trino-spi/src/main/java/io/trino/spi/StandardErrorCode.java
Outdated
Show resolved
Hide resolved
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.
"Introduce dropTable SPI method that takes SchemaTableName"
DropTableTask lgtm
please clean up the commit (deprecation, unused class)
038d833
to
bf2bc50
Compare
I have written a doc for the approaches we have taken for this PR https://docs.google.com/document/d/1uydrtqfj4S5dhyrQ8JqAsW3fqr1ACXmEvj9MYSpJpLw/ CC: @findepi |
sorry for not following up earlier on this. |
bf2bc50
to
2860eee
Compare
Rebased and resolved the conflicts. @findepi, I am using using |
2860eee
to
f83da0c
Compare
Rebased |
f83da0c
to
b07a719
Compare
Rebased with the master and resolve conflicts. |
b07a719
to
1856081
Compare
(rebased resolving a conflict) |
@@ -264,9 +264,18 @@ Optional<TableExecuteHandle> getTableHandleForExecute( | |||
* Drops the specified table | |||
* | |||
* @throws RuntimeException if the table cannot be dropped or table handle is no longer valid | |||
* | |||
* @deprecated use {@link #dropTable(Session, QualifiedObjectName)} |
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 overload is a dead code now, no need for keeping it (as deprecated)
@@ -614,6 +636,32 @@ public void testDeny() | |||
onTrino().executeQuery("DROP TABLE " + icebergTableName); | |||
} | |||
|
|||
@Test(groups = {HIVE_ICEBERG_REDIRECTIONS, PROFILE_SPECIFIC_TESTS}) | |||
public void testDropTableWithMissingMetadataFile() |
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.
Would it make sense to have it tested outside of PTs?
Description
Fixes #12318
This PR Includes below:
SPI:
Introduced new SPI method
dropTable
which takesSchemaTableName
. It is the connector's responsibility to implement the method.Note:
dropTable
with table handle deprecation/removal will be taken care in new PRIceberg connector:
Q: What if latest manifest file or snapshot file does not exist and data files referenced by TableMetadata located in different locations?
Delta-Lake connector:
dropTable
withSchemaTableName
in case delta log does not existmetadataEntry
non-optional in DeltaLakeTableHandleNon-technical explanation
NA
Release notes
( ) This is not user-visible or docs only and no release notes are required.
(X) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text: