Repository navigation
fix(dags): lake_init held two sessions on one catalog, losing what it wrote (#778) - #785
Merged
Merged
Conversation
… wrote
`lake_init` reported success while the lake it built recorded none of its
relations: a 1.8MB catalog, 22 orphan `schema_migrations` parquets, no live
tables, and a freshly spawned process saw the same — so not a stale attach.
Two sessions were attached to one catalog file inside one process.
`exec_task::run_inner` opens a session for EVERY task, and `LakeInit` opened a
second through `schema::reconcile_lake_env`. The reconciler's session committed
its DDL and was dropped; the pod's ctx session — attached BEFORE the reconcile
and dropped AFTER it, since it lives to the end of `run_inner` — then wrote its
own earlier view back over the committed metadata. What survived was the
reconciler's parquet data with no catalog rows pointing at it.
The task could not notice. Its `catalog_hash` is computed from the compiled
catalog rather than read back, so it reported the hash it intended to write.
So `LakeInit` reconciles through the session it already holds; `reconcile_lake`
takes a plain `&duckdb::Connection`. The comment that justified the second
handle — "the lake this task initialises may not have existed when the pod's
ctx session was opened" — is false in this DAG: `create_catalog` is
`lake_init`'s upstream and creates the catalog, so the file exists before the
pod starts. That premise stopped being true when provisioning became a DAG, and
the second handle outlived it.
`AssemblyError::UnorderedLakeWriters` already names this class — "two
concurrent writers of one tenant lake" — but it guards BETWEEN tasks in a
graph, so it cannot see two writers inside one task.
## Two more provisioning gaps, found by the same port
Both are things the legacy arm did and the task path did not:
- **`activate` never promoted the default dataset.** It is converged at org
creation carrying the org's state of that moment, `provisioning`, and nothing
else ever moves it — the boot sweep is do-nothing on existing rows. So every
tenant provisioned through the executor kept a `default` dataset which, in
the legacy comment's words, "the dataset guard rightly renders as still being
set up".
- **No `tenant_schema_states` row was written for a provisioned tenant.** The
finish handler writes it, but filtered on `plan == "schema_reconciled"` while
`lake_init` emits `lake_initialized`. That table exists so the deploy report
and the drift check never open a lake, and a provisioned tenant was invisible
to both. `LakeInitialized` now carries `status` and `detail` for the same
reason `SchemaReconciled` does, and the handler accepts either receipt.
## The profile seam
`pg_provision.rs` could not run on this path at all: `CreateCatalog` called
`Profile::from_env()` itself, and a Postgres-tier test cannot set an
environment variable — `std::env::set_var` is `unsafe` under edition 2024 and
the workspace denies `unsafe_code`. That is exactly why `dispatch_once_with`
takes a profile argument; the executor path had no equivalent.
`ExecutorConfig` now carries the profile, `run_control_task` takes it, and
`CreateCatalog` holds it as task state. It stays `Default`-constructible for
the DAG builder, and `Default` means "auto-provisioning is not configured" —
the answer an operator with no `ER_PROVISION_MODE` already got.
## Evidence
`pg_provision.rs` ported to the executor, asserting what it already asserted
against the legacy arm. Observed failing with the second session restored, and
the reproduction is the bug itself:
assertion failed: session.lake_table_exists("raw_records").unwrap()
Before this, nothing under `tests/` mentioned `create_catalog` or `lake_init`.
Provisioning had no coverage on the only path that runs it, which is how three
separate gaps accumulated there unnoticed.
`make check` green; the full 104-test er-server tier green against a real
Postgres and DuckLake.
Closes #778
Refs #645
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #778 · unblocks the last of #645's eight test ports
The bug
lake_initreported success while the lake it built recorded none of its relations: a 1.8MB catalog, 22 orphanschema_migrationsparquets, no live tables, and a fresh process saw the same — so not a stale attach.The cause is two sessions on one catalog file inside one process:
exec_task::run_inneropens a session for every task (open_order_session, exec_task.rs:372), which attaches the tenant's DuckLake.LakeInitopened a second one viaschema::reconcile_lake_env→open_lake_env.The reconciler's session committed its DDL and was dropped. The pod's ctx session — attached before the reconcile, and dropped after it, since it lives to the end of
run_inner— then wrote its own earlier view back over the committed metadata. What survived was the reconciler's parquet data with no catalog rows pointing at it.The task could not notice: its
catalog_hashis computed from the compiled catalog, not read back.(The issue description's first guess was
std::process::exitskipping destructors. That was wrong —reconcile_lake_env's session is dropped when the function returns, long before exit. Corrected in the issue.)The fix
LakeInitreconciles through the session it already holds.reconcile_laketakes a plain&duckdb::Connection, soctx.session.connection()works directly.The comment that justified the second handle — "the lake this task initialises may not have existed when the pod's ctx session was opened" — is false in this DAG:
create_catalogislake_init's upstream and creates the catalog, so the file exists before the pod starts. That premise is why the second session was there, and it stopped being true when provisioning became a DAG.Worth noting the framework already names this class —
AssemblyError::UnorderedLakeWriters, "two concurrent writers of one tenant lake" — but it guards between tasks in a graph, so it cannot see two writers inside one task.Two further gaps the same port exposed
Both were things the legacy arm did and the task path did not, so both are needed for provisioning to actually work:
activatenever promoted the default dataset. The dataset is converged at org creation carrying the org's state of that moment —provisioning— and nothing else ever moves it. So every tenant provisioned through the executor kept adefaultdataset that, in the legacy comment's words, "the dataset guard rightly renders as still being set up".tenant_schema_statesrow was written for a provisioned tenant. The finish handler writes that row, but filtered onplan == "schema_reconciled", andlake_initemitslake_initialized. That table exists so the deploy report and the drift check never have to open a lake; a provisioned tenant was invisible to both.LakeInitializednow carriesstatusanddetailfor the same reasonSchemaReconcileddoes, and the handler accepts either receipt.The profile seam
pg_provision.rscould not run on the task path at all, becauseCreateCatalogcalledProfile::from_env()itself and a Postgres-tier test cannot set an environment variable —std::env::set_varisunsafeunder edition 2024 and the workspace deniesunsafe_code. That is precisely whydispatch_once_withtakes a profile argument, and the executor path had no equivalent.So
ExecutorConfigcarries the profile,run_control_tasktakes it, andCreateCatalogholds it as task state. It staysDefault-constructible for the DAG builder, andDefaultmeans "auto-provisioning is not configured" — the answer an operator with noER_PROVISION_MODEalready got.Evidence
pg_provision.rsported to the executor: a realprovisionjob, claimed and planned, run ascreate_catalog→lake_init→activate. It asserts what it already asserted against the legacy arm — the org and dataset reachactive,raw_recordsandschema_migrationsexist, the ledger'scatalog_hashmatcheslake_catalog_hash(), and thetenant_schema_staterow saysmigrated.Observed failing with the second session restored, reproducing the bug exactly:
Before this, nothing under
tests/so much as mentionedcreate_catalogorlake_init— provisioning had no coverage on the only path that runs it, which is how three separate gaps accumulated there unnoticed.make checkgreen; full er-server tier green against a real Postgres and DuckLake.