When to use it
Use it when losing the one server that admits runs is not acceptable. It gives failover, not scale-out: admission, command ordering and run state live in one server at a time. To spread node work over more machines, see Remote workers.How it works
All servers run the same build against the same database. A lease row in PostgreSQL names the current leader and when its lease expires.- The leader renews the lease three times per lease period. With the default
15slease, that is every 5 seconds. - A standby tries to take the lease once it has expired, in one atomic database statement.
- Each change of holder increases a fencing number stored in the lease row.
- A server counts itself leader only while its own last renewal is younger than the lease, measured on its own clock. A server that cannot reach the database therefore stops admitting runs before another server can take over.
- A server that stops gracefully releases the lease at once, so a standby does not wait for it to expire.
What a standby does
A standby is a normal running server that does not admit work:- It refuses every start, restart and resume with HTTP
503and the message “This server is a standby; retry on the leader”. The counteryukta.executions.rejected{reason=not_leader}counts these. - It refuses worker registrations.
- It does not run recovery at start, so it does not mark a living leader’s runs
ABORTED.
Takeover and recovery
When a server becomes leader, including the first server at a cold start, it runs recovery once:- Runs of the previous leader that never finished are marked
ABORTED. - The newest runs are restored into history from the shared execution log.
- With
yukta.restart.auto-resume=true, the interrupted runs are resumed one after another from their checkpoints.
Not carried over
These are not carried over to the new leader:- Approval waits that were open (the plugin waiting for a signal). A resumed run waits again.
- Queued starts that had not yet run.
- Execution slots held by the old leader.
- Live progress state of the old leader beyond what the execution log records.
How clients and workers find the leader
Yukta does not proxy requests to the leader. A client that reaches a standby gets503 and must try the other address.
- Clients: list every server in the client configuration, or put a load balancer in front whose health check selects the leader.
- Workers: set
yukta.workers.control-planeto every server, comma separated. A standby refuses the worker, so the worker ends up on the leader. After a failover it tries the next address.
Health check on the leader gauge
The gaugeyukta.leader is 1 on the leader and 0 on a standby. Read it from the metrics endpoint:
1.0 on the leader. When keys are configured, the metrics endpoint needs an unrestricted ADMIN key. /actuator/health stays open but does not tell leaders from standbys, so a load balancer that must route to the leader should use the gauge.
Alert when no server reports 1, or when more than one does.
Settings
postgres profile and the connection URLs described in Persistence.