overlap_on
def overlap_on() -> Bool ORCA_OVERLAP: off (the default: one scheduler at a time, as before) or on (an instance row, a lead, and a drain).
orca.instancesScheduler instances: two orca schedulers of different images overlapping on one Postgres during a deploy (docs/overlap.md).
With ORCA_OVERLAP=on, each orca scheduler has a row in
orca.schedulers, kept fresh on every tick with the runs its processes
are. One instance leads: it holds the session advisory lock LEAD_LOCK,
and only it decides (fires, sensors, retries, starts, alerts, sweeps). The
newest live instance takes the lead: an older one that sees a newer one
live, or is asked to (orca scheduler drain), gives the lock up and
drains: it starts nothing, keeps supervising the processes it started
until they end, then ends its row and exits. A run an instance started
records it (runs.instance), and orca.live.held_sql keeps it live while
the instance lists it, so the leader counts it and leaves it alone.
An instance is live while it has been seen within the stale limit and
hasn't ended; "gone" is the opposite, and only then are its runs, once
their heartbeats are stale too, queued again (Scheduler._requeue_orphans).
overlap_ondef overlap_on() -> Bool ORCA_OVERLAP: off (the default: one scheduler at a time, as before) or on (an instance row, a lead, and a drain).
live_conddef live_cond(stale: Float64) -> String SQL true for a row of orca.schedulers that is live: not ended, and seen within stale seconds.
joindef join(mut db: State) -> Int Adds this process's row, waiting, with the migrations it knows and its image (ORCA_IMAGE); returns its id.
beatdef beat(mut db: State, id: Int, running: String) -> Bool Marks instance id seen, with running (run ids, comma-separated) its processes' runs; returns whether it was asked to drain.
newerdef newer(mut db: State, id: Int) -> Int The newest live instance after id that isn't draining, or 0.
try_leaddef try_lead(mut db: State, id: Int) -> Bool Takes the lead for instance id if no one holds it; records it.
step_downdef step_down(mut db: State, id: Int, leading: Bool) Instance id drains: gives up the lead if it held it, and records that it drains.
enddef end(mut db: State, id: Int) Instance id has ended: gone at once, for the leader's requeue.
ask_draindef ask_drain(mut db: State, id: Int) -> Bool Asks live instance id to drain; False if there's no such one.
instancesdef instances(mut db: State) -> List[String] A line for each instance not long gone (ended or unseen within the last hour), oldest first: id, host and pid, role, image, migrations known, runs going, and when it was last seen.
overlap_refusaldef overlap_refusal(mut db: State) -> String Why this binary can't start beside the scheduler going now, or empty if it can (docs/overlap.md#deploying): a live instance leads, and no live instance knows fewer migrations than this binary's floor (orca.state.migration_floor), which its migrations would raise past it. Doesn't migrate.
wait_for_leaddef wait_for_lead(mut db: State, timeout: Float64) -> Bool Waits, up to timeout seconds, for the newest live instance to lead (a handover over); True at once with no instance live. A deploy registers the new image's pipelines only after this, so the instance going away never starts their new code.
comptime LEAD_LOCK = 1869767525The session advisory lock the leading instance holds.