Repository navigation
Conversation
dimas-b
left a comment
There was a problem hiding this comment.
Glad to see progress on this feature 🚀
This is a partial review 😅
| + " soft-deleted for a hold period instead of permanently removing it. Soft-deleted" | ||
| + " tables are hidden from Iceberg REST list/load/HEAD, the identifier stays" | ||
| + " reserved until permanent delete, and data files are not deleted. Default is" | ||
| + " false (today's hard DROP). DROP TABLE with purge remains an immediate" |
There was a problem hiding this comment.
nit: today is different every day 😉 Maybe just hard DROP?
There was a problem hiding this comment.
updated to hard DROP :)
|
|
||
| public static final FeatureConfiguration<String> TABLE_SOFT_DELETE_HOLD_PERIOD = | ||
| PolarisConfiguration.<String>builder() | ||
| .key("TABLE_SOFT_DELETE_HOLD_PERIOD") |
There was a problem hiding this comment.
How do you envision actually purging soft-deleted tables?
There was a problem hiding this comment.
phase 1 is lazy on namespace access, not a scheduled sweep (this is also @jbonofre's question on https://lists.apache.org/thread/1djyz0x3k7m71d71bqhw11c3syyshtdr).
when TABLE_SOFT_DELETE_ENABLED is false (the default), expiration is a no-op: a config check only, no extra scan.
when it is enabled, the next list, create, or drop-namespace in that namespace loads Iceberg tables under it (including dropped ones) and permanently deletes those whose toPurgeTimestamp has passed. catalog state is always removed then. file cleanup is a separate flag and uses the existing ENTITY_CLEANUP_SCHEDULER. There is no dedicated expiration task, and no purge-now API, in phase 1.
I spelled that out on TABLE_SOFT_DELETE_HOLD_PERIOD. Cost is confined to catalogs that opt in; a namespace with many held tables pays a full Iceberg-table listing on those operations. scheduled sweep can wait until we know whether lazy-on-access is enough.
| "If set to true, permanent delete of a previously soft-deleted Iceberg table" | ||
| + " enqueues the existing entity-cleanup task so data and metadata files may" | ||
| + " be removed. Used only when TABLE_SOFT_DELETE_ENABLED is true. Default is" | ||
| + " false (catalog state is removed; files are left in place).") |
There was a problem hiding this comment.
If false reusing the table name will effectively enable the new table owner to access old table's data. This is still a serious risk, I think... until Polaris enforces unique table locations.
I'd prefer to avoid this risk by always deleting data files on purge.
There was a problem hiding this comment.
hmm yes, agreed that is a real risk until unique table locations are the catalog invariant. after the hold we free the name, so a recreate at the same location can see leftover files.
I left the flag default-off for phase 1 so expire matches today's DROP without purge (catalog state gone, files remain) and so opting into hold/recover does not also become delayed file deletion. DROP PURGE on a live table is still immediate destroy, including files.
if you would rather Phase 1 always enqueue entity-cleanup when a soft-deleted table is permanently deleted (drop the flag, or default it true), I can do that. That would make expire match DROP PURGE for files and close the recreate-at-same-location leak while unique locations are still opt-in.
There was a problem hiding this comment.
Enqueueing cleanup on every permanent delete would still leave a name-reuse window. dropEntityIfExists releases the identifier before asynchronous cleanup runs, so a recreate at the same location can succeed while the old files remain. Same-location recreation needs to stay blocked until file cleanup, including the child tasks spawned by the cleanup scheduler, has completed, unless we can guarantee isolation from the retained location. A test with cleanup paused would pin that ordering.
There was a problem hiding this comment.
Actually, this is a bigger problem. Even with current Polaris code, deleting a table without purge does not delete its data. I think the proposed soft-deleted table cleanup logic is in-line with existing Polaris behaviours.
I'd just propose to enable this flag by default.
There was a problem hiding this comment.
+1, expire still does this. dropEntityIfExists and the name is free before cleanup is done.
There was a problem hiding this comment.
Once the hold expires, the name is released even if the cleanup task hasn't finished yet. So a new catalog can be created with the same name while the old files are still being removed, just like DROP PURGE.
Keeping the name reserved until cleanup completes would be a bigger lifecycle change. Maybe we can look at that separately? WDYT?
There was a problem hiding this comment.
Keeping the name reserved until cleanup completes would be a bigger lifecycle change
This looks like the best solution, but +1 to look into it separately.
There was a problem hiding this comment.
I'd take that as a follow-up.
| boolean cleanup = | ||
| realmConfig.getConfig( | ||
| FeatureConfiguration.TABLE_SOFT_DELETE_PURGE_DATA_ON_PERMANENT_DELETE, catalogEntity); | ||
| Map<String, String> cleanupProperties = | ||
| cleanup ? new HashMap<>(catalogEntity.getInternalPropertiesAsMap()) : Map.of(); |
There was a problem hiding this comment.
IIUC, with purge-on-expiration enabled, the cleanup task is missing the table's storage location. This map only copies catalog internal properties, but TaskFileIOSupplier reads STORAGE_LOCATION from the task and calls Set.of(location), so cleanup fails with a NPE before deleting any files, after the catalog entity is already gone. Please make expiration with purge enabled actually delete the files and cover it through task execution. Reusing the per-table cleanup context assembled by dropTable is one option.
There was a problem hiding this comment.
Thanks for catching both issues. @flyingImer
For listTables when soft-delete is disabled, we now always use listFullEntities and filter out dropped entities. So a table deleted when the flag was on will not show up again after the flag is turned off.
For expire + purge, we no longer pass catalog-only internal props to the cleanup task. Expire now builds the same purge map as dropTable (metadata +/ storage hierarchy + storageLocation). If metadata read fails, we log a warning and skip the data purge. WDYT?
| return listResult | ||
| .getPage() | ||
| .map(record -> TableIdentifier.of(parentNamespace, record.getName())); | ||
| if (!tableSoftDeleteEnabled()) { |
There was a problem hiding this comment.
Disabling soft-delete makes previously dropped tables appear in LIST again. Their name-index records are intentionally retained, and this branch returns them without checking isDropped, while LOAD/HEAD still reject them. Please keep existing dropped tables hidden independently of whether new drops are soft-deleted, with an enable/drop/disable/list regression test.
left a comment
There was a problem hiding this comment.
Nice phase-1 shape. Reusing dropTimestamp/toPurgeTimestamp plus the resolver's existing isDropped() handling keeps this small, and the default-off flag protects existing users. Things I'd like to see before merge:
- Name reservation vs cleanup: the dev-list thread (2026-10-22) agreed that a name stays reserved until entity cleanup and its child tasks finish. Here, expiry hard-deletes the entity as soon as the hold ends, even when cleanup is skipped. Is that coming in this PR?
- Tests: can we add SPI-level
softDeleteEntityIfExistscases to BasePolarisMetaStoreManagerTest (already dropped, undroppable, concurrent modification, permanent drop of a soft-deleted entity)? Also a handler test for the external-catalog 400,dropNamespace/rename tests with a held table, and a REST IT for list/load/HEAD hiding. - Docs: can the CHANGELOG and flag docs mention that held tables block drop-namespace, and what happens to them when the flag is turned off?
- Authz: list/create can now permanently delete expired tables. Can we call that out in the docs so it's an explicit decision?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| op, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier); | ||
|
|
||
| CatalogEntity catalog = getResolvedCatalogEntity(); | ||
| if (realmConfig().getConfig(FeatureConfiguration.TABLE_SOFT_DELETE_ENABLED, catalog) |
There was a problem hiding this comment.
If an operator sets TABLE_SOFT_DELETE_ENABLED=true realm-wide, every non-purge DROP on a federated/external catalog starts failing with 400. Those catalogs never asked for soft-delete, so this is a pretty surprising regression. Can we just fall through to the normal hard drop for external catalogs instead of rejecting?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
There was a problem hiding this comment.
Realm-wide setting is the Admin User's choice. It applies to all catalogs, so the failure is justified.
| * No-op when soft-delete is disabled. Catalog-only: files are purged only if configured. | ||
| */ | ||
| private void expireEligibleSoftDeletedTables(List<PolarisEntity> catalogPath) { | ||
| if (!tableSoftDeleteEnabled()) { |
There was a problem hiding this comment.
Once the flag is turned off, expiry never runs again. Any tables that were soft-deleted earlier stay hidden, keep their names reserved, and keep dropNamespace failing forever, and testSoftDeletedTablesStayHiddenWhenSoftDeleteDisabled locks that in. Should expiry keep running whenever held rows exist, regardless of the flag?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| long now = System.currentTimeMillis(); | ||
| List<PolarisBaseEntity> entities = | ||
| getMetaStoreManager() | ||
| .listFullEntitiesAll( |
There was a problem hiding this comment.
This loads every full table entity in the namespace on every listTables page and every create. Pagination then stops helping on big namespaces, since page 1 of a 10k-table namespace pays the full scan. Can we bound it (cap per call, or only scan when something can be held)?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| metadataLocation, | ||
| identifier, | ||
| e); | ||
| purgeEntity = false; |
There was a problem hiding this comment.
If the metadata read fails, we flip purgeEntity to false but still hard-delete the entity just below. With purge-on-expire on, the files are orphaned for good and the name is freed even though cleanup never ran. Can we keep the entity in this case so the next expiry pass can retry?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
There was a problem hiding this comment.
Makes sense, that was still deleting the entity. if the metadata read fails we leave it in place now, so the next list or create can retry. the name stays reserved until that works
| List<PolarisEntity> catalogPath = resolvedEntities.getRawParentPath(); | ||
| PolarisEntity leafEntity = resolvedEntities.getRawLeafEntity(); | ||
|
|
||
| expireEligibleSoftDeletedTables(resolvedEntities.getRawFullPath()); |
There was a problem hiding this comment.
During the hold, dropNamespace fails with 'Namespace is not empty' while listTables returns nothing, which is confusing for users. Can the error say that a soft-deleted table is blocking the drop?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| return realmConfig.getConfig(FeatureConfiguration.TABLE_SOFT_DELETE_ENABLED, catalogEntity); | ||
| } | ||
|
|
||
| private long softDeleteHoldPeriodMillis() { |
There was a problem hiding this comment.
A bad hold-period value is operator config, but it surfaces as a 400 on the end user's DROP. Can we validate it when catalog properties are set instead?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| @NonNull PolarisBaseEntity entityToDrop, | ||
| long dropTimestamp, | ||
| long toPurgeTimestamp) { | ||
| throw new UnsupportedOperationException("softDeleteEntityIfExists"); |
There was a problem hiding this comment.
Custom metastore managers inherit this throwing default, so enabling the flag on them will 500 on every DROP. Can we say that in the javadoc?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| public static final FeatureConfiguration<String> TABLE_SOFT_DELETE_HOLD_PERIOD = | ||
| PolarisConfiguration.<String>builder() | ||
| .key("TABLE_SOFT_DELETE_HOLD_PERIOD") | ||
| .catalogConfig("polaris.config.table-soft-delete.hold-period") |
There was a problem hiding this comment.
Can this be merged with TABLE_SOFT_DELETE_ENABLED?.. i.e. if the period is set, soft-delete is enabled?
| "If set to true, permanent delete of a previously soft-deleted Iceberg table" | ||
| + " enqueues the existing entity-cleanup task so data and metadata files may" | ||
| + " be removed. Used only when TABLE_SOFT_DELETE_ENABLED is true. Default is" | ||
| + " false (catalog state is removed; files are left in place).") |
There was a problem hiding this comment.
Actually, this is a bigger problem. Even with current Polaris code, deleting a table without purge does not delete its data. I think the proposed soft-deleted table cleanup logic is in-line with existing Polaris behaviours.
I'd just propose to enable this flag by default.
| */ | ||
| public Page<T> filter(Predicate<T> predicate) { | ||
| return new Page<>( | ||
| request, nextToken, items.stream().filter(predicate).collect(Collectors.toList())); |
There was a problem hiding this comment.
This could leave the current page empty. I'm fine with that behaviour. Just flagging it for review in case other people have different opinions.
There was a problem hiding this comment.
Thanks for flagging. I'll leave empty pages as they are.
| * @param dropTimestamp epoch millis when the entity was soft-deleted | ||
| * @param toPurgeTimestamp epoch millis when the entity becomes eligible for permanent delete | ||
| */ | ||
| default @NonNull DropEntityResult softDeleteEntityIfExists( |
There was a problem hiding this comment.
Is "If Exists" relevant to soft deletes? If something does not exist we cannot mark it in anyway.
In fact, AtomicOperationMetaStoreManager fails these calls for non-existent entities 🤔
There was a problem hiding this comment.
kept IfExists to match dropEntityIfExists.
missing entity still returns ENTITY_NOT_FOUND. already-dropped is a successful no-op so a retry during hold does not fail. happy to rename if you would rather it not echo the drop method.
There was a problem hiding this comment.
I'd rename to softDeleteEntity... TBH, I do not find meaning in the "If Exists" suffix 🤔 We do not have to follow existing method naming patterns blindly :)
In the SQL world "if exists" usually means that the operation is a no-op for non-existent entities, but as I noted above this logic does not hold in the current impl.
| @NonNull PolarisBaseEntity entityToDrop, | ||
| long dropTimestamp, | ||
| long toPurgeTimestamp) { | ||
| throw new UnsupportedOperationException("softDeleteEntityIfExists"); |
There was a problem hiding this comment.
I do not agree with adding default methods to SPI interfaces.
This masks the need to implement the feature is custom (downstream) SPI implementations.
If am impl. chooses to fail the call unconditionally, it is easy to add the throw clause there. The key aspect is that it has to be a deliberate implementation choice.
There was a problem hiding this comment.
agreed, default throw was the wrong shape.
softDeleteEntityIfExists is a real SPI method now. Atomic, Transactional and NoSQL already implement it. TransactionWorkspace throws, same as dropEntityIfExists.
| op, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier); | ||
|
|
||
| CatalogEntity catalog = getResolvedCatalogEntity(); | ||
| if (realmConfig().getConfig(FeatureConfiguration.TABLE_SOFT_DELETE_ENABLED, catalog) |
There was a problem hiding this comment.
Realm-wide setting is the Admin User's choice. It applies to all catalogs, so the failure is justified.
| } | ||
|
|
||
| List<PolarisEntity> catalogPath = resolvedParent.getRawFullPath(); | ||
| expireEligibleSoftDeletedTables(catalogPath); |
There was a problem hiding this comment.
I'm hesitant to do the expiration on the drop call paths of other entities.
I think it creates hard-to-predict behaviours. Plus, other drops may never come after an entity is soft-deleted.
WDYT about doing the expiry via the Admin Tool? https://github.com/apache/polaris/tree/main/runtime/admin
There was a problem hiding this comment.
Also (from Codex):
- [P2] Creation expires tables after overlap validation — LocalIcebergCatalog.java:2909 (runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/LocalIcebergCatalog.java:2909)
With OPTIMIZED_SIBLING_CHECK enabled, recreating an expired table at its previous location fails: doCommit() checks location overlap while the dropped entity still occupies the location index, before reaching this expiration hook. This prevents the documented create-triggered expiration unless another operation expires the entry first. Expiration needs to precede overlap validation.
| String locationDir = | ||
| metadataLocation.substring(0, metadataLocation.lastIndexOf('/')); | ||
| PolarisResolvedPathWrapper resolvedStorage = | ||
| CatalogUtils.findResolvedStorageEntity(resolvedEntityView, identifier); |
There was a problem hiding this comment.
- [P1] Purge-on-expiry never completes through REST requests — LocalIcebergCatalog.java:3116 (runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/LocalIcebergCatalog.java:3116)
Namespace list/create/drop requests do not register the expired tables in the resolution manifest. findResolvedStorageEntity() queries an unregistered table path and throws; the catch block retains the entry on every retry. With purge-on-expiry enabled, names remain reserved and namespaces cannot become empty. Build the storage context from the supplied namespace path and persisted entity. The tests’ dynamic resolution view masks this failure.
| } | ||
|
|
||
| List<PolarisEntity> catalogPath = resolvedParent.getRawFullPath(); | ||
| expireEligibleSoftDeletedTables(catalogPath); |
There was a problem hiding this comment.
Also (from Codex):
- [P2] Creation expires tables after overlap validation — LocalIcebergCatalog.java:2909 (runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/LocalIcebergCatalog.java:2909)
With OPTIMIZED_SIBLING_CHECK enabled, recreating an expired table at its previous location fails: doCommit() checks location overlap while the dropped entity still occupies the location index, before reaching this expiration hook. This prevents the documented create-triggered expiration unless another operation expires the entry first. Expiration needs to precede overlap validation.
| long now = System.currentTimeMillis(); | ||
| List<PolarisBaseEntity> entities = | ||
| getMetaStoreManager() | ||
| .listFullEntitiesAll( |
There was a problem hiding this comment.
- [P2] Every list page scans the entire namespace — LocalIcebergCatalog.java:3092 (runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/LocalIcebergCatalog.java:3092)
When soft-delete is enabled, each page calls listFullEntitiesAll(), loading every table and its properties even when nothing is dropped. Listing N tables across N/page-size pages therefore processes roughly N²/page-size entities, defeating bounded pagination and increasing memory use and latency. Expiration should use bounded batches or an expiry-specific query.
| .getPage() | ||
| .map(record -> TableIdentifier.of(parentNamespace, record.getName())); | ||
| return getMetaStoreManager() | ||
| .listFullEntities( |
There was a problem hiding this comment.
Thanks @iprithv for the PR, quick question here - looks like this moves listTables/listViews over to listFullEntities for every catalog, even ones that never turn soft-delete on. On JDBC that's all columns and no LIMIT, just to get names back. Correct me if I am wrong but I get why: EntityNameLookupRecord has no drop timestamp, and tables dropped while the flag was on need to stay hidden after it's off.
Could we filter out dropped entities in listEntities itself instead, e.g. drop_timestamp = 0 on JDBC? Then the default list path stays as light as it is today. WDYT?
There was a problem hiding this comment.
You're right, that was a JDBC full scan for catalogs that never turn the flag on.
With the flag off, listTables / listViews use listEntities as before. listFullEntities + filter(isDropped()) is only used for Iceberg tables when the flag is on. Views always stay on the cheap path.
One edge case is if the flag is turned off while held rows still exist. The list could show the reserved name, but load / HEAD would still return 404. If the holds expire first, this shouldn't come up.
425881e to
f4687d6
Compare
left a comment
There was a problem hiding this comment.
Thanks @iprithv.. Admin tool expire is the right place. Leftover notes on that path.
commented
Nov 17, 2026
|
Heads-up: #5967 has been merged, so Could you rebase onto |
| "If set to true, permanent delete of a previously soft-deleted Iceberg table" | ||
| + " enqueues the existing entity-cleanup task so data and metadata files may" | ||
| + " be removed. Used only when TABLE_SOFT_DELETE_ENABLED is true. Default is" | ||
| + " false (catalog state is removed; files are left in place).") |
There was a problem hiding this comment.
Keeping the name reserved until cleanup completes would be a bigger lifecycle change
This looks like the best solution, but +1 to look into it separately.
| toPurgeTimestamp, | ||
| original); | ||
|
|
||
| long now = System.currentTimeMillis(); |
There was a problem hiding this comment.
We should inject the application-wide Clock here instead.
| .getConfig( | ||
| FeatureConfiguration.TABLE_SOFT_DELETE_PURGE_DATA_ON_PERMANENT_DELETE, | ||
| catalogEntity); | ||
| long now = System.currentTimeMillis(); |
| * | ||
| * @param catalogName when non-null, only this catalog is scanned | ||
| */ | ||
| public @NonNull Summary expireAll( |
There was a problem hiding this comment.
Should this class be a CDI bean and have these parameters injected?
There was a problem hiding this comment.
i'd keep the helper a plain class, clock comes in from the Admin Tool command. CDI bean can wait unless you want it here
thoughts?
commented
Nov 17, 2026
|
This PR goes in the right direction, but as I said on the mailing list, I think we should think of the table lifecycle more holistically, and introduce a "soft-created" state, for staged table creations. IOW, the table would be in 3 possible states: I don't suggest we do all of this in one PR, but maybe we should pause and rethink the feature flags and schema changes that we are introducing here, and make sure they make room for soft-creations. |
| description = | ||
| "Permanently delete Iceberg tables whose soft-delete hold has expired. Names stay reserved" | ||
| + " until this command runs.") | ||
| public class ExpireSoftDeletedTablesCommand extends BaseMetaStoreCommand { |
There was a problem hiding this comment.
Agree, an auto expire task would be nicer for operators. i'd do it as a follow-up though, maybe once the task framework is in
commented
Nov 19, 2026
Agree, let's keep this PR scoped to hold + expire via the Admin Tool. we're reusing the existing wdyt? |
Signed-off-by: prithvi <[email protected]>
Signed-off-by: prithvi <[email protected]>
Always hide dropped tables in listTables even when soft-delete is disabled, and build per-table purge storage properties on expire like drop-with-purge.
DROP still reserves the name for the hold period. Permanent delete is an operator command (expire-soft-deleted-tables), not a side-effect of list, create, or drop-namespace. listTables uses listEntities when the flag is off. Signed-off-by: Prithvi S <[email protected]>
Expire purge now records write.data.path and write.metadata.path via StorageUtil.getLocationsUsedByTable, matching DROP PURGE. Regenerate config docs so config-doc-verify matches the generator. Signed-off-by: Prithvi S <[email protected]>
Inject the application Clock instead of System.currentTimeMillis for soft-delete and expire. The new SPI takes Instant; persistence still stores epoch millis on dropTimestamp / toPurgeTimestamp. Move the release note into changelog.d after apache#5967. Signed-off-by: Prithvi S <[email protected]>
97243a4 to
c93cbd2
Compare
Polaris DROP is hard from the catalog's point of view: the name is gone immediately, and there is no hold. Operators who need a recoverable drop have no first-class path.
This is phase 1 of #5054. Default stays today's hard DROP. When
polaris.config.table-soft-delete.enabledis true on an INTERNAL catalog,DROP TABLEwithout purge keeps the entity for a hold period (P7Dby default), hides it from Iceberg REST list/load/HEAD, and reserves the name.DROP TABLE PURGEstays an immediate permanent delete.After the hold, permanent delete is the Admin Tool command
expire-soft-deleted-tables, not a side-effect of list, create, or drop-namespace. File cleanup is opt-in viapolaris.config.table-soft-delete.purge-data-on-permanent-delete. Enabling the flag on an external catalog returns 400.STAGED/LIVE/DELETED and staged create stay follow-ups. Flags and
dropTimestamp == 0leave room for that later.