Expand description
Deployment tracking operations.
This module contains methods for managing deployment records in the database, including creating tracking tables, inserting/querying deployment records, and managing deployment lifecycle (staging, promotion, abort).
§Hydration State Machine
During staging, clusters transition through the following states:
┌──────────┐ all objects hydrated ┌───────┐
│ Hydrating │ ────────────────────────▶ │ Ready │
└──────────┘ & lag ≤ threshold └───────┘
│ ▲
│ lag > threshold ┌─────────┐
└────────────────────────────────▶ │ Lagging │
└─────────┘
│
▼ (no replicas OR all replicas OOM-looping)
┌─────────┐
│ Failing │
└─────────┘- Hydrating → objects are being backfilled; progress tracked as
hydrated / totalviamz_internal.mz_hydration_statuses. - Ready → all objects hydrated and max wallclock lag ≤ threshold (default 300s / 5 minutes).
- Lagging → all objects hydrated but wallclock lag exceeds threshold.
- Failing → no replicas configured, or all replicas are problematic
(3+ OOM kills within 24 hours per
mz_cluster_replica_status_history).
§Apply State Tracking
The apply (cutover) process uses a pair of schemas in _mz_deploy as a
state marker: apply_<id>_pre and apply_<id>_post. During the atomic
swap transaction these schemas exchange names, moving the swapped=true
comment to the _pre schema. This enables crash recovery:
- Schema absent →
NotStarted _precomment =swapped=false→PreSwap(resume pre-swap work)_precomment =swapped=true→PostSwap(resume post-swap work)
§SUBSCRIBE Streaming
subscribe_deployment_hydration opens a SUBSCRIBE cursor over the
hydration status query. Retractions (mz_diff == -1) are filtered out
before yielding updates — only insertions are surfaced to the caller.
Structs§
- Cluster
Status Context - Full status context for a cluster in a staging deployment.
- Hydration
Status Update - A hydration status update from the SUBSCRIBE stream.
Enums§
- Cluster
Deployment Status - Status of a cluster in a staging deployment.
- Failure
Reason - Reason why a cluster deployment is failing.
Constants§
- DEFAULT_
ALLOWED_ LAG_ SECS - Default allowed lag threshold in seconds (5 minutes).
Functions§
- append_
deployment_ 🔒objects - Append deployment object records (insert-only, never update or delete).
- check_
deployment_ 🔒conflicts - Check for deployment conflicts (schemas updated after deployment started).
- create_
apply_ 🔒state_ schemas - Create apply state schemas with comments for tracking apply progress.
- delete_
apply_ 🔒state_ schemas - Delete apply state schemas after successful completion.
- delete_
deployment 🔒 - Delete all deployment records for a specific deployment.
- delete_
deployment_ 🔒clusters - Delete cluster records for a staging deployment.
- delete_
pending_ 🔒statements - Delete all pending statements for a deployment.
- delete_
replacement_ 🔒mvs - Delete all replacement MV records for a deployment.
- deployment_
table_ 🔒exists - Check if the deployment tracking table exists.
- get_
apply_ 🔒state - Get the current apply state for a deployment.
- get_
deployment_ 🔒clusters - Get cluster names for a staging deployment.
- get_
deployment_ 🔒details - Get detailed information about a specific deployment.
- get_
deployment_ 🔒hydration_ status - Get detailed hydration and health status for clusters in a staging deployment.
- get_
deployment_ 🔒metadata - Get metadata about a deployment for validation.
- get_
deployment_ 🔒objects - Get deployment object records from the database for a specific deployment.
- get_
pending_ 🔒statements - Get pending statements for a deployment that haven’t been executed yet.
- get_
replacement_ 🔒mvs - Get replacement MV records for a deployment.
- get_
schema_ 🔒deployments - Get schema deployment records from the database for a specific deployment.
- hydration_
status_ 🔒query - Build the shared hydration-status SQL query.
- insert_
deployment_ 🔒clusters - Insert cluster records for a staging deployment.
- insert_
pending_ 🔒statements - Insert pending statements for deferred execution (e.g., sinks).
- insert_
replacement_ 🔒mvs - Insert replacement MV records for a deployment.
- insert_
schema_ 🔒deployments - Insert schema deployment records (insert-only, no DELETE).
- list_
deployment_ 🔒history - List deployment history in chronological order (promoted deployments only).
- list_
production_ 🔒clusters - List clusters that host at least one promoted deployment.
- list_
staging_ 🔒deployments - List all staging deployments (promoted_at IS NULL), grouped by deploy_id.
- mark_
statement_ 🔒executed - Mark a pending statement as executed.
- update_
promoted_ 🔒at - Update promoted_at timestamp for a staging deployment.
- validate_
deployment_ 🔒clusters - Validate that all cluster IDs in a deployment still exist in the catalog.