Documentation
¶
Index ¶
- type Count
- type Lease
- type LeaseDuration
- type LeasePin
- type State
- func (s *State) ClaimLease(ctx context.Context, uuid uuid.UUID, key corelease.Key, req corelease.Request) error
- func (s *State) ExpireLeases(ctx context.Context) error
- func (s *State) ExtendLease(ctx context.Context, key corelease.Key, req corelease.Request) error
- func (s *State) LeaseGroup(ctx context.Context, namespace, modelUUID string) (map[corelease.Key]corelease.Info, error)
- func (s *State) Leases(ctx context.Context, keys ...corelease.Key) (map[corelease.Key]corelease.Info, error)
- func (s *State) PinLease(ctx context.Context, key corelease.Key, entity string) error
- func (s *State) Pinned(ctx context.Context) (map[corelease.Key][]string, error)
- func (s *State) RevokeLease(ctx context.Context, key corelease.Key, holder string) error
- func (s *State) UnpinLease(ctx context.Context, key corelease.Key, entity string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Pinned (lease.Store) returns all leases that are currently pinned, and the entities requiring such behaviour for them.
func (*State) RevokeLease ¶
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 ¶
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.