Skip to content

fix(partitioning): render chunk names from the UTC instant#49

Merged
taran-dbx merged 1 commit into
mainfrom
fix/utc-chunk-names
Jun 9, 2026
Merged

fix(partitioning): render chunk names from the UTC instant#49
taran-dbx merged 1 commit into
mainfrom
fix/utc-chunk-names

Conversation

@taran-dbx

Copy link
Copy Markdown
Collaborator

Problem

The partition-manager job failed:

duplicate key value violates unique constraint "idx_chunk_metadata_chunk_name"
DETAIL: Key (chunk_name)=(public.stock_ticks_20260609_040000) already exists.
... ON CONFLICT (chronotable_id, range_start) DO NOTHING

_ensure_partitions builds chunk_name with to_char(range_start, 'YYYYMMDD_HH24MISS') in the session timezone, but range_start is an absolute timestamptz. When the function runs under different session timezones — the scheduled job in UTC vs a client in UTC+2 — the same chunk gets named differently, so chunk_name stops being 1:1 with range_start. A later run then computes a name that collides with a stale row whose range_start differs, and ON CONFLICT (chronotable_id, range_start) can't absorb a chunk_name collision → the insert throws.

Observed on lakets-demo: a row created under UTC+2 stored …_040000 for range_start = 02:00 UTC; the UTC job computing …_040000 for the real 04:00 UTC chunk collided.

Fix

Render the name from the instant in UTC: to_char(v_start AT TIME ZONE 'UTC', 'YYYYMMDD_HH24MISS') (both the CREATE TABLE partition name and the _chunk_metadata.chunk_name). chunk_name is now 1:1 with range_start regardless of session timezone.

Test plan

  • make build clean (14 modules, version 0.1.3)
  • Reinstall, run partition manager under UTC and a non-UTC session → no chunk_name collision; names match range_start in UTC
  • Note: rows created before this fix under a non-UTC session keep their old names; drop stale rows for already-dropped chunks and let the manager recreate them.

Ships as v0.1.3. Reinstall dist/lakets.sql.

_ensure_partitions built chunk_name via to_char(range_start, 'YYYYMMDD_HH24MISS')
in the session timezone, but range_start is an absolute timestamptz. Running
under different session timezones (job in UTC vs client in UTC+2) named the same
chunk differently, desyncing chunk_name from range_start and tripping the
chunk_name unique index ('duplicate key ... idx_chunk_metadata_chunk_name')
that ON CONFLICT (chronotable_id, range_start) cannot absorb.

Render the name from v_start AT TIME ZONE 'UTC' so chunk_name is 1:1 with
range_start regardless of session timezone.

Release 0.1.3.
@taran-dbx taran-dbx merged commit 01fc163 into main Jun 9, 2026
9 checks passed
@taran-dbx taran-dbx deleted the fix/utc-chunk-names branch June 9, 2026 05:55
@github-actions github-actions Bot added documentation Improvements or additions to documentation sql labels Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation sql

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant