Skip to content

add opt-in Iceberg table soft-delete (#5054) - #5544

Open
iprithv wants to merge 7 commits into
apache:mainfrom
iprithv:feat/table-soft-delete-phase1
Open

iprithv wants to merge 7 commits into
apache:mainfrom
iprithv:feat/table-soft-delete-phase1

Conversation

@iprithv

@iprithv iprithv commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

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.enabled is true on an INTERNAL catalog, DROP TABLE without purge keeps the entity for a hold period (P7D by default), hides it from Iceberg REST list/load/HEAD, and reserves the name. DROP TABLE PURGE stays 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 via polaris.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 == 0 leave room for that later.

@dimas-b dimas-b left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: today is different every day 😉 Maybe just hard DROP?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to hard DROP :)


public static final FeatureConfiguration<String> TABLE_SOFT_DELETE_HOLD_PERIOD =
PolarisConfiguration.<String>builder()
.key("TABLE_SOFT_DELETE_HOLD_PERIOD")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ghost Nov 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ghost Nov 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, expire still does this. dropEntityIfExists and the name is free before cleanup is done.

ghost Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

ghost Nov 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ghost Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd take that as a follow-up.

@iprithv
iprithv requested a review from dimas-b September 19, 2026 09:07
@iprithv
iprithv marked this pull request as ready for review September 19, 2026 13:30

ghost left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

three comments cover lifecycle gaps that leave soft-deleted tables inconsistent with their retention and visibility guarantees. The concrete legal-hold use case also still needs clarification on the dev list IMO

Comment on lines +3055 to +3059
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();

ghost Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ghost Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {

ghost Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@iprithv
iprithv requested a review from flyingImer October 3, 2026 03:57

ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 softDeleteEntityIfExists cases 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)

ghost Oct 26, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ghost Nov 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {

ghost Oct 26, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

ghost Oct 26, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

ghost Oct 26, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ghost Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

ghost Oct 26, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

ghost Oct 26, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");

ghost Oct 26, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

ghost Nov 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).")

ghost Nov 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()));

ghost Nov 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ghost Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

ghost Nov 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🤔

ghost Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ghost Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");

ghost Nov 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ghost Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

ghost Nov 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

ghost Nov 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

ghost Nov 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also (from Codex):

  1. [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.

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posting feedback from artificial helpers

String locationDir =
metadataLocation.substring(0, metadataLocation.lastIndexOf('/'));
PolarisResolvedPathWrapper resolvedStorage =
CatalogUtils.findResolvedStorageEntity(resolvedEntityView, identifier);

ghost Nov 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. [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);

ghost Nov 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also (from Codex):

  1. [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(

ghost Nov 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. [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(

ghost Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

ghost Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@iprithv
iprithv force-pushed the feat/table-soft-delete-phase1 branch from 425881e to f4687d6 Compare November 14, 2026 22:59

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @iprithv.. Admin tool expire is the right place. Leftover notes on that path.

@iprithv
iprithv requested review from dimas-b and vigneshio November 15, 2026 19:57
@adutra

ghost commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Heads-up: #5967 has been merged, so CHANGELOG.md is no longer edited directly. Changelog entries now go in a fragment file under changelog.d/, which avoids merge conflicts on CHANGELOG.md. See changelog.d/README.md for the format.

Could you rebase onto main, revert your changes to CHANGELOG.md, and add a fragment file instead if your change needs a changelog entry? A fragment is only needed for things worth calling out in release notes, such as breaking changes, metastore schema changes, or changes that require manual steps during an upgrade. Thanks!

"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).")

ghost Nov 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

ghost Nov 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should inject the application-wide Clock here instead.

.getConfig(
FeatureConfiguration.TABLE_SOFT_DELETE_PURGE_DATA_ON_PERMANENT_DELETE,
catalogEntity);
long now = System.currentTimeMillis();

ghost Nov 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: inject Clock.

*
* @param catalogName when non-null, only this catalog is scanned
*/
public @NonNull Summary expireAll(

ghost Nov 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this class be a CDI bean and have these parameters injected?

ghost Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@adutra

ghost commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

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: STAGED, LIVE, DELETED.

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 {

ghost Nov 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this operation shouldn't also be available as an automatic cleanup task similar to FileCleanupTaskHandler. Can be left for a follow-up task though. It may also require a proper task framework like the one @snazy proposed last year.

ghost Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@iprithv

ghost commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

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: STAGED, LIVE, DELETED.

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.

Agree, let's keep this PR scoped to hold + expire via the Admin Tool.

we're reusing the existing dropTimestamp / toPurgeTimestamp columns, so dropTimestamp == 0 still means "not deleted". that leaves room for a STAGED state later on the same side, no breaking schema change needed. flags for this path stay under table-soft-delete.*.

wdyt?

@iprithv
iprithv requested a review from adutra November 20, 2026 20:37
prithvi added 7 commits November 27, 2026 19:14
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]>
@iprithv
iprithv force-pushed the feat/table-soft-delete-phase1 branch from 97243a4 to c93cbd2 Compare November 27, 2026 13:50

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants