~/bend-docscommunity

src/leader.bend relies on unsafe/foreign

raw source on the hub · import bend-kube-runtime@0.12.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

type LEv source · line 75 · raw

Type

What the loop just saw.

Definitions

def LOpts.default source · line 23 · raw

@ns:String -> @name:String -> @id:String -> LOpts

def LOpts.api source · line 26 · raw

@o:LOpts -> 0x9e77ca668bf7a778a1520b32b67729c2/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:0x9e77ca668bf7a778a1520b32b67729c2/src/client.KErr -> @missing:Bool -> Result<&2, &2, 0x9e77ca668bf7a778a1520b32b67729c2/src/client.KErr, Maybe<&2, 0x9e77ca668bf7a778a1520b32b67729c2/src/json.Json>>

def Leader.read source · line 59 · raw

@r:Result<&2, &2, 0x9e77ca668bf7a778a1520b32b67729c2/src/client.KErr, 0x9e77ca668bf7a778a1520b32b67729c2/src/json.Json> -> Result<&2, &2, 0x9e77ca668bf7a778a1520b32b67729c2/src/client.KErr, Maybe<&2, 0x9e77ca668bf7a778a1520b32b67729c2/src/json.Json>>

The Lease read: Some, None on 404, or the error.

def Leader.decide source · line 66 · raw

@r:Result<&2, &2, 0x9e77ca668bf7a778a1520b32b67729c2/src/client.KErr, Maybe<&2, 0x9e77ca668bf7a778a1520b32b67729c2/src/json.Json>> -> @+o:LOpts -> @+obs:0x9e77ca668bf7a778a1520b32b67729c2/src/lease.Obs -> @+mono:U32 -> @+w:0x9e77ca668bf7a778a1520b32b67729c2/src/time.Wall -> Result<&2, &2, 0x9e77ca668bf7a778a1520b32b67729c2/src/client.KErr, 0x9e77ca668bf7a778a1520b32b67729c2/src/lease.Decision>

def Leader.wrote source · line 84 · raw

@r:Result<&2, &2, 0x9e77ca668bf7a778a1520b32b67729c2/src/client.KErr, 0x9e77ca668bf7a778a1520b32b67729c2/src/json.Json> -> Bool

def Leader.timed.of source · line 87 · raw

@m:Maybe<&1, Result<&2, &2, 0x9e77ca668bf7a778a1520b32b67729c2/src/client.KErr, 0x9e77ca668bf7a778a1520b32b67729c2/src/json.Json>> -> Result<&2, &2, 0x9e77ca668bf7a778a1520b32b67729c2/src/client.KErr, 0x9e77ca668bf7a778a1520b32b67729c2/src/json.Json>

def Leader.timed source · line 95 · raw

@+ms:U32 -> @act:IO(Result<&2, &2, 0x9e77ca668bf7a778a1520b32b67729c2/src/client.KErr, 0x9e77ca668bf7a778a1520b32b67729c2/src/json.Json>) -> IO(Result<&2, &2, 0x9e77ca668bf7a778a1520b32b67729c2/src/client.KErr, 0x9e77ca668bf7a778a1520b32b67729c2/src/json.Json>)

A lease call that takes longer than ms fails.

def Leader.mono source · line 104 · raw

IO(U32)

The monotonic clock in ms (never stepped; wrapped subtraction handles its 49.7-day wrap): every timing decision (expiry, the renew deadline, lateness) uses it; the wall clock only stamps the Lease.

def Leader.started source · line 108 · raw

@leading:Bool -> @start:Maybe<&1, IO(Unit)> -> IO(Unit)

On first acquiring: log and start the work.

def Leader.lost source · line 117 · raw

IO(Unit)

A leader that cannot renew within the deadline stops at once (a candidate that fails just tries again).

def Leader.fence source · line 123 · raw

@m:Maybe<&2, Chan(0x9e77ca668bf7a778a1520b32b67729c2/src/config.FenceMsg)> -> @+f:0x9e77ca668bf7a778a1520b32b67729c2/src/config.Fence -> IO(Unit)

Moves the leadership fence (K.Config.fence) to a renewal: every write of the controllers' requests asks the fence keeper first, so none leaves once this renewal is past the deadline.

def Leader.renewed source · line 134 · 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 142 · raw

@outer:Nat -> @fuel:Nat -> @ev:LEv -> @+cfg:0x9e77ca668bf7a778a1520b32b67729c2/src/config.Config -> @+o:LOpts -> @+obs:0x9e77ca668bf7a778a1520b32b67729c2/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 208 · raw

@r:Result<&2, &2, 0x9e77ca668bf7a778a1520b32b67729c2/src/client.KErr, 0x9e77ca668bf7a778a1520b32b67729c2/src/json.Json> -> IO(Bool)

def Leader.release.mine source · line 216 · raw

@+cfg:0x9e77ca668bf7a778a1520b32b67729c2/src/config.Config -> @+o:LOpts -> @l:0x9e77ca668bf7a778a1520b32b67729c2/src/json.Json -> @mine:Bool -> IO(Bool)

def Leader.release.got source · line 226 · raw

@r:Result<&2, &2, 0x9e77ca668bf7a778a1520b32b67729c2/src/client.KErr, 0x9e77ca668bf7a778a1520b32b67729c2/src/json.Json> -> @+cfg:0x9e77ca668bf7a778a1520b32b67729c2/src/config.Config -> @+o:LOpts -> @w:0x9e77ca668bf7a778a1520b32b67729c2/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 237 · raw

@+cfg:0x9e77ca668bf7a778a1520b32b67729c2/src/config.Config -> @+o:LOpts -> IO(Bool)

def Leader.release.again source · line 242 · raw

@n:Nat -> @+cfg:0x9e77ca668bf7a778a1520b32b67729c2/src/config.Config -> @+o:LOpts -> @done:Bool -> IO(Unit)

def Leader.release.timed source · line 249 · raw

@m:Maybe<&1, Unit> -> IO(Unit)

def Leader.release source · line 258 · raw

@+cfg:0x9e77ca668bf7a778a1520b32b67729c2/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 263 · raw

IO(Unit)

A second SIGTERM or SIGINT while draining exits at once.

def Leader.handover source · line 270 · raw

@+cfg:0x9e77ca668bf7a778a1520b32b67729c2/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 280 · raw

@+cfg:0x9e77ca668bf7a778a1520b32b67729c2/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.go source · line 288 · raw

@+cfg:0x9e77ca668bf7a778a1520b32b67729c2/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.

def LOpts.check source · line 292 · raw

@o:LOpts -> Maybe<&2, String>

def Leader.elect.ok source · line 297 · raw

@+cfg:0x9e77ca668bf7a778a1520b32b67729c2/src/config.Config -> @+o:LOpts -> @drain:IO(Bool) -> @work:IO(Unit) -> @bad:Maybe<&2, String> -> IO(Unit)

def Leader.elect source · line 308 · raw

@+cfg:0x9e77ca668bf7a778a1520b32b67729c2/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), after checking the timing is safe (Lease.timing); drain runs on SIGTERM before the lease is handed back.