Skip to content

feat(transaction): clean expired metadata in ExpireSnapshotsAction - #3064

Draft
alessandro-nori wants to merge 4 commits into
apache:mainfrom
alessandro-nori:anori/clean-expired-metadata
Draft

feat(transaction): clean expired metadata in ExpireSnapshotsAction#3064
alessandro-nori wants to merge 4 commits into
apache:mainfrom
alessandro-nori:anori/clean-expired-metadata

Conversation

@alessandro-nori

@alessandro-nori alessandro-nori commented Aug 25, 2026

Copy link
Copy Markdown

Which issue does this PR close?

Follows up on #2591, which landed ExpireSnapshotsAction and left this as remaining work: "cleanExpiredMetadata (removing unreferenced partition specs and schemas)."

What changes are included in this PR?

Adds clean_expired_metadata(bool) to ExpireSnapshotsAction, off by default. When enabled, the action also emits RemoveSchemas / RemovePartitionSpecs for specs and schemas that no surviving snapshot references.

Schemas need no I/O, since each snapshot records its schema_id. Specs require reading each surviving snapshot's manifest list, so those reads are spawned on the table's IO runtime with bounded concurrency, skipped entirely for single-spec tables, and stopped early once every spec has been seen. The current schema and default spec are always seeded as reachable. commit() no longer returns early when nothing expires, since cleanup can still have work to do.

Because the removals are computed against the base metadata, enabling the flag also asserts CurrentSchemaIdMatch, DefaultSpecIdMatch and LastAssignedPartitionIdMatch. Without them a concurrent commit that makes a targeted spec or schema current/default turns the removal into a non-retryable DataInvalid from the metadata builder; asserting them yields a retryable conflict so the action re-plans against the refreshed table. These are not added for plain expiries, which cannot be invalidated that way.

}

// Unlike specs, a snapshot's schema is recorded in metadata, so this needs no I/O. A
// snapshot that predates `schema-id` leaves its schema unknown; treating it as referencing

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

schema-id is an optional field on a snapshot and snapshots written by older writers don't have it

@alessandro-nori
alessandro-nori marked this pull request as ready for review August 25, 2026 09:28
@alessandro-nori
alessandro-nori marked this pull request as draft August 25, 2026 09:31
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.

1 participant