service

package
v0.0.0-...-bee7c02 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InvocationQueue invocationQueue

all requests go into a global queue

Functions

func UnitsFromConfig

func UnitsFromConfig(config *apb.Config) (map[string]*unit, error)

UnitsFromConfig given a Config proto during startup, store unit topologies

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 Match

type Match struct {
	Topology *apb.Topology // yes, duplicate from invocation, but pointers are cheap. this makes iterating easier.
	Units    []*unit
}

TODO: move to topology.go

func (*Match) Found

func (m *Match) Found() bool

type Matched

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

func Matchmaker

func Matchmaker(units map[string]*unit, inv *invocation, all bool) (*Matched, error)

Matchmaker returns [n][_]*unit containing plausible matches n: index corresponding to the invocation topologies _: if all=false, len is 0 (nomatch) or 1 (match). if all=true, len is uint

func NewMatched

func NewMatched(inv *invocation) *Matched

TODO: feels not quite right style wise

func (*Matched) Found

func (md *Matched) Found() bool

func (*Matched) ToString

func (md *Matched) ToString(nu int) string

type Position

type Position uint32

Position represents a relative position within the queue.

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

Given the QueueID of an element its Position can be computed in O(0) 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 *apb.Config) (*Service, error)

func (*Service) Allocate

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

Allocate validates invocation request is satisfiable, then queues it. See the proto docstrings for more details.

func (*Service) Refresh

func (s *Service) Refresh(ctx context.Context, req *apb.RefreshRequest) (retRes *apb.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 *apb.ReleaseRequest) (retRes *apb.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.

func (*Service) Status

func (s *Service) Status(ctx context.Context, req *apb.StatusRequest) (retRes *apb.StatusResponse, retErr error)

Status returns the status for every license type. 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