← LeaderboardThe Skill Leaderboard

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.

Published by sickn33 ↗sickn33/agentic-awesome-skills

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-pipeline and data-engineer cover broad lakehouse/ETL architecture checklists and high-level platform roles without inspecting Iceberg metadata.json snapshot 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 Iceberg refs and 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 and refs (main, feature branches, compliance tags) before scheduling or tuning Iceberg snapshot expiration.
  • Explaining why expire_snapshots preserves older snapshots than max-snapshot-age-ms alone would suggest (e.g., an abandoned branch with default infinite max-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+ (pytest optional 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

  1. Validate every entry in snapshots[] (not only traversed snapshots) and assessment inputs: verify as_of_ms and window_ms are non-negative non-boolean integers (failing closed before timestamp arithmetic), format-version is 1, 2, or 3 (strict integer), each snapshot-id is a non-boolean integer without duplicates, timestamp-ms is a present valid integer <= as_of_ms, and optional parent-snapshot-id is an integer.
  2. Read table-level retention properties from properties, applying specification defaults only when absent:
    • history.expire.max-snapshot-age-ms: default 432000000 ms (5 days).
    • history.expire.min-snapshots-to-keep: default 1.
    • 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 explicit null, 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).
  3. Inspect current-snapshot-id and refs:
    • If refs is completely absent (common in v1 metadata) and current-snapshot-id is set, synthesize an implicit "main" branch and record a metadata notice.
    • If a partial refs map is supplied (e.g., only tags) without "main" while current-snapshot-id is set, or if "main" disagrees with current-snapshot-id, protect current-snapshot-id conservatively, 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 in snapshots[] (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-id ancestors 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.

2. Evaluate per-reference protection vs. contiguous surviving ancestry

Apply the retention rules documented in retention spec semantics:

  1. Reference type & expiry (max-ref-age-ms): Validate type in {"branch", "tag"} (and "main" is always a "branch") before evaluating expiry so malformed refs cannot pass as expired. main never expires regardless of max-ref-age-ms. Non-main refs expire only when snapshot age strictly exceeds max-ref-age-ms (age > max_ref_age_ms).
  2. Per-reference retention reasons:
    • An active tag protects its target snapshot-id directly (tags do not specify min-snapshots-to-keep or branch ancestor histories).
    • An active branch walks parent-snapshot-id from its head, protecting at least min-snapshots-to-keep consecutive reachable ancestors present in snapshots[] plus consecutive ancestors within max-snapshot-age-ms (age <= max_snapshot_age_ms).
  3. Union & contiguous surviving main ancestry: Take the union of snapshots protected by all active branches and tags (retained_snapshots). Compute surviving_main_ancestry by walking main's parent chain from its head and stopping before the first ancestor not in the retained union — so an older main parent kept alive by an active tag or diverging branch remains included. surviving_main_ancestry models contiguous retained lineage in snapshots[] only, not guaranteed timestamp-based time travel (AS OF TIMESTAMP), which also depends on snapshot-log history 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:

  1. Spec-derived retention estimate: Explicit effective_settings origins, active/expired refs, retained_snapshots per-ref reasons, surviving_main_ancestry + rollback floor, and expirable_snapshots (or None when indeterminate).
  2. Incomplete / invalid metadata warnings: Duplicate or malformed IDs, missing/invalid timestamp-ms, malformed retention settings, broken/cyclic parent chains, or partial refs missing main.
  3. Engine-specific caveats (must not be inferred from metadata.json alone): Explicit runtime overrides (older_than, retain_last, Trino retention_threshold), gc.enabled=false (where reference Iceberg implementations reject expire_snapshots altogether 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 stale metadata.json exports require catalog verification before operator action.
  • surviving_main_ancestry reflects contiguous retained lineage in snapshots[] rather than guaranteed SQL AS OF TIMESTAMP / time-travel execution, which also requires matching snapshot-log history 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.

Sources and related skills