leases

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

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.

func ToShard

func ToShard(lease *coordinationv1.Lease, now time.Time) Shard

ToShard takes a Lease object and transforms it to a Shard.

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

func (s Shards) AvailableShards() Shards

AvailableShards returns the subset of available Shards as determined by IsAvailable.

func (Shards) ByID

func (s Shards) ByID(id string) Shard

ByID returns the Shard with the given ID from the list of Shards.

func (Shards) IDs

func (s Shards) IDs() []string

IDs returns the list of Shard IDs.

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.

func ToTimes

func ToTimes(lease *coordinationv1.Lease, now time.Time) Times

ToTimes parses the times and durations in the given Lease object and returns them in the Times representation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL