Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), version

## [Unreleased]

## [0.1.2] - 2026-06-08

### Fixed

- **`add_tiered_retention_policy` now actually tiers.** The flag/tier phase only recognized `tiering` policies, so a combined `tiered_retention` policy was never flagged (`Found 0 table(s) with tiering policies`) — only its drop horizon worked. Fixed across the flag path: the tiering job and `_get_chunks_to_tier` now match `policy_type IN ('tiering', 'tiered_retention')` and read the horizon from `after` or `tier_after`. `add_tiered_retention_policy` also installs the write-tracking trigger, backfills `last_write_lsn` on existing chunks, and sets `tiering_enabled = TRUE` — without these, `tier_chunk` deferred every chunk.

Upgrade by reinstalling `dist/lakets.sql` and redeploying the maintenance jobs (the fix spans both SQL and `tiering_job.py`).

## [0.1.1] - 2026-06-08

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.1
0.1.2
4 changes: 2 additions & 2 deletions databricks/workflows/tiering_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def run(project_name: str) -> int:
deferred = 0
with lakebase_cursor(project_name) as cur:
tables = fetch_all(cur, """
SELECT hr.id, hr.schema_name, hr.table_name
SELECT DISTINCT hr.id, hr.schema_name, hr.table_name
FROM lakets._chronotable_registry hr
JOIN lakets._policy_registry pr ON hr.id = pr.chronotable_id
WHERE pr.policy_type = 'tiering' AND pr.enabled = TRUE
WHERE pr.policy_type IN ('tiering', 'tiered_retention') AND pr.enabled = TRUE
""")
logger.info("Found %d table(s) with tiering policies", len(tables))

Expand Down
2 changes: 1 addition & 1 deletion sql/00_version.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SET client_min_messages TO NOTICE;
DO $$
DECLARE
v_installed TEXT;
v_incoming TEXT := coalesce(nullif('__LAKETS_VERSION__', '__LAKE' || 'TS_VERSION__'), '0.1.1');
v_incoming TEXT := coalesce(nullif('__LAKETS_VERSION__', '__LAKE' || 'TS_VERSION__'), '0.1.2');
v_installed_parts INT[];
v_incoming_parts INT[];
BEGIN
Expand Down
9 changes: 7 additions & 2 deletions sql/05_tiering.sql
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,18 @@ DECLARE
v_after INTERVAL;
v_shadow TEXT;
BEGIN
SELECT hr.id, (pr.config->>'after')::INTERVAL, hr.shadow_table_name
-- The flag/tier horizon comes from a 'tiering' policy ('after') or the
-- tier_after leg of a combined 'tiered_retention' policy. Both are validated
-- and flagged here; 'tiered_retention' also owns the later drop at drop_after.
SELECT hr.id,
COALESCE(pr.config->>'after', pr.config->>'tier_after')::INTERVAL,
hr.shadow_table_name
INTO v_chronotable_id, v_after, v_shadow
FROM lakets._chronotable_registry hr
JOIN lakets._policy_registry pr ON hr.id = pr.chronotable_id
WHERE hr.schema_name = p_schema_name
AND hr.table_name = p_table_name
AND pr.policy_type = 'tiering'
AND pr.policy_type IN ('tiering', 'tiered_retention')
AND pr.enabled = TRUE;

IF NOT FOUND THEN
Expand Down
17 changes: 17 additions & 0 deletions sql/06_retention.sql
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ BEGIN
), TRUE)
RETURNING id INTO v_policy_id;

UPDATE lakets._chronotable_registry
SET tiering_enabled = TRUE
WHERE id = v_chronotable_id;

-- The tiering job flags chunks 'tiered' at tier_after, gated on each chunk's
-- last_write_lsn being durable in UC. Install write-tracking and backfill the
-- current WAL head onto existing active chunks (same as add_tiering_policy),
-- or tier_chunk treats a NULL last_write_lsn as "cannot prove durable" and
-- defers every chunk forever.
PERFORM lakets._install_tiering_write_tracking(p_schema_name, p_table_name);

UPDATE lakets._chunk_metadata
SET last_write_lsn = pg_current_wal_lsn()
WHERE chronotable_id = v_chronotable_id
AND status = 'active'
AND last_write_lsn IS NULL;

RETURN v_policy_id;
END;
$$;
Expand Down