Skip to content

Project Structure

Icepack is organized as a layered Python application. This page maps every top-level module in the icepack/ package and explains how the layers fit together.

Module map

ModuleResponsibility
api.pyFastAPI app — all HTTP endpoints + lifespan.
cli.pyStandalone icepack CLI commands; bypasses the API queue.
worker.pyKEDA-invoked maintenance worker (one job per pod).
jobs.pyJobStore — Postgres-backed queue + state (DL-197 fence).
locks.pyTableLock — per-table ownership-checked lock.
table_cache.pyTableCache + TableCacheSyncWorker (atomic-swap refresh).
history.pyHistoryStore — schema management + persistent reads.
backend.pyselect_job_store / select_table_cache factory.
metrics.pyOTel/Prometheus gauges (queue depth, workers, etc.).
config.pyPydantic CompactionConfig — env-driven configuration.
discovery.pyPolarisDiscovery — PyIceberg catalog table listing (Polaris REST or Glue fallback).
catalog.pyPyIceberg catalog factories (Polaris + Glue).
status.pyMaps collected metadata metrics into the raw table status contract.
health.pyDerives policy-independent health status and issues from table status.
recommendation.pyDerives policy-aware maintenance recommendations from status, table metadata, and history.
inspector.pyMetadata inspector abstraction — PyIceberg chart/config default or configured iceberg-go helper.
maintenance.pyMaintenanceRunner — executes one action via Spark.
spark.pySparkQueryEngine — Thrift/Kyuubi wrapper.
service.pyCompactionService — request-scoped service composition.
orchestrator.pyAuto-submit maintenance based on API recommendations.
health_sync.pyShared health precomputation worker using the configured metadata inspector.
health_sync_job.pyCronJob entrypoint for one health-sync cycle.

Layered architecture

Icepack follows a strict layered architecture. Each layer only calls into the layer directly below it, keeping concerns separated and individual components testable in isolation.

Entry points

There are three ways to interact with Icepack:

  • CLI (cli.py) — Click commands for ad-hoc operations. The CLI talks directly to the service layer; it does not go through the API.
  • REST API (api.py) — FastAPI endpoints for programmatic access and the orchestrator. All job submission and health queries flow through here.
  • Web UI — An Alpine.js single-page application served by the API. The UI is a pure API consumer and introduces no additional backend logic.

Service layer

The CLI uses CompactionService (service.py) directly. The API uses the same lower-level discovery/inspector/runner components where needed, but job submission itself is a Postgres queue operation. CompactionService composes:

  • Discovery (discovery.py) — lists tables from the configured PyIceberg catalog (Polaris REST when configured, Glue fallback otherwise).
  • Metadata inspector (inspector.py) — loads Iceberg table metadata through the configured backend: PyIceberg by chart/config default, or the bundled iceberg-go helper in named deployed environment values.
  • MaintenanceRunner (maintenance.py) — executes a single maintenance action (compaction, snapshot expiry, etc.) by issuing Spark SQL.

Status, health, and recommendation are now separate contracts. status.py builds raw observed state, health.py derives issues from that state, and recommendation.py combines status with policy/history to produce action intent.

Query engine

At the bottom of the stack sits the QueryEngine protocol (spark.py). This is a minimal, backend-agnostic interface that the service layer uses to run SQL. The concrete implementation, SparkQueryEngine, wraps a PyHive/Thrift connection to Spark Thrift Server (or Kyuubi).

Data flow summary

CLI (Click) REST API / Web UI
| |
CompactionService Postgres queue/cache + service components
| |
Discovery / Inspector / Status / Health / Recommendation / MaintenanceRunner
(PyIceberg catalog) (metadata inspector + Spark SQL)
| |
QueryEngine Protocol -> SparkQueryEngine (PyHive / Thrift)

State management — job queue, table locks, table inventory cache, cached status snapshots, cached health assessments, and run history — is handled entirely through Postgres via the jobs.py, locks.py, table_cache.py, and history.py modules.