src/leader.bend relies on unsafe/foreign
raw source on the hub · import bend-kube-runtime@0.4.0.0/src/leader.bend as Leader
9 imports
import Base import ./json.bend as J import ./core.bend as C import ./config.bend as K import ./client.bend as Cl import ./time.bend as T import ./sys.bend as Y import ./log.bend as L import ./lease.bend as E
Types
type LOpts source · line 20 · raw
Data
LOpts@ns:String -> @name:String -> @id:String -> @dur:U32 -> @deadline:U32 -> @retry:U32 -> LOpts
type LEv source · line 75 · raw
Type
What the loop just saw.
LTryLEv
LAt@w:0xd9e5cff93d88385a2d6e80af4f4859e0/src/time.Wall -> @mono:U32 -> LEv
LRead@w:0xd9e5cff93d88385a2d6e80af4f4859e0/src/time.Wall -> @mono:U32 -> @r:Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/json.Json> -> LEv
LDecided@now:U32 -> @d:Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/lease.Decision> -> LEv
LCheck@now:U32 -> @ok:Bool -> LEv
LWrote@now:U32 -> @ok:Bool -> @late:Bool -> LEv
LFail@stop:Bool -> LEv
Definitions
def LOpts.default source · line 23 · raw
@ns:String -> @name:String -> @id:String -> LOpts
def LOpts.api source · line 26 · raw
@o:LOpts -> 0xd9e5cff93d88385a2d6e80af4f4859e0/src/core.Api
def LOpts.id source · line 31 · raw
@o:LOpts -> String
def LOpts.name source · line 36 · raw
@o:LOpts -> String
def LOpts.retry source · line 41 · raw
@o:LOpts -> U32
def LOpts.deadline source · line 46 · raw
@o:LOpts -> U32
def Leader.read.err source · line 51 · raw
@e:0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr -> @missing:Bool -> Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, Maybe<&2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/json.Json>>
def Leader.read source · line 59 · raw
@r:Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/json.Json> -> Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, Maybe<&2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/json.Json>>
The Lease read: Some, None on 404, or the error.
def Leader.decide source · line 66 · raw
@r:Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, Maybe<&2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/json.Json>> -> @+o:LOpts -> @+obs:0xd9e5cff93d88385a2d6e80af4f4859e0/src/lease.Obs -> @+mono:U32 -> @+w:0xd9e5cff93d88385a2d6e80af4f4859e0/src/time.Wall -> Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/lease.Decision>
def Leader.wrote source · line 84 · raw
@r:Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/json.Json> -> Bool
def Leader.late source · line 87 · raw
@+now:U32 -> @+last:U32 -> @+deadline:U32 -> Bool
def Leader.room.left source · line 90 · raw
@+deadline:U32 -> @+spent:U32 -> @left:Bool -> U32
def Leader.room.go source · line 97 · raw
@+deadline:U32 -> @+spent:U32 -> U32
def Leader.room source · line 102 · raw
@+now:U32 -> @+last:U32 -> @+deadline:U32 -> @leading:Bool -> U32
How long a lease call may take: while leading, what is left of the renew deadline since the last renewal (at least 1ms); else the whole deadline.
def Leader.timed.of source · line 109 · raw
@m:Maybe<&1, Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/json.Json>> -> Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/json.Json>
def Leader.timed source · line 117 · raw
@+ms:U32 -> @act:IO(Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/json.Json>) -> IO(Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/json.Json>)
A lease call that takes longer than ms fails.
def Leader.mono source · line 125 · raw
IO(U32)
The monotonic clock in ms (time since boot, never stepped): every timing decision (expiry, the renew deadline, lateness) uses it; the wall clock only stamps the Lease.
def Leader.started source · line 129 · raw
@leading:Bool -> @start:Maybe<&1, IO(Unit)> -> IO(Unit)
On first acquiring: log and start the work.
def Leader.lost source · line 138 · raw
IO(Unit)
A leader that cannot renew within the deadline stops at once (a candidate that fails just tries again).
def Leader.renewed source · line 144 · raw
@late:Bool -> @go:IO(Unit) -> IO(Unit)
A leader's renewal that landed only after the renew deadline counts as lost (client-go's RenewDeadline): a standby may already have judged the lease expired.
def Leader.run source · line 152 · raw
@outer:Nat -> @fuel:Nat -> @ev:LEv -> @+cfg:0xd9e5cff93d88385a2d6e80af4f4859e0/src/config.Config -> @+o:LOpts -> @+obs:0xd9e5cff93d88385a2d6e80af4f4859e0/src/lease.Obs -> @+leading:Bool -> @+last:U32 -> @start:Maybe<&1, IO(Unit)> -> IO(Unit)
The election loop. start runs once, when the lease is first ours.
def Leader.release.said source · line 207 · raw
@r:Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/json.Json> -> IO(Bool)
def Leader.release.mine source · line 215 · raw
@+cfg:0xd9e5cff93d88385a2d6e80af4f4859e0/src/config.Config -> @+o:LOpts -> @l:0xd9e5cff93d88385a2d6e80af4f4859e0/src/json.Json -> @mine:Bool -> IO(Bool)
def Leader.release.got source · line 225 · raw
@r:Result<&2, &2, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/client.KErr, 0xd9e5cff93d88385a2d6e80af4f4859e0/src/json.Json> -> @+cfg:0xd9e5cff93d88385a2d6e80af4f4859e0/src/config.Config -> @+o:LOpts -> @w:0xd9e5cff93d88385a2d6e80af4f4859e0/src/time.Wall -> IO(Bool)
Hands the lease back if it is ours; answers whether there is nothing left to do.
def Leader.release.once source · line 236 · raw
@+cfg:0xd9e5cff93d88385a2d6e80af4f4859e0/src/config.Config -> @+o:LOpts -> IO(Bool)
def Leader.release.again source · line 241 · raw
@n:Nat -> @+cfg:0xd9e5cff93d88385a2d6e80af4f4859e0/src/config.Config -> @+o:LOpts -> @done:Bool -> IO(Unit)
def Leader.release.timed source · line 248 · raw
@m:Maybe<&1, Unit> -> IO(Unit)
def Leader.release source · line 257 · raw
@+cfg:0xd9e5cff93d88385a2d6e80af4f4859e0/src/config.Config -> @+o:LOpts -> IO(Unit)
Hands the lease back, reading it afresh and trying again if a renewal raced the write (a 409), up to three times, within 4s in all.
def Leader.again source · line 262 · raw
IO(Unit)
A second SIGTERM or SIGINT while draining exits at once.
def Leader.handover source · line 269 · raw
@+cfg:0xd9e5cff93d88385a2d6e80af4f4859e0/src/config.Config -> @+o:LOpts -> @drained:Bool -> IO(Unit)
The lease goes back only after a clean drain. A reconcile still running past the grace period could otherwise overlap the next leader's; the process exits holding the lease, which expires after its duration.
def Leader.on_signal source · line 279 · raw
@+cfg:0xd9e5cff93d88385a2d6e80af4f4859e0/src/config.Config -> @+o:LOpts -> @drain:IO(Bool) -> IO(Unit)
On SIGTERM or SIGINT: drain (stop starting reconciles and wait for the running ones, up to the grace period), hand the lease back if nothing is left running, then exit 0; a second signal exits at once.
def Leader.elect source · line 287 · raw
@+cfg:0xd9e5cff93d88385a2d6e80af4f4859e0/src/config.Config -> @+o:LOpts -> @drain:IO(Bool) -> @work:IO(Unit) -> IO(Unit)
Runs work only while we hold the lease (client-go's RunOrDie); drain runs on SIGTERM before the lease is handed back.