Managing Trino Cluster Lifecycles Safely

Ram AggarwalData Platforms Engineer
Safe Trino cluster lifecycle

Stopping new assignments to a Trino cluster is only the first half of removing it. Existing clients can still depend on that coordinator to retrieve results. If the Gateway backend disappears too early, a capacity change becomes a client-visible failure even when query execution appears complete.

In Part 1 we described how Fleet Commander places queries across fleets. This article follows the other end of the lifecycle: how we stop admitting work, wait for existing queries, and recover when a coordinator or cleanup operation stops responding.

The normal drain path aims to preserve in-progress queries. Timeout and failure paths may interrupt work, so operators need to distinguish a completed drain from forced termination.

Safe cluster drain sequence

Figure 1. Normal removal preserves the result path while the selector redirects new work. Timeout and unreachable-coordinator paths use an explicit termination policy.

Why Draining Needs Its Own Protocol

When a cluster begins draining, Fleet Commander marks it as draining so the selector excludes it from new query assignments. Trino Gateway remains connected to the cluster to handle queries already in progress.

A query in FINISHING can still be retrieving results or completing work such as a write commit. Removing its Gateway backend prematurely can break result polling. We therefore separate eligibility for new placement from the continued availability of the result path. That separation is the core of the drain protocol.

On the normal path, Fleet Commander waits for running, queued, and finishing queries to reach zero. If a check fails, an unknown count does not become zero. Missing evidence is not proof that all work has completed.

When the Coordinator Stops Responding

A draining cluster may become unreachable before its coordinator can confirm that its work has finished. Without that confirmation, Fleet Commander cannot use its usual completion checks to determine when teardown can proceed.

Fleet Commander stops treating an unreachable backend as a normal destination and uses repeated health checks and a configurable drain timeout to bound the wait. If progress cannot be established, it follows an explicit termination path.

Forced termination can interrupt in-flight work. The policy trades more waiting against prolonged unavailability and stranded capacity. Its timeout should reflect the workload rather than remain an unexplained infrastructure setting.

Missing Metrics Do Not Mean an Idle Cluster

Fleet Commander uses coordinator metrics to assess cluster load. If a metrics request fails, treating the missing value as zero can lead the router to send more queries to a cluster whose actual load is unknown. This creates a risk of routing work to a cluster that may not be healthy enough to accept it.

When a coordinator cannot be reached, Fleet Commander retains its last known load and penalises stale observations in normal selection. Health, registration, and Gateway availability also influence placement.

The principle is to avoid interpreting uncertainty as spare capacity. Degraded and fallback paths still make availability trade-offs, so freshness penalties are not an absolute safety guarantee.

Recovery Needs the Context of What Happened

Removing a cluster can also remove the evidence needed to investigate its queries. Before teardown, Fleet Commander performs a final history synchronisation with Gateway to reduce gaps in recent activity.

It also attempts to collect coordinator logs. Collection is best-effort, but those logs can remain useful after the Kubernetes resources have gone.

Recovery introduced another trap: measuring the wrong clock. A query might execute for several minutes before entering FINISHING. Comparing its total runtime with a finishing timeout could cancel it immediately, even though finishing has barely begun.

The cleaner measures time spent finishing, using an estimate if coordinator detail is unavailable. It protects writes and treats unknown SQL conservatively. A long runtime alone is not sufficient evidence that a query is stuck.

Measuring time in FINISHING

The Cluster Can Disappear Before Its History Arrives

Query history arrives asynchronously. A collector can move past a timestamp before the corresponding record becomes visible, leaving a gap even though every collection run appeared successful.

Fleet Commander revisits a small overlap in recent history and deduplicates by query ID. Reading some records again is a deliberate trade-off to avoid losing late arrivals.

A short-lived cluster may also disappear before its final query details are collected. An optional completion-event backfill offers another recovery path. It reduces dependence on coordinator lifetime, but relies on the event pipeline being configured and retaining the records.

Late query history recovery

Making Lifecycle Operations Safe to Retry

Cluster removal spans PostgreSQL, Gateway, Helm, and Kubernetes. An operation can fail partway through, and a delayed response can leave a worker unsure whether a step succeeded. Retrying must account for that uncertainty.

Fleet Commander claims cleanup ownership before beginning slow teardown, so competing workers do not independently start the same removal. That claim records who should continue; it does not prove the infrastructure has already disappeared.

A crash after the claim can leave resources behind. Reconciliation checks for orphaned namespaces and stale Gateway entries, allowing later passes to finish incomplete cleanup.

There is no single transaction across all these systems. Recovery depends on retryable operations, visible intermediate state, and reconciliation rather than an assumption of exactly-once execution.

Retryable cluster cleanup

What This Changes for Operators

Fleet Commander brings cluster health, Gateway state, lifecycle progress, and query history into one operational view. Operators can investigate routing and lifecycle decisions without piecing together every step across separate systems.

Draining and teardown follow defined steps, while recorded state helps distinguish a cluster still serving queries from one waiting for infrastructure cleanup.

Failures can still occur. The benefit is a clearer account of what the system tried, where it stopped, and what a later recovery pass needs to complete.

What We Would Keep in the Design

We would carry three choices into another control plane: separate new assignments from existing client dependencies, measure time in the state that matters, and claim cleanup before starting slow teardown. Each addresses a failure that a healthy pod or a successful API response alone cannot explain.

Observations can lag, forced termination can interrupt queries, and recorded cleanup intent can precede resource deletion. Safe lifecycle management depends on making those differences visible and giving reconciliation enough information to finish the work.

Read Part 1: Operating Shared Trino Workloads with Fleet Commander.

Building Trino Fleet Commander was a team effort shaped by the engineering challenges we worked through together. The work reflects the Data Platform team's collective contribution, including Nilesh Kumar Sinha, Abhishek Gedela, Ram Aggarwal, and Utkarsh Purohit.

Posted
Nov 24, 2026
 in 
Engineering
 category

More from 

Engineering

 category

View All
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.