module TrinoDemand
How many executions need the Trino engine right now. While it is above zero, the engine stays up.
Constants
- ACTIVE_EXECUTION_STATUSES
- PENDING_STALE_AFTER
-
A “pending” execution is demand too, so one whose dispatch never arrived (worker down when it was enqueued, queue row lost, primary commit rolled back) held the engine up forever - reaping only looked at “running”.
Deliberately well above the whole start path: READY_TIMEOUT x MAX_START_ATTEMPTS plus slack, so a run legitimately waiting for a slow engine start is never reaped. A failed start already fails its pending executions through SuperviseEngineStartJob#fail_pending_executions!.
- STALE_AFTER
Public Instance Methods
Source
# File app/models/trino_demand.rb, line 33 def any? = count.positive?
Whether anything currently needs the engine. @return [Boolean]
Source
# File app/models/trino_demand.rb, line 36 def breakdown { maintenance: maintenance_count } end
Detail for the “in progress” screen.
Source
# File app/models/trino_demand.rb, line 22 def count reap_orphans! maintenance_count end
Total executions currently needing the engine, after reaping orphaned ones. @return [Integer]
Source
# File app/models/trino_demand.rb, line 29 def maintenance_count = ExecutionHistory.where(status: ACTIVE_EXECUTION_STATUSES).count
Number of maintenance executions currently pending or running. @return [Integer]
Source
# File app/models/trino_demand.rb, line 42 def reap_orphans! ExecutionHistory .where(status: "running") .where("COALESCE(last_heartbeat_at, started_at) < ?", STALE_AFTER.ago) .find_each do |execution| ExecutionFailureHandler.handle(execution, "Trino coordinator lost during execution (no heartbeat for #{STALE_AFTER.inspect})") end ExecutionHistory .where(status: "pending") .where("COALESCE(started_at, created_at) < ?", PENDING_STALE_AFTER.ago) .find_each do |execution| ExecutionFailureHandler.handle(execution, "dispatch never arrived (pending for over #{PENDING_STALE_AFTER.inspect})") end end
A “live” execution without a heartbeat for too long lost its coordinator together with the query.