Documentation ¶
Overview ¶
Package leases implements logic for determining the state of shards based on their membership Lease object. It is used by the shardlease controller to maintain the state label.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Shard ¶
type Shard struct { // ID is the ID of this Shard, i.e., the name of the Lease object. ID string // State is the current state of this shard based on the times and durations of the Lease object. State ShardState // Times holds the parsed times and durations of the Lease object. Times Times }
Shard represents a single shard in a ring of controller instances.
type ShardState ¶
type ShardState int
ShardState represents a state of a single shard which determines whether it is available for assigning objects to it or whether it is unhealthy.
const ( // Unknown is the ShardState if the Lease is not present or misses required fields. Unknown ShardState = iota // Orphaned is the ShardState if the Lease has been in state Dead for at least 1 minute. Orphaned // Dead is the ShardState if the Lease is Uncertain and was successfully acquired by the sharder. Dead // Uncertain is the ShardState if the Lease has expired at least leaseDuration ago. Uncertain // Expired is the ShardState if the Lease has expired less than leaseDuration ago. Expired // Ready is the ShardState if the Lease is held by the shard and has not expired. Ready )
func StateFromString ¶
func StateFromString(state string) ShardState
StateFromString returns the ShardState matching the given string representation.
func ToState ¶
func ToState(lease *coordinationv1.Lease, now time.Time) ShardState
ToState returns the ShardState of the given Lease.
func (ShardState) IsAvailable ¶
func (s ShardState) IsAvailable() bool
IsAvailable returns true for shard states that should be considered for object assignment.
func (ShardState) String ¶
func (s ShardState) String() string
String returns a string representation of this ShardState.
type Shards ¶
type Shards []Shard
Shards is a list of Shards. This could also be a map, but a slice is deterministic in order. The methods returning a list are called way more frequently than a lookup using ByID.
func ToShards ¶
func ToShards(leases []coordinationv1.Lease, now time.Time) Shards
ToShards takes a list of Lease objects and transforms them to a list of Shards.
func (Shards) AvailableShards ¶
AvailableShards returns the subset of available Shards as determined by IsAvailable.
type Times ¶
type Times struct { // Expiration is the time when the Lease expires (RenewTime + LeaseDurationSeconds) Expiration time.Time // LeaseDuration is LeaseDurationSeconds represented as a Duration. LeaseDuration time.Duration // ToExpired is the duration until the Lease expires (Expiration - now). ToExpired time.Duration // ToUncertain is the duration until the Shard Lease becomes uncertain and should get acquired by the sharder // (ToExpired + LeaseDuration). ToUncertain time.Duration // ToOrphaned is the duration until the Lease becomes orphaned and should get cleaned up (ToExpired + leaseTTL). ToOrphaned time.Duration }
Times holds the parsed times and durations of the Lease object.