Skip to content

DM-56864: Replace Dataflow for staging chunks with BigQuery load jobs (PPDB) - #981

Merged
JeremyMcCormick merged 11 commits into
mainfrom
tickets/DM-56864
Nov 10, 2026
Merged

JeremyMcCormick merged 11 commits into
mainfrom
tickets/DM-56864

Conversation

@JeremyMcCormick

@JeremyMcCormick JeremyMcCormick commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

PPDB infrastructure for staging replica chunks with BigQuery load jobs instead of a Dataflow job. The stage chunk function now loads each chunk into temporary landing tables and copies them into the staging tables itself (lsst/dax_ppdb#69, lsst-dm/ppdb-cloud-functions#38). The Dataflow staging resources and the track chunk function are removed, and the function and the ingest bucket are renamed.

Changes

All changes are in environment/deployments/ppdb/.

  • Landing dataset (services/bigquery.tf)
    • New ppdb_landing dataset for the per-chunk landing tables, in the same location (US) as staging
    • Its tables expire after bigquery_landing_table_expiration_days (default 1)
  • Stage chunk function (services/stage-chunk.tf, renamed from trigger-stage-chunk.tf)
    • Renamed from trigger-stage-chunk to stage-chunk, along with its service account (cloudrun-stage-chunk), Cloud SQL user, push subscription and variables (trigger_stage_chunk_* → stage_chunk_*)
    • The service account gets dataEditor on the landing and staging datasets (staging was dataViewer)
    • Its storage access is limited to storage.objectViewer on the chunk ingest bucket (was project-wide storage.admin), and its unneeded topic subscriber role is removed
    • New environment variables BIGQUERY_CHECK_TIMEOUT_SECONDS, BIGQUERY_JOB_TIMEOUT_SECONDS and BIGQUERY_RETRY_TIMEOUT_SECONDS, from stage_chunk_bigquery_check_timeout_seconds (60), stage_chunk_bigquery_job_timeout_seconds (240) and stage_chunk_bigquery_retry_timeout_seconds (300)
    • Keeps one instance running (min_instance_count = 1) to avoid cold starts
    • Its push subscription allows 100 delivery attempts before dead-lettering (stage_chunk_pubsub_max_delivery_attempts), about 16 hours of retries, so a chunk can wait out a BigQuery quota
    • Removed its Dataflow permissions and Dataflow environment variables
  • Dataflow staging removed (services/dataflow-stage-chunk.tf): the Dataflow service account and its IAM, and the template path and temp location variables. The load_sso Dataflow resources are unchanged.
  • Pub/Sub delivery attempts per subscription: the shared pubsub_max_delivery_attempts is replaced by stage_chunk_pubsub_max_delivery_attempts (100) and load_sso_pubsub_max_delivery_attempts (15, unchanged)
  • Track chunk removed (services/track-chunk.tf): the function, its service account and Cloud SQL user, the track-chunk-topic and track-chunk-dlt topics, its subscriptions and variables
  • Chunk ingest bucket (services/gcs.tf): ppdb-<env>-ingest is replaced by ppdb-<env>-chunk-ingest, with its IAM bindings and variables moved over
  • Other
    • The staging dataset description no longer mentions Dataflow
    • The Sentry DSN secret accessors follow the renamed and removed service accounts
    • SQL/iam-sa-permissions.sql updated for the renamed and removed service accounts

Before applying

  • Pause chunk uploads: pause the USDF ppdb-replication uploads. The apply deploys placeholder code for stage-chunk, which drops messages until the real function is deployed from ppdb-cloud-functions.
  • Empty the old bucket: empty ppdb-<env>-ingest first. GCS can't rename buckets, so the apply deletes it, and it must be empty.
  • Revoke old Postgres grants: revoke the grants of the cloudrun-track-chunks and cloudrun-trigger-stage-chunk Postgres users, so their Cloud SQL users can be dropped.
  • Drain the old subscription: let the trigger-stage-chunk subscription drain. It is replaced, and messages still in it are lost.

After applying

  • Grant the new Postgres user: grant cloudrun-stage-chunk its chunk_tracking permissions (SQL/iam-sa-permissions.sql).
  • Upload the configs: upload the PPDB configs with bucket_name: ppdb-<env>-chunk-ingest to gs://ppdb-<env>-config.
  • Deploy the function: deploy stage-chunk from ppdb-cloud-functions, then resume the uploads.

Related

🤖 Generated with Claude Code

https://claude.ai/code/session_01VJ51nAbGJ4BBgwpjau1VX7

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJ51nAbGJ4BBgwpjau1VX7
JeremyMcCormick and others added 3 commits November 3, 2026 16:35
Each chunk is loaded into its own landing tables before it is copied into
staging. Its tables expire after bigquery_landing_table_expiration_days
(1 by default). The stage chunk function can now write to the landing
and staging datasets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJ51nAbGJ4BBgwpjau1VX7
Removes the function, its service account, IAM and Cloud SQL user, the
track-chunk topic, push and dead-letter subscriptions, and the variables.
Only the Dataflow staging job published to the topic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJ51nAbGJ4BBgwpjau1VX7
The stage chunk function stages chunks with BigQuery load jobs. Removes
the Dataflow service account and its IAM, the function's Dataflow
permissions and environment variables, and their variables. The load_sso
Dataflow resources are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJ51nAbGJ4BBgwpjau1VX7
JeremyMcCormick and others added 4 commits November 3, 2026 21:13
New variables trigger_stage_chunk_bigquery_job_timeout_seconds (240 by
default) and trigger_stage_chunk_bigquery_check_timeout_seconds (60 by
default), passed to the function as BIGQUERY_JOB_TIMEOUT_SECONDS and
BIGQUERY_CHECK_TIMEOUT_SECONDS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJ51nAbGJ4BBgwpjau1VX7
Renames the bucket that replica chunks are uploaded to, matching
ppdb-<env>-sso-ingest. GCS buckets can't be renamed, so Terraform
creates the new bucket and deletes ppdb-<env>-ingest, which must be
empty first. The bucket's IAM bindings and variables move with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJ51nAbGJ4BBgwpjau1VX7
Renames the file, resources and variables, the function, its service
account cloudrun-stage-chunk and its Pub/Sub subscription stage-chunk.
GCP can't rename these, so the apply replaces them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJ51nAbGJ4BBgwpjau1VX7
…ngest bucket

Replace project-wide storage.admin with storage.objectViewer on the chunk
ingest bucket, and drop the unneeded topic subscriber role (the function
is invoked by a push subscription).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJ51nAbGJ4BBgwpjau1VX7
JeremyMcCormick and others added 3 commits November 3, 2026 23:28
New variable stage_chunk_bigquery_retry_timeout_seconds (300 by
default), passed to the function as BIGQUERY_RETRY_TIMEOUT_SECONDS. The
job timeout's description no longer mentions the Pub/Sub deadline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJ51nAbGJ4BBgwpjau1VX7
Replace the shared pubsub_max_delivery_attempts with
stage_chunk_pubsub_max_delivery_attempts (100, so a chunk can wait out a
BigQuery quota for about 16 hours before dead-lettering) and
load_sso_pubsub_max_delivery_attempts (15, unchanged).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJ51nAbGJ4BBgwpjau1VX7
The Cloud Run service and scheduler retry settings for promote chunks
are no longer used by any resource since it became a Cloud Run job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJ51nAbGJ4BBgwpjau1VX7
@JeremyMcCormick

Copy link
Copy Markdown
Contributor Author

@fajpunk This is tested and working in dev now (staging and promotion).

Some resources like deprecated storage buckets may need to be cleaned-up/deleted manually.

@JeremyMcCormick JeremyMcCormick changed the title DM-56864: Replace Dataflow for staging chunks with BigQuery load jobs (PPDB) DM-56864: Replace Dataflow for staging chunks with BigQuery load jobs (PPDB) Nov 5, 2026

@fajpunk fajpunk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied this manually. As you said, I had to destroy a vestigial bucket manually, and we had to do some manual stuff in the database to dissociate database objects from service accounts we are getting rid of.

@JeremyMcCormick

JeremyMcCormick commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

@fajpunk I am going to merge this as I need to work on getting the changes deployed to int and prod. The other two PRs are not approved and merged yet but I'm anticipating that they will be shortly. I will deploy them from their branches to update int. (dev is already updated).

@JeremyMcCormick
JeremyMcCormick merged commit 4bec851 into main Nov 10, 2026
4 checks passed
@JeremyMcCormick
JeremyMcCormick deleted the tickets/DM-56864 branch November 10, 2026 22:35
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