-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Cleanup metadata file when commitNewTable
fails for the Iceberg table
#14869
Conversation
TODO Add test cases. |
ce68802
to
8106393
Compare
4d110da
to
d2e44a1
Compare
commitNewTable
fails for the Iceberg table
d2e44a1
to
bb34560
Compare
protected void cleanupMetadata(String metadataLocation) | ||
{ | ||
if (fileIo.newInputFile(metadataLocation).exists()) { | ||
fileIo.deleteFile(metadataLocation); |
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.
In a local File system, This operation does not delete the parent folder.
cabcba5
to
f1d331c
Compare
.../trino/plugin/iceberg/catalog/file/TestIcebergFileMetastoreTableOperationsCreateFailure.java
Outdated
Show resolved
Hide resolved
.../trino/plugin/iceberg/catalog/file/TestIcebergFileMetastoreTableOperationsCreateFailure.java
Outdated
Show resolved
Hide resolved
.../trino/plugin/iceberg/catalog/file/TestIcebergFileMetastoreTableOperationsCreateFailure.java
Outdated
Show resolved
Hide resolved
commitNewTable
fails for the Iceberg tablecommitNewTable
fails for the Iceberg table
0150fee
to
95036ab
Compare
...no-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/AbstractIcebergTableOperations.java
Outdated
Show resolved
Hide resolved
commitNewTable
fails for the Iceberg tablecommitNewTable
fails for the Iceberg table
e90cc3a
to
c287c6a
Compare
|
||
protected boolean isCommitSuccess(String metadataLocation) | ||
{ | ||
AtomicReference<Boolean> isSuccess = new AtomicReference<>(false); |
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 atomic when it runs in one thread?
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.
c287c6a
to
4919a81
Compare
5e5a1ad
to
2faf497
Compare
...o-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/glue/GlueIcebergTableOperations.java
Outdated
Show resolved
Hide resolved
2faf497
to
1fcb7c2
Compare
} | ||
catch (SchemaNotFoundException | ||
| TableAlreadyExistsException | ||
| UnsupportedOperationException 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 UnsupportedOperationException?
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 was looking for createTable
implementation and the exceptions thrown by them. InMemoryThriftMetastore#createTable
throw UnsupportedOperationException
.
But now I realized that InMemoryThriftMetastore
is implemented for test cases. So UnsupportedOperationException
check is needed.
|
||
import java.io.IOException; | ||
|
||
@Test(singleThreaded = true) |
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 single threaded?
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.
My bad. It was not needed earlier. But now it's needed with the latest change (// testException is a shared mutable state).
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
@Test(singleThreaded = true) |
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 single threaded?
|
||
import java.io.IOException; | ||
|
||
@Test(singleThreaded = true) |
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 single threaded?
...io/trino/plugin/iceberg/catalog/file/TestIcebergFileCreateTableFailureMetadataCleanedUp.java
Outdated
Show resolved
Hide resolved
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
@Test(singleThreaded = true) | ||
public abstract class BaseIcebergFileCreateTableFailureTest |
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 doesn't need to be a base class with two subclasses.
- one option is to just move QueryRunner setup to a test method (or helper of a test method) and have ordinary test class with two test methods
- clean
- the downside is that you pay query runner setup cost twice
- another option is to just have a query runner and a test instance field (eg AtomicReference) which determines what exception to throw
- this would be very similar to the code you have
- a bit less clean as you have a mutable field
- but you pay query runner setup cost once only
- this is the option i'd implement
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 followed the 2nd option.
throws Exception | ||
{ | ||
this.dataDirectory = Files.createTempDirectory("test_iceberg_create_table_failure"); | ||
this.metastore = new FileHiveMetastore( |
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 am not entirely sure we need that test, since file metastore is just a testing utliity.
if we use file metastore as an approximation of HMS, that's also fine, but let's have a code comment explaining that
1fcb7c2
to
915e512
Compare
@krvikash please rebase & resolve the conflicts. |
915e512
to
bdf2fea
Compare
Rebased with master. |
Hi @ebyhr, when you get time could you please review this PR? |
...rc/test/java/io/trino/plugin/iceberg/catalog/file/TestIcebergFileCreateTableFailureTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/iceberg/catalog/file/TestIcebergFileCreateTableFailureTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/iceberg/catalog/file/TestIcebergFileCreateTableFailureTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/iceberg/catalog/file/TestIcebergFileCreateTableFailureTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/iceberg/catalog/file/TestIcebergFileCreateTableFailureTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/iceberg/catalog/file/TestIcebergFileCreateTableFailureTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/iceberg/catalog/file/TestIcebergFileCreateTableFailureTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/iceberg/catalog/glue/TestIcebergGlueCreateTableFailureTest.java
Outdated
Show resolved
Hide resolved
bdf2fea
to
311ae6e
Compare
Thanks, @ebyhr for the review. I have addressed the comments and updated the PR. |
/test-with-secrets sha=311ae6e98b205d8d9eea761fd75b0b4d1cd375d7 |
311ae6e
to
d657166
Compare
I pushed a small fix to rename test classes:
|
d657166
to
b36e2aa
Compare
b36e2aa
to
b8dd25d
Compare
Description
Fixes #14798
Iceberg connector creates a new metadata file when we do DDL/DML operation. In such case, if the operation gets fails then the metadata file does not get cleanup. Metastore Table Operation can fail in various cases like permission denied, and not having valid credentials. This fix will cleanup the metadata file if gets it is created.
The fix is inspired from https://github.com/apache/iceberg/blob/3cddc9f28c93b9231060ecb6b90e2d524bd5d160/aws/src/main/java/org/apache/iceberg/aws/glue/GlueTableOperations.java#L142
Non-technical explanation
NA
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: