Fix DROP TABLE cancellation and prevent Iceberg phantom delete queries #26715
+121
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
DROP TABLE operations in Trino were not properly cancellable, leading to resource exhaustion issues particularly with Iceberg tables:
DropTableTask.execute()
returnedimmediateVoidFuture()
and performed operations synchronouslyDataDefinitionExecution.cancelQuery()
only changed query state but didn't cancel the actual running operationdropTableData()
) continued running in the background even after the query was "cancelled"The stack trace from the issue shows queries stuck in
CatalogUtil.deleteFiles()
:Solution
Core DDL Framework Changes
DataDefinitionExecution.java:
@ForQueryExecution ExecutorService
instead of running them synchronouslyvolatile ListenableFuture<Void> runningFuture
cancelQuery()
to actually cancel the running future withfuture.cancel(true)
instead of just changing stateBefore:
After:
Iceberg Connector Changes
Added interruption handling to all Iceberg catalog implementations that perform long-running
dropTableData()
operations:TrinoHiveCatalog.java, TrinoGlueCatalog.java, TrinoJdbcCatalog.java:
dropTableData()
operationInterruptedException
by restoring thread interrupt statusBefore:
After:
Testing
Added
testDropTableIsCancellable()
test case to verify that DROP TABLE operations can be properly cancelled using executor service futures.Impact
✅ DROP TABLE operations are now properly cancellable - No more phantom delete queries continuing in the background
✅ Prevents resource exhaustion - Iceberg worker pools are no longer hogged by cancelled operations
✅ Maintains backward compatibility - Normal DROP TABLE operations continue to work as expected
✅ Comprehensive coverage - All Iceberg catalog implementations (HMS, Glue, JDBC) support proper cancellation
This resolves the core issue where cancelled DROP TABLE queries would continue consuming cluster resources, particularly problematic for large Iceberg tables with many files to delete.
Original prompt
This section details on the original issue you should resolve
<issue_title>Drop Table task is not cancellable/Iceberg phantom delete queries</issue_title>
<issue_description>From
io.trino.execution.DropTableTask#execute
. The code isAlso,
io.trino.execution.DataDefinitionExecution#cancelQuery
doesn't really cancel future that is created inio.trino.execution.DataDefinitionExecution#start
.This means DDLs (and DTOP TABLE) are generally not cancellable.
In case of iceberg,
DROP TABLE
will delete files:->
but it's not stopping even after
DROP
table is abandoned. This is hogging Iceberg worker pool which causes cluster to stall</issue_description>Comments on the Issue (you are @copilot in this section)
@sopel39 cc @raunaqmorarka @ebyhr @osscm @findinpath @sopel39 Pherhaps we could have separate thread pool for DROP table iceberg ops @sopel39 Additionally, I think cancelling DROP table might leave table in stalled state (to be confirmed), e.g: ``` @OverRide public void dropTable(ConnectorSession session, SchemaTableName schemaTableName) { BaseTable table = loadTable(session, schemaTableName); TableMetadata metadata = table.operations().current();