iceberg-snapshot-maintenance-review
Run read-only Apache Iceberg snapshot-retention and rollback-window reviews from table metadata across branches, tags, parent lineage, and ref expiry rules.
Try your first task
A source-grounded starter task has not been verified for this skill yet.
SKILL.md
name: iceberg-snapshot-maintenance-reviewdescription: "Run read-only Apache Iceberg snapshot-retention and rollback-window reviews from table metadata across branches, tags, parent lineage, and ref expiry rules."category: datarisk: safesource: selfsource_type: selfdate_added: "2026-12-01"author: Koushik-Katkamtags: [apache-iceberg, snapshot-retention, lakehouse, metadata-audit, governance]Iceberg Snapshot Maintenance Review
Overview
Perform a strictly read-only assessment of Apache Iceberg snapshot retention, reference expiry (branches and tags), parent snapshot ancestry, and rollback windows from supplied Iceberg table metadata (metadata.json). Helps data engineers explain why snapshots remain retained (abandoned branches or infinite tags) or detect when aggressive expiration narrows rollback/time-travel windows before running engine maintenance.
Distinction from existing skills:
data-engineering-data-pipelineanddata-engineercover broad lakehouse/ETL architecture checklists and high-level platform roles without inspecting Icebergmetadata.jsonsnapshot graphs or specification retention semantics.duckdb-analytics(merged via PR #2652) queries Parquet, Arrow, and Polars datasets with DuckDB (EXPLAIN (FORMAT JSON)partition pruning and Relation APIs) rather than auditing Icebergrefsand snapshot retention trees.
This skill evaluates supplied metadata only and never executes snapshot expiration, orphan-file deletion, or catalog writes.
When to Use
- Reviewing a table's
history.expire.*properties andrefs(main, feature branches, compliance tags) before scheduling or tuning Iceberg snapshot expiration. - Explaining why
expire_snapshotspreserves older snapshots thanmax-snapshot-age-msalone would suggest (e.g., an abandoned branch with default infinitemax-ref-age-ms). - Auditing rollback windows and contiguous surviving ancestry along
main(including parents kept alive by other tags or diverging branches). - Do not use this skill for running Spark/Trino/PyIceberg write jobs (
expire_snapshots,remove_orphan_files), querying Parquet files directly (duckdb-analytics), or designing general ETL pipelines (data-engineering-data-pipeline).
Prerequisites
- Supplied Apache Iceberg table
metadata.json(format v1/v2/v3 export or metadata snapshot) and an explicit assessment reference timestamp (as_of_ms). - Python 3.10+ (
pytestoptional to run the bundled fixture verification suite). - No catalog access or write credentials required when analyzing exported
metadata.json. Never execute maintenance mutations during review.
How It Works
1. Validate every snapshot entry, ref, and retention property strictly
- Validate every entry in
snapshots[](not only traversed snapshots) and assessment inputs: verifyas_of_msandwindow_msare non-negative non-boolean integers (failing closed before timestamp arithmetic),format-versionis1,2, or3(strict integer), eachsnapshot-idis a non-boolean integer without duplicates,timestamp-msis a present valid integer<= as_of_ms, and optionalparent-snapshot-idis an integer. - Read table-level retention properties from
properties, applying specification defaults only when absent:history.expire.max-snapshot-age-ms: default432000000ms (5 days).history.expire.min-snapshots-to-keep: default1.history.expire.max-ref-age-ms: default infinite (Long.MAX_VALUE/ unset).- If a supplied property or per-ref override (
max-snapshot-age-ms,min-snapshots-to-keep,max-ref-age-ms) is explicitnull, malformed, non-integer, negative, zero, or out of Iceberg integer bounds, do not silently replace it with a default and treat the result as authoritative — flag the metadata error and mark the assessment indeterminate (expirable_snapshots = None).
- Inspect
current-snapshot-idandrefs:- If
refsis completely absent (common in v1 metadata) andcurrent-snapshot-idis set, synthesize an implicit"main"branch and record a metadata notice. - If a partial
refsmap is supplied (e.g., only tags) without"main"whilecurrent-snapshot-idis set, or if"main"disagrees withcurrent-snapshot-id, protectcurrent-snapshot-idconservatively, log an incomplete-metadata warning, and mark the assessment indeterminate (expirable_snapshots = None). - Whenever duplicate IDs, invalid
ref.type(even on expired references), missing timestamps, missing active ref/current heads, invalid retention properties, or parent cycles anywhere insnapshots[](including unreferenced snapshots) exist, withhold expiration candidate lists (None) and mark the assessment indeterminate. - Distinguish missing active heads or invalid fields/cycles (metadata corruption / indeterminate) from missing historical
parent-snapshot-idancestors that can legitimately remain after prior snapshot expiration: surface missing historical parents explicitly as ancestry-gap warnings (never silently ignore unreferenced gaps) without falsely classifying expired ancestry gaps as corruption.
- If
2. Evaluate per-reference protection vs. contiguous surviving ancestry
Apply the retention rules documented in retention spec semantics:
- Reference type & expiry (
max-ref-age-ms): Validatetype in {"branch", "tag"}(and"main"is always a"branch") before evaluating expiry so malformed refs cannot pass as expired.mainnever expires regardless ofmax-ref-age-ms. Non-mainrefs expire only when snapshot age strictly exceedsmax-ref-age-ms(age > max_ref_age_ms). - Per-reference retention reasons:
- An active tag protects its target
snapshot-iddirectly (tags do not specifymin-snapshots-to-keepor branch ancestor histories). - An active branch walks
parent-snapshot-idfrom its head, protecting at leastmin-snapshots-to-keepconsecutive reachable ancestors present insnapshots[]plus consecutive ancestors withinmax-snapshot-age-ms(age <= max_snapshot_age_ms).
- An active tag protects its target
- Union & contiguous surviving
mainancestry: Take the union of snapshots protected by all active branches and tags (retained_snapshots). Computesurviving_main_ancestryby walkingmain's parent chain from its head and stopping before the first ancestor not in the retained union — so an oldermainparent kept alive by an active tag or diverging branch remains included.surviving_main_ancestrymodels contiguous retained lineage insnapshots[]only, not guaranteed timestamp-based time travel (AS OF TIMESTAMP), which also depends onsnapshot-loghistory and physical data/manifest file availability.
See snapshot retention harness for the runnable pytest / CLI reference analyzer and synthetic fixtures.
3. Separate spec estimates from engine behavior
Report results in three distinct sections:
- Spec-derived retention estimate: Explicit
effective_settingsorigins, active/expired refs,retained_snapshotsper-ref reasons,surviving_main_ancestry+ rollback floor, andexpirable_snapshots(orNonewhen indeterminate). - Incomplete / invalid metadata warnings: Duplicate or malformed IDs, missing/invalid
timestamp-ms, malformed retention settings, broken/cyclic parent chains, or partialrefsmissingmain. - Engine-specific caveats (must not be inferred from
metadata.jsonalone): Explicit runtime overrides (older_than,retain_last, Trinoretention_threshold),gc.enabled=false(where reference Iceberg implementations rejectexpire_snapshotsaltogether rather than deleting metadata safely), manifest/data-file overlap across snapshots, and catalog commit locks. Retention metadata alone does not establish exact byte savings or safe file deletion.
Examples
Run the read-only retention analyzer in snapshot retention harness:
User request: "Why does main snapshot 1 still survive with our tag, and is our 7-day rollback window intact?"
Inputs: Exported Iceberg metadata.json + target assessment timestamp (read-only).
Expected result: Analyzer tracks per-reference protection separately from the retained union, reports
surviving_main_ancestry as [2, 1] when active tag 'audit-q1' protects parent 1 past main's max age,
withholds expirable_snapshots (None) when any snapshot entry lacks timestamp-ms or parent ancestry is
broken/cyclic, and notes that gc.enabled=false blocks snapshot expiration in reference engines.
Limitations
- Spec-derived JSON analysis cannot observe explicit procedure overrides passed at runtime (e.g., Spark
expire_snapshots(older_than => ..., retain_last => ...)), catalog-level locks, or physical Parquet/manifest overlap across snapshots. - Retention metadata alone cannot prove physical data-file readability, safe deletion, or exact storage reclamation bytes.
- Metadata timestamps rely on producer clocks (
timestamp-ms); clock skew or stalemetadata.jsonexports require catalog verification before operator action. surviving_main_ancestryreflects contiguous retained lineage insnapshots[]rather than guaranteed SQLAS OF TIMESTAMP/ time-travel execution, which also requires matchingsnapshot-loghistory and readable physical manifest/data files.
Safety and Side Effects
- Strictly read-only: inspects supplied Iceberg JSON metadata in memory or from local files.
- Never executes
expire_snapshots,remove_orphan_files,rewrite_data_files,DROP BRANCH,DROP TAG, or any catalog commit. - Treat supplied metadata paths, snapshot summaries, and branch/tag names as untrusted data; redact storage bucket URIs or sensitive partition summary values before sharing reports externally.