Skip to content

feat(datasets): the queue, the dispatcher and provisioning go per-dataset (PR5) - #396

Merged
athvin merged 2 commits into
mainfrom
bm/datasets-p5-queue
Nov 2, 2026
Merged

athvin merged 2 commits into
mainfrom
bm/datasets-p5-queue

Conversation

@athvin

@athvin athvin commented Nov 2, 2026

Copy link
Copy Markdown
Owner

PR 5 of the datasets program (after #380/#381/#383/#392). This is the rung that actually unlocks concurrent datasets — and ships with the cap at 1, so nothing changes until an operator raises it.

What

  • The writer lock moves to where the writing is: one active job (and one live pod) per DATASET; org-level jobs (dataset_id IS NULL: provision) conflict with everything of their org, in both directions. Fixup 0003 retires the superseded per-org indexes and the tenant_schema_states UNIQUE(org_id) in-table constraint (looked up in pg_constraint — Postgres named it, and names are the fragile part). tenant_schema_states becomes one row per dataset via two partial uniques (a plain UNIQUE(dataset_id) would let NULL org-level rows accumulate), with split upsert statements.
  • The org concurrency cap: orgs.max_concurrent_jobs, defaulting to ER_ORG_JOB_CAP (ships as 1 — the exact pre-dataset profile). A COUNT can't be index-enforced, so pg::claim serializes claims under an advisory lock; the per-dataset partial unique stays the database-level backstop.
  • The dispatcher resolves the DATASET env for every dataset job (config, lake, models, deliveries come from the dataset row), falling back to the org env for org-level kinds. The two org-env mutation paths (PATCH /resources, the lexicon path) fan their patch out to every dataset env — the convergence sweep deliberately never rewrites an existing dataset, so explicit mutations must.
  • Dataset provisioning end to end: Profile::plan_dataset (local: nested dirs; postgres: ER_LAKE_CATALOG_SCHEMA=ds_<name> in the org's shared metadata DB, {dataset} substitution in the data template and env_extra); POST /datasets without a config_path becomes the tenant-admin auto path (workspace + starter config v1 + a provisioning row + the dataset_provision job — BYO stays operator-only); the new dispatcher arm reconciles the lake into existence and flips provisioning→active.
  • The deploy sweep fans out one lake_migrate per ACTIVE DATASET, reported as org/dataset.

Proof

pg_dataset_concurrency (new): cap 1 behaves exactly as before datasets; cap 2 runs two datasets at once while each stays strictly single-writer; an org-level job waits for everything and blocks everything, through the full claim/mark sequence. pg_approval mirrors its raw env swap onto the dataset rows — the job it enqueues carries the default dataset now, which is the point. Full pg suite green locally (49/49); make check green.

🤖 Generated with Claude Code

bmoore813 and others added 2 commits November 2, 2026 12:21
…aset (PR5)

The writer lock moves to where the writing is: one active job (and one live
pod) per DATASET, each dataset being its own lake, with org-level jobs
(dataset_id IS NULL: provision) still conflicting with everything of their
org in both directions. A per-org concurrency cap rides on top —
orgs.max_concurrent_jobs, defaulting to ER_ORG_JOB_CAP (shipped as 1, the
exact pre-dataset profile) — and because a COUNT cannot be index-enforced,
pg::claim serializes claims under an advisory lock while the per-dataset
partial unique stays the database-level backstop. Fixup 0003 retires the
superseded per-org indexes and the tenant_schema_states UNIQUE(org_id)
in-table constraint (looked up in pg_constraint — Postgres named it, and
names are the fragile part); tenant_schema_states becomes one row per
dataset via two partial uniques, because a plain UNIQUE(dataset_id) would
let NULL org-level rows accumulate.

The dispatcher resolves the DATASET env for every dataset job — config,
lake, models, deliveries all come from the dataset row — falling back to the
org env only for org-level kinds. The two org-env mutation paths (resources,
the lexicon path) now fan their patch out to every dataset env, because the
convergence sweep deliberately never rewrites an existing dataset.

Dataset provisioning exists end to end: Profile::plan_dataset derives the
lake (ER_LAKE_CATALOG_SCHEMA=ds_<name> inside the org's shared metadata
database; a nested directory locally; {dataset} substitution in the data
template and env_extra), POST /datasets without a config_path becomes the
tenant-admin auto path (workspace + starter config v1 + a provisioning row +
the dataset_provision job), and the new dispatcher arm reconciles the lake
into existence and flips provisioning→active. The deploy sweep fans out one
lake_migrate per ACTIVE DATASET, reported as org/dataset.

pg_dataset_concurrency proves the lot: cap 1 behaves exactly as before
datasets; cap 2 runs two datasets at once while each stays single-writer;
an org-level job waits for everything and blocks everything. pg_approval
now mirrors its raw env swap onto the dataset rows — the job it enqueues
carries the default dataset, which is the point of the whole change.

Co-Authored-By: Claude Fable 5 <[email protected]>
…as not met — one org-level lake_migrate when no dataset rows exist yet

Co-Authored-By: Claude Fable 5 <[email protected]>
@athvin
athvin merged commit 56f2469 into main Nov 2, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants