service

package
v0.0.0-...-c1ee6d7 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvenOwnersPrioritizer

type EvenOwnersPrioritizer struct {
	// contains filtered or unexported fields
}

EvenOwnerAllocationsPrioritizer is a prioritizer that tries to spread license allocations evenly across owners.

Time is not part of the equation: if user A has 10 licenses allocated and an user B comes by, it will prioritize B over A until there is a 5 ~ 5 distribution in number of licenses.

func NewEvenOwnersPrioritizer

func NewEvenOwnersPrioritizer() *EvenOwnersPrioritizer

func (*EvenOwnersPrioritizer) OnAllocate

func (so *EvenOwnersPrioritizer) OnAllocate(inv *invocation)

func (*EvenOwnersPrioritizer) OnDequeue

func (so *EvenOwnersPrioritizer) OnDequeue(inv *invocation)

func (*EvenOwnersPrioritizer) OnEnqueue

func (so *EvenOwnersPrioritizer) OnEnqueue(inv *invocation)

func (*EvenOwnersPrioritizer) OnRelease

func (so *EvenOwnersPrioritizer) OnRelease(inv *invocation)

func (*EvenOwnersPrioritizer) Sorter

func (so *EvenOwnersPrioritizer) Sorter() Sorter

type FIFOPrioritizer

type FIFOPrioritizer struct {
}

FIFOPrioritizer simply keeps the entries in the order they were queued.

func (*FIFOPrioritizer) OnAllocate

func (_ *FIFOPrioritizer) OnAllocate(inv *invocation)

func (*FIFOPrioritizer) OnDequeue

func (_ *FIFOPrioritizer) OnDequeue(inv *invocation)

func (*FIFOPrioritizer) OnEnqueue

func (_ *FIFOPrioritizer) OnEnqueue(inv *invocation)

func (*FIFOPrioritizer) OnRelease

func (_ *FIFOPrioritizer) OnRelease(inv *invocation)

func (*FIFOPrioritizer) Sorter

func (_ *FIFOPrioritizer) Sorter() Sorter

type Filter

type Filter func(pos Position, inv *invocation) bool

Filter is a function used to remove entries from the queue.

It is invoked once per invocation in the queue, returns true if the entry has to be filtered (removed), false if the entry has to be kept.

type Position

type Position uint32

Position represents a relative position within the queue.

For example, if this is the 3rd element in the queue, Position will be 3.

Given the QueueID of an element its Position can be computed in O(1) by subtracting the QueueID of the first element currently in the queue.

type Prioritizer

type Prioritizer interface {
	// OnEnqueue is called every time an invocation is queued.
	OnEnqueue(inv *invocation)
	// OnDequeue is called every time an invocation is dequeued.
	//
	// Note that an invocation may be dequeued because it is expired,
	// because the user withdrew the request, or because an allocation
	// is now possible.
	// In this last case, OnDequeue() will be followed by an OnAllocate()
	// call.
	OnDequeue(inv *invocation)

	// OnAllocate is called every time an invocation is allocated a license.
	OnAllocate(inv *invocation)
	// OnRelease is called every time an invocation loses a license.
	//
	// This generally means that the invocation was serviced and the
	// license is no longer needed, but it could be called also if,
	// for example, a client timed out while holding a license.
	OnRelease(inv *invocation)

	// Sorter is a function that returns a function capable of
	// reordering the queue.
	//
	// The returned Sorter is generally passed to invocationQueue.Sort.
	Sorter() Sorter
}

Prioritizer is an object capable of sorting a queue in order of priority.

In order for the prioritizer to have enough data to make the prioritization decision, it must be invoked every time an entry is queued and dequeued, and every time a license is allocated and released.

Prioritizers are NOT thread safe. The caller must guarantee that the use of any method is serialized.

type QueueID

type QueueID uint64

QueueID is a monotonically increasing number representing the absolute position of the item in the queue from when the queue was last emptied.

If the element is reordered, so to be dequeued earlier, its QueueID will be changed accordingly.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service implements the LicenseManager gRPC service.

func New

func New(config *fpb.Config) (*Service, error)

func (*Service) Allocate

func (s *Service) Allocate(ctx context.Context, req *fpb.AllocateRequest) (retRes *fpb.AllocateResponse, retErr error)

Allocate allocates a license to the requesting invocation, or queues the request if none are available. See the proto docstrings for more details.

func (*Service) LicensesStatus

func (s *Service) LicensesStatus(ctx context.Context, req *fpb.LicensesStatusRequest) (retRes *fpb.LicensesStatusResponse, retErr error)

LicensesStatus returns the status for every license type. See the proto docstrings for more details.

func (*Service) Refresh

func (s *Service) Refresh(ctx context.Context, req *fpb.RefreshRequest) (retRes *fpb.RefreshResponse, retErr error)

Refresh serves as a keepalive to refresh an allocation while an invocation is still using it. See the proto docstrings for more info.

func (*Service) Release

func (s *Service) Release(ctx context.Context, req *fpb.ReleaseRequest) (retRes *fpb.ReleaseResponse, retErr error)

Release returns an allocated license and/or unqueues the specified invocation ID across all license types. See the proto docstrings for more details.

type Sorter

type Sorter func(a, b *invocation) bool

Sorter is a function capable of prioritizing an invocation over another.

It behaves like the Less() function in the Sort.Interface definition, moving "lesser" items to the front of the queue.

type Walker

type Walker func(pos Position, inv *invocation) bool

Walker is a function that does something for each entry in the queue.

It is invoked once per invocation in the queue, returns true if the walk should continue, false if it should stop.

Jump to

Keyboard shortcuts

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