feat(table): expire snapshots and add sys.expire_snapshots - #965
Open
zhuxiangyi wants to merge 2 commits into
Open
zhuxiangyi wants to merge 2 commits into
zhuxiangyi wants to merge 2 commits into
Conversation
Port Java's ExpireSnapshotsImpl and SnapshotDeletion. Snapshots are chosen with snapshot.num-retained.min/max, snapshot.time-retained (a snapshot expires once its successor is older than the cut-off), consumer protection, and snapshot.expire.limit. Expiring [earliest, end) deletes data files removed by the deltas of (earliest, end] that the closest earlier tag does not read, changelog files, and manifest lists, manifests, index files, statistics and reassign plans that neither end nor a tag in the range references, then the snapshot files and finally moves the EARLIEST hint. Read failures only ever make a run delete less. Expose it as Table::new_expire_snapshots() and the DataFusion procedure sys.expire_snapshots with Java's arguments.
…ation Extend the file-set invariant to changelog files and index files kept in bucket directories, and add cases for deletion-vector files in both index layouts, changelog and hash index files of a primary-key table, external data files, unreadable deltas, tags and skipping sets (each must delete less, never more), the closest earlier tag among several, a snapshot missing from the range, the slowest of several consumers, and older_than given as a timestamp string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose
Linked issue: #964 (part 1 of 4)
Tables written through paimon-rust (Rust API, pypaimon native, C FFI) never expire snapshots, so
their snapshot, manifest, and data files only ever grow. This PR adds snapshot expiration to the
core crate and exposes it as
CALL sys.expire_snapshots, following Java'sExpireSnapshotsImpland the Flink/Spark
expire_snapshotsprocedure.Brief change log
Table::new_expire_snapshots()/ExpireSnapshots(table/expire_snapshots.rs):Chooses snapshots to expire with Java's rules:
snapshot.num-retained.maxsnapshots are kept, and never fewer thansnapshot.num-retained.min;(
snapshot.time-retained, or an explicitolder_than);consumer/consumer-*) still reads from are kept;snapshot.expire.limitsnapshots.Each rule can be overridden per call.
Expiring
[earliest, end)deletes, in Java's order:(earliest, end]that the closest earliertag does not still read;
[earliest, end);files, and row-id reassign plans that neither
endnor a tag in the range references;table/snapshot_deletion.rs(JavaFileDeletionBase/SnapshotDeletion) holds the planningand deletion. Every read failure makes the plan delete less, never more:
depend on the DELETE entry coming before the ADD entry.
CoreOptions:snapshot.num-retained.min/.max,snapshot.time-retained,snapshot.expire.limit, with Java's defaults. Invalid values fail instead of silently fallingback, since this path deletes files.
SnapshotManager::try_get_snapshotandearliest_hint_exists.CALL sys.expire_snapshots(table, retain_max, retain_min, older_than, max_deletes, options)returnsdeleted_snapshots_count, like Java.older_thanaccepts epoch millisecondsor a
yyyy-MM-dd HH:mm:ss[.SSS]timestamp in the local time zone (Java's format).optionsare dynamic table options for the call.
table.snapshot_manager(), so REST-catalog tables resolve their latest snapshot through thecatalog, as in Java.
Scope notes:
ExpireConfigwithout changelog options, changelogfiles expire with their snapshots.
changelog.num-retained.*/changelog.time-retained(changelog decoupling) need a changelog manager and are left for later.
snapshot.clean-empty-directoriesis not implemented yet.Tests
table::expire_snapshots::tests(23 tests). The central check isassert_files_match_references: after a run, the data, manifest, and index files on disk mustbe exactly the files some remaining snapshot or tag references. That includes changelog files
and index files kept in bucket directories. Live data files come from the scan planner, not
from the deletion code. The scenarios:
scan.tag-name;scan.snapshot-id;num-retained.max,older_than(successor rule),max_deletes,retain_min;previous_tagandfind_skipping_tags;index-file-in-data-file-dirboth offand on;
(
changelog-producer = input);external_path) are deleted at their own path;protection or upgrade protection, skipping index or changelog deletion, ignoring
external_path, and treating an unreadable tag as "no tag".CoreOptionsdefaults, overrides, and invalid values.tests/procedures.rs:CALL sys.expire_snapshotstest coveringretain_max,older_than,max_deletes, andoptions, checked against$snapshotsand the table data;retain_maxbelowretain_min, anda bad timestamp;
older_thanas a local timestamp string.older_thanparsing.cargo test -p paimon --all-targets --features fulltext,vortexandcargo clippy --all-targets --workspace --features fulltext,vortex -- -D warningspass.API and Format
Table::new_expire_snapshots()/ExpireSnapshots; newCoreOptionsaccessors; new
sys.expire_snapshotsprocedure.Documentation
docs/src/sql.mddocumentsexpire_snapshots: its arguments, the table options behind them, andwhat the procedure keeps.