lakekeeper: Trino's `expire_snapshot` Not Deleting S3 Files and Raise Error (Soft-Deletion Disabled)

Describe the bug I’m encountering potential issues with deleting underlying files in S3 using maintenance procedures like expire_snapshots in Trino. While Spark seems to handle this correctly under different soft-deletion configurations, Trino exhibits inconsistent behavior.

For Spark:

  • Soft-deletion disabled: Spark’s expire_snapshots successfully deletes both metadata and the corresponding files without requiring any specific S3 deletion configurations.
  • Soft-deletion enabled: Spark also manages to delete both metadata and files when the s3.delete-enabled: true configuration is explicitly set in the client. And it works.

However, with Trino, I’m experiencing a problem. Even when soft-deletion is disabled, Trino fails to remove the underlying files in S3 during the expire_snapshots process. Note, the metadata snapshots are deleted as expected, but the actual data files remain in S3, and raise errors.

Message error:

Caused by: java.sql.SQLException: Query failed (#20250429_025633_00022_wwef4): Failed to delete files during snapshot expiration
	at io.trino.jdbc.ResultUtils.resultsException(ResultUtils.java:33)
	at io.trino.jdbc.AsyncResultIterator.lambda$new$1(AsyncResultIterator.java:93)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: io.trino.spi.TrinoException: Failed to delete files during snapshot expiration
	at io.trino.plugin.iceberg.IcebergMetadata.executeExpireSnapshots(IcebergMetadata.java:2188)
	at io.trino.plugin.iceberg.IcebergMetadata.executeTableExecute(IcebergMetadata.java:2087)
	at io.trino.plugin.base.classloader.ClassLoaderSafeConnectorMetadata.executeTableExecute(ClassLoaderSafeConnectorMetadata.java:217)
	at io.trino.tracing.TracingConnectorMetadata.executeTableExecute(TracingConnectorMetadata.java:188)
	at io.trino.metadata.MetadataManager.executeTableExecute(MetadataManager.java:370)
	at io.trino.tracing.TracingMetadata.executeTableExecute(TracingMetadata.java:238)
	at io.trino.operator.SimpleTableExecuteOperator.getOutput(SimpleTableExecuteOperator.java:128)
	at io.trino.operator.Driver.processInternal(Driver.java:403)
	at io.trino.operator.Driver.lambda$process$8(Driver.java:306)
	at io.trino.operator.Driver.tryWithLock(Driver.java:709)
	at io.trino.operator.Driver.process(Driver.java:298)
	at io.trino.operator.Driver.processForDuration(Driver.java:269)
	at io.trino.execution.SqlTaskExecution$DriverSplitRunner.processFor(SqlTaskExecution.java:890)
	at io.trino.execution.executor.dedicated.SplitProcessor.run(SplitProcessor.java:77)
	at io.trino.execution.executor.dedicated.TaskEntry$VersionEmbedderBridge.lambda$run$0(TaskEntry.java:201)
	at io.trino.$gen.Trino_474____20250423_102443_2.run(Unknown Source)
	at io.trino.execution.executor.dedicated.TaskEntry$VersionEmbedderBridge.run(TaskEntry.java:202)
	at io.trino.execution.executor.scheduler.FairScheduler.runTask(FairScheduler.java:177)
	at io.trino.execution.executor.scheduler.FairScheduler.lambda$submit$0(FairScheduler.java:164)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:545)
	at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:131)
	at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:75)
	at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:82)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1095)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:619)
	at java.base/java.lang.Thread.run(Thread.java:1447)
Caused by: io.trino.filesystem.TrinoFileSystemException: Error while batch deleting files
	at io.trino.filesystem.s3.S3FileSystem.deleteObjects(S3FileSystem.java:213)
	at io.trino.filesystem.s3.S3FileSystem.deleteFiles(S3FileSystem.java:177)
	at io.trino.filesystem.switching.SwitchingFileSystem.deleteFiles(SwitchingFileSystem.java:94)
	at io.trino.filesystem.tracing.TracingFileSystem.lambda$deleteFiles$1(TracingFileSystem.java:89)
	at io.trino.filesystem.tracing.Tracing.lambda$withTracing$1(Tracing.java:42)
	at io.trino.filesystem.tracing.Tracing.withTracing(Tracing.java:51)
	at io.trino.filesystem.tracing.Tracing.withTracing(Tracing.java:41)
	at io.trino.filesystem.tracing.TracingFileSystem.deleteFiles(TracingFileSystem.java:89)
	at io.trino.filesystem.cache.CacheFileSystem.deleteFiles(CacheFileSystem.java:148)
	at io.trino.plugin.iceberg.IcebergMetadata.executeExpireSnapshots(IcebergMetadata.java:2185)
	... 25 more
Caused by: software.amazon.awssdk.core.exception.SdkClientException: Unable to load credentials from any of the providers in the chain AwsCredentialsProviderChain(credentialsProviders=[SystemPropertyCredentialsProvider(), EnvironmentVariableCredentialsProvider(), WebIdentityTokenCredentialsProvider(), ProfileCredentialsProvider(profileName=default, profileFile=ProfileFile(sections=[])), ContainerCredentialsProvider(), InstanceProfileCredentialsProvider()]) : [SystemPropertyCredentialsProvider(): Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId)., EnvironmentVariableCredentialsProvider(): Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId)., WebIdentityTokenCredentialsProvider(): Either the environment variable AWS_WEB_IDENTITY_TOKEN_FILE or the javaproperty aws.webIdentityTokenFile must be set., ProfileCredentialsProvider(profileName=default, profileFile=ProfileFile(sections=[])): Profile file contained no credentials for profile 'default': ProfileFile(sections=[]), ContainerCredentialsProvider(): Cannot fetch credentials from container - neither AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variables are set., InstanceProfileCredentialsProvider(): Failed to load credentials from IMDS.]
	at software.amazon.awssdk.core.exception.SdkClientException$BuilderImpl.build(SdkClientException.java:130)
	at software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain.resolveCredentials(AwsCredentialsProviderChain.java:130)
	at software.amazon.awssdk.auth.credentials.internal.LazyAwsCredentialsProvider.resolveCredentials(LazyAwsCredentialsProvider.java:45)
	at software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider.resolveCredentials(DefaultCredentialsProvider.java:129)
	at software.amazon.awssdk.auth.credentials.AwsCredentialsProvider.resolveIdentity(AwsCredentialsProvider.java:54)
	at software.amazon.awssdk.services.s3.auth.scheme.internal.S3AuthSchemeInterceptor.lambda$trySelectAuthScheme$6(S3AuthSchemeInterceptor.java:169)
	at software.amazon.awssdk.core.internal.util.MetricUtils.reportDuration(MetricUtils.java:80)
	at software.amazon.awssdk.services.s3.auth.scheme.internal.S3AuthSchemeInterceptor.trySelectAuthScheme(S3AuthSchemeInterceptor.java:169)
	at software.amazon.awssdk.services.s3.auth.scheme.internal.S3AuthSchemeInterceptor.selectAuthScheme(S3AuthSchemeInterceptor.java:87)
	at software.amazon.awssdk.services.s3.auth.scheme.internal.S3AuthSchemeInterceptor.beforeExecution(S3AuthSchemeInterceptor.java:67)
	at software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain.lambda$beforeExecution$1(ExecutionInterceptorChain.java:59)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
	at software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain.beforeExecution(ExecutionInterceptorChain.java:59)
	at software.amazon.awssdk.awscore.internal.AwsExecutionContextBuilder.runInitialInterceptors(AwsExecutionContextBuilder.java:254)
	at software.amazon.awssdk.awscore.internal.AwsExecutionContextBuilder.invokeInterceptorsAndCreateExecutionContext(AwsExecutionContextBuilder.java:144)
	at software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler.invokeInterceptorsAndCreateExecutionContext(AwsSyncClientHandler.java:67)
	at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.lambda$execute$1(BaseSyncClientHandler.java:76)
	at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.measureApiCallSuccess(BaseSyncClientHandler.java:182)
	at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.execute(BaseSyncClientHandler.java:74)
	at software.amazon.awssdk.core.client.handler.SdkSyncClientHandler.execute(SdkSyncClientHandler.java:45)
	at software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler.execute(AwsSyncClientHandler.java:53)
	at software.amazon.awssdk.services.s3.DefaultS3Client.deleteObjects(DefaultS3Client.java:3640)
	at io.trino.filesystem.s3.S3FileSystem.deleteObjects(S3FileSystem.java:207)
	... 34 more

To Reproduce Steps to reproduce the behavior, preferably starting from one of our docker-compose examples.

  1. Connect Trino in DBeaver
  2. Run expire_snapshot and get errors

Expected behavior Trino can run expire_snapshot without errors and delete both metadata and files underlying S3 storage

Screenshots Check number of files and snapshots before executing procedure using Trino Image

Run expire_snapshot and got errors Image

Check files and snapshots metadata after executing. Metadata is deleted as expected, but not files Image

System Information:

  • Deployment Type: Heml
  • Lakekeeper Version: 0.8.3
  • Authentication Provider: Keycloak
  • Authorization Provider: OpenFGA

Additional context Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (2 by maintainers)

Most upvoted comments

After debugging trino for a bit, I’ve found:

  1. there are vended credentials in the table config at time of the error
  2. S3FileSystem.context.credentialsProviderOverride (src/main/java/io/trino/filesystem/s3/S3FileSystem.java) has as corresponding StaticCredentialsProvider(credentials=AwsSessionCredentials(....))
  3. in S3FileSystem::delete_objects there are two config overrides:
                DeleteObjectsRequest request = DeleteObjectsRequest.builder()
                        .overrideConfiguration(context::applyCredentialProviderOverride)
                        .requestPayer(requestPayer)
                        .bucket(bucket)
                        .overrideConfiguration(disableStrongIntegrityChecksums())
                        .delete(builder -> builder.objects(objects).quiet(true))
                        .build();

After stepping through this in a debugger, it appears that after .overrideConfiguration(context::applyCredentialProviderOverride) the credential provider is set correctly. After .overrideConfiguration(disableStrongIntegrityChecksums()) it’s set to null again which apparently was part of a fix for strong integrity checks:

    // TODO (https://github.com/trinodb/trino/issues/24955):
    // remove me once all of the S3-compatible storage support strong integrity checks
    @SuppressWarnings("deprecation")
    static AwsRequestOverrideConfiguration disableStrongIntegrityChecksums()
    {
        return AwsRequestOverrideConfiguration.builder()
            .signer(AwsS3V4Signer.create())
            .build();
    }

Given all that, my current understanding is that this is a regression in trino introduced to fix issues with signers & strong integrity checks. I’m not sure why, but I cannot build trino locally, it fails on trino-docs. We’ll open an issue at trino.

Once https://github.com/trinodb/trino/pull/25791 is released trino’s expire_snapshots should work. We may have to change default access to vended-credentials as I encountered some errors while testing the 476 + fix image.

Image

After upgrading trino to 475 I can reproduce the credentials error. I’m now trying to understand if it is a regression or if it has been a silent error before. Our example was on trino 467.

Hi @twuebi, My table is quite small(for testing purposes), around 10 rows and 5 snapshots. Btw, my namespace have nearly 50 tables.

I’ll try to reproduce it on Monday. A hunch: maybe trino requires a “batchoperations.s3.amazonaws.com” trust policy. In the logs it states that batch deletion failed. Maybe batch deletion only happens for more files / larger tables which is why we couldn’t reproduce it so far.

Thanks for your respone @c-thiel , I’m also encountering the same keyword error and I’m unsure of the exact cause.

Caused by: io.trino.filesystem.TrinoFileSystemException: Error while batch deleting files
Caused by: software.amazon.awssdk.core.exception.SdkClientException: Unable to load credentials from any of the providers in the chain AwsCredentialsProviderChain

For easier problem tracing, I’m using Ceph RGW.

My config @twuebi , I’m using Trino 474 Lakekeeper v0.8.3 storage conf     {"type": "s3", "bucket": "test-sts-bucket", "flavor": "s3-compat", "region": "us-east-2", "endpoint": "https://ceph-rgw.xyz/", "key-prefix": "test-sts-bucket2", "sts-enabled": true, "sts-role-arn": "arn:aws:iam:::role/cephsts", "assume-role-arn": null, "path-style-access": true, "push-s3-delete-disabled": false, "allow-alternative-protocols": false}


Trino 474 conf
 
     connector.name=iceberg
   iceberg.catalog.type=rest
   iceberg.expire-snapshots.min-retention=0d
   iceberg.remove-orphan-files.min-retention=0d
   iceberg.rest-catalog.uri=...
   iceberg.rest-catalog.warehouse=test-sts-bucket2
   iceberg.rest-catalog.security=OAUTH2
   iceberg.rest-catalog.oauth2.credential=${ENV:LAKEKEEPER_CLIENT_ID}:${ENV:LAKEKEEPER_CLIENT_SECRET}
   iceberg.rest-catalog.vended-credentials-enabled=true
   iceberg.rest-catalog.oauth2.scope=lakekeeper
   iceberg.rest-catalog.oauth2.server-uri=...
   s3.region=us-east-2
   s3.path-style-access=true
   s3.endpoint=...
   fs.native-s3.enabled=true

It still raise error. Following this error, I observed that Trino attempts to use static S3 credentials instead of vended credentials from Lakekeeper to delete S3 files.

Message: Unable to load credentials from any of the providers in the chain AwsCredentialsProviderChain

Credentials Providers Attempted:
1. SystemPropertyCredentialsProvider
  - Error: Unable to load credentials from system settings.
  - Resolution: Access key must be specified via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId).

2. EnvironmentVariableCredentialsProvider
  - Error: Unable to load credentials from system settings.
  - Resolution: Access key must be specified via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId).

3. WebIdentityTokenCredentialsProvider
  - Error: Either the environment variable AWS_WEB_IDENTITY_TOKEN_FILE or the Java property aws.webIdentityTokenFile must be set.

4. ProfileCredentialsProvider
  - Profile Name: default
  - Profile File: ProfileFile(sections=[])
  - Error: Profile file contained no credentials for profile 'default': ProfileFile(sections=[]).

5. ContainerCredentialsProvider
  - Error: Cannot fetch credentials from container.
  - Reason: Neither AWS_CONTAINER_CREDENTIALS_FULL_URI nor AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variables are set.

6. InstanceProfileCredentialsProvider
  - Error: Failed to load credentials from IMDS. ```

Could you provide some additional details, e.g. payload used to create the warehouse, did you set push-s3-delete-disabled to some explicit value? Are you using vended credentials? How to reproduce the errors? I.e. did you set some table properties?

Hi @twuebi, Thanks for the detailed information and the code snippet. My table doesn’t have any properties; I’ve left it with the default settings.

In my case, I’ve already test in both soft-deletion disabled/enabled and regardless of push-s3-delete-disabled=false or push-s3-delete-disabled=true, it still get same error. However, when I try to select snapshots after doing this. The metadata snapshots are deleted as expected, but the actual data files remain in S3, and raise errors.(as my image above).

Here is the code I use to reproduce the error. Could you please rerun it? I’ve also included an UPDATE operation in this case.

CREATE SCHEMA IF NOT EXISTS lakekeeper.trino_namespace;
CREATE TABLE lakekeeper.trino_namespace.my_table (my_ints INT, my_floats DOUBLE, strings VARCHAR) WITH (format='PARQUET')

INSERT INTO lakekeeper.trino_namespace.my_table VALUES (1, 1.0, 'a'), (2, 2.0, 'b');
update lakekeeper.trino_namespace.my_table set strings = 'c';

SELECT * FROM lakekeeper.trino_namespace.my_table;
SELECT * FROM lakekeeper.trino_namespace."my_table$snapshots";

alter table lakekeeper.trino_namespace.my_table execute expire_snapshots(retention_threshold => '0d')

SELECT * FROM lakekeeper.trino_namespace."my_table$snapshots";