state

package
v0.0.0-...-f88c608 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: AGPL-3.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Count

type Count struct {
	Num int `db:"num"`
}

Count is used count leases.

type Lease

type Lease struct {
	// UUID is the unique id of the lease.
	UUID string `db:"uuid"`
	// Type is the name of the type.
	Type string `db:"type"`
	// ModelUUID is the UUID of the model the lease is for.
	ModelUUID string `db:"model_uuid"`
	// Name is the name of the lease.
	Name string `db:"name"`
	// Holder is the holder of the lease.
	Holder string `db:"holder"`
	// Start is the lease start time.
	Start time.Time `db:"start"`
	// Duration is the duration of the lease. It is used only when inserting an
	// expiry time, the actual time is calculated from the duration by the
	// database.
	Duration LeaseDuration `db:"duration"`
	// Expiry is the lease expiry time. Expiry is only used to read expiry
	// times, Duration is used for writing.
	Expiry time.Time `db:"expiry"`
}

Lease represents a lease to be serialised to the database.

type LeaseDuration

type LeaseDuration time.Duration

func (LeaseDuration) Value

func (d LeaseDuration) Value() (driver.Value, error)

Value implements the Valuer interface for scanning

type LeasePin

type LeasePin struct {
	// UUID is the unique identifier of the lease pin.
	UUID string `db:"uuid"`
	// EntityID is the id of the entity requesting the pin.
	EntityID string `db:"entity_id"`
}

LeasePin represents a lease pin to be serialised to the database.

type State

type State struct {
	*domain.StateBase
	// contains filtered or unexported fields
}

State describes retrieval and persistence methods for storage.

func NewState

func NewState(factory coredatabase.TxnRunnerFactory, logger logger.Logger) *State

NewState returns a new state reference.

func (*State) ClaimLease

func (s *State) ClaimLease(ctx context.Context, uuid uuid.UUID, key corelease.Key, req corelease.Request) error

ClaimLease (lease.Store) claims the lease indicated by the input key, for the holder and duration indicated by the input request. The lease must not already be held, otherwise an error is returned.

func (*State) ExpireLeases

func (s *State) ExpireLeases(ctx context.Context) error

ExpireLeases (lease.Store) deletes all leases that have expired, from the store. This method is intended to be called periodically by a worker.

func (*State) ExtendLease

func (s *State) ExtendLease(ctx context.Context, key corelease.Key, req corelease.Request) error

ExtendLease (lease.Store) ensures the input lease will be held for at least the requested duration starting from now. If the input holder does not currently hold the lease, an error is returned.

func (*State) LeaseGroup

func (s *State) LeaseGroup(ctx context.Context, namespace, modelUUID string) (map[corelease.Key]corelease.Info, error)

LeaseGroup (lease.Store) returns all leases for the input namespace and model.

func (*State) Leases

func (s *State) Leases(ctx context.Context, keys ...corelease.Key) (map[corelease.Key]corelease.Info, error)

Leases (lease.Store) returns all leases in the database, optionally filtering using the input keys.

func (*State) PinLease

func (s *State) PinLease(ctx context.Context, key corelease.Key, entity string) error

PinLease (lease.Store) adds the input entity into the lease_pin table to indicate that the lease indicated by the input key must not expire, and that this entity requires such behaviour.

func (*State) Pinned

func (s *State) Pinned(ctx context.Context) (map[corelease.Key][]string, error)

Pinned (lease.Store) returns all leases that are currently pinned, and the entities requiring such behaviour for them.

func (*State) RevokeLease

func (s *State) RevokeLease(ctx context.Context, key corelease.Key, holder string) error

RevokeLease (lease.Store) deletes the lease from the store, provided it exists and is held by the input holder. If either of these conditions is false, an error is returned.

func (*State) UnpinLease

func (s *State) UnpinLease(ctx context.Context, key corelease.Key, entity string) error

UnpinLease (lease.Store) removes the record indicated by the input key and entity from the lease pin table, indicating that the entity no longer requires the lease to be pinned. When there are no entities associated with a particular lease, it is determined not to be pinned, and can expire normally.

Jump to

Keyboard shortcuts

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