~/bend-docscommunity

src/lease.bend checks

raw source on the hub · import bend-kube-runtime@0.5.2.0/src/lease.bend as Lease

3 imports
import Base
import ./json.bend as J
import ./core.bend as C

Types

type Obs source · line 24 · raw

Data

What we last saw of the record, and when (our clock, in ms).

type LeaseAct source · line 27 · raw

Data

type Decision source · line 32 · raw

Data

Definitions

def Obs.none source · line 35 · raw

Obs

def Lease.spec source · line 38 · raw

@+l:0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json -> @field:String -> 0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json

def Lease.holder source · line 41 · raw

@+l:0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json -> String

def Lease.renew_time source · line 44 · raw

@+l:0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json -> String

def Lease.transitions source · line 47 · raw

@+l:0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json -> U32

def Lease.new_spec source · line 50 · raw

@id:String -> @+dur:U32 -> @acquire:String -> @renew:String -> @+trans:U32 -> 0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json

def Lease.fresh source · line 56 · raw

@ns:String -> @name:String -> @id:String -> @+dur:U32 -> @+now:String -> 0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json

A fresh Lease naming us.

def Lease.elapsed.go source · line 61 · raw

@+d:U32 -> @back:Bool -> U32

def Lease.elapsed source · line 71 · raw

@+now:U32 -> @+at:U32 -> U32

Time since an observation, by our clock: a clock that stepped back (now before at, by the wrapped difference) counts as no time at all, so a clock step can never make a live lease look expired.

def Lease.observe.same source · line 74 · raw

@o:Obs -> @+now:U32 -> @back:Bool -> Obs

def Obs.at source · line 82 · raw

@o:Obs -> U32

def Lease.observe.go source · line 87 · raw

@h:String -> @r:String -> @+o:Obs -> @+now:U32 -> @same:Bool -> Obs

def Lease.observe source · line 96 · raw

@+l:0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json -> @o:Obs -> @+now:U32 -> Obs

The record seen now: the old observation if nothing changed, else a new one stamped now.

def Lease.duration.pos source · line 102 · raw

@+d:U32 -> @+dur:U32 -> @zero:Bool -> U32

def Lease.duration.go source · line 109 · raw

@m:Maybe<&2, U32> -> @+dur:U32 -> U32

def Lease.duration source · line 119 · raw

@+l:0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json -> @+dur:U32 -> U32

The holder's own lease duration (spec.leaseDurationSeconds), so a contender configured shorter cannot expire a holder early; ours when the Lease does not say.

def Lease.held source · line 123 · raw

@+l:0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json -> @+me:String -> @o:Obs -> @+now:U32 -> @+dur:U32 -> Bool

Whether another holder's lease is still live by our clock.

def Lease.take.go source · line 130 · raw

@+l:0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json -> @me:String -> @+dur:U32 -> @+now:String -> @ours:Bool -> 0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json

def Lease.take source · line 139 · raw

@+l:0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json -> @+me:String -> @+dur:U32 -> @+now:String -> 0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json

The Lease rewritten to name us, keeping its metadata (resourceVersion).

def Lease.decide.fin source · line 142 · raw

@+l:0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json -> @+me:String -> @o:Obs -> @+dur:U32 -> @+now:String -> @held:Bool -> Decision

def Lease.decide.held source · line 150 · raw

@+l:0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json -> @+me:String -> @+o:Obs -> @+now_ms:U32 -> @+dur:U32 -> @+now:String -> Decision

def Lease.decide.got source · line 154 · raw

@+l:0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json -> @+me:String -> @o:Obs -> @+now_ms:U32 -> @+dur:U32 -> @+now:String -> Decision

def Lease.decide source · line 160 · raw

@cur:Maybe<&2, 0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json> -> @ns:String -> @name:String -> @+me:String -> @o:Obs -> @+now_ms:U32 -> @+dur:U32 -> @+now:String -> Decision

One round: the Lease read (None when absent), us, what we saw before, our clock in ms, the lease duration in seconds, and the time to stamp.

def Lease.release source · line 170 · raw

@+l:0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json -> @+now:String -> 0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/json.Json

The Lease handed back: no holder, a one-second duration, so the next candidate takes it at once (client-go's ReleaseOnCancel).

def Lease.timing.go source · line 173 · raw

@zero:Bool -> @short:Bool -> @tight:Bool -> Maybe<&2, String>

def Lease.timing.big source · line 186 · raw

@+dur:U32 -> @+deadline:U32 -> @+retry:U32 -> @big:Bool -> Maybe<&2, String>

Settings over a day are refused before any arithmetic, which then cannot overflow.

def Lease.timing source · line 198 · raw

@+dur:U32 -> @+deadline:U32 -> @+retry:U32 -> Maybe<&2, String>

Election timing that keeps two leaders from acting at once, as client-go's NewLeaderElector checks it: every setting above zero, the lease (dur, seconds) longer than the renew deadline (ms), and the deadline longer than 1.2 retry periods (ms). The fault, if any.

def Lease.room.left source · line 202 · raw

@+deadline:U32 -> @+spent:U32 -> @left:Bool -> U32

def Lease.room.go source · line 209 · raw

@+deadline:U32 -> @+spent:U32 -> U32

def Lease.room source · line 215 · raw

@+now:U32 -> @+last:U32 -> @+deadline:U32 -> @leading:Bool -> U32

def Lease.nap source · line 228 · raw

@+now:U32 -> @+last:U32 -> @+deadline:U32 -> @+retry:U32 -> @leading:Bool -> U32

How long to wait before the next try: the retry period, but for a leader never past its renew deadline, so it notices the deadline in time (the loop checks it before every request).

def Lease.late source · line 237 · raw

@+now:U32 -> @+last:U32 -> @+deadline:U32 -> Bool

Whether the renew deadline has passed since the last renewal (reaching it counts: a standby may act from then on).