Documentation ¶
Index ¶
- Variables
- func UnitsFromConfig(config *apb.Config) (map[string]*unit, error)
- type EvenOwnersPrioritizer
- type FIFOPrioritizer
- type Filter
- type Match
- type Matched
- type Position
- type Prioritizer
- type QueueID
- type Service
- func (s *Service) Allocate(ctx context.Context, req *apb.AllocateRequest) (retRes *apb.AllocateResponse, retErr error)
- func (s *Service) Refresh(ctx context.Context, req *apb.RefreshRequest) (retRes *apb.RefreshResponse, retErr error)
- func (s *Service) Release(ctx context.Context, req *apb.ReleaseRequest) (retRes *apb.ReleaseResponse, retErr error)
- func (s *Service) Status(ctx context.Context, req *apb.StatusRequest) (retRes *apb.StatusResponse, retErr error)
- type Sorter
- type Walker
Constants ¶
This section is empty.
Variables ¶
var InvocationQueue invocationQueue
all requests go into a global queue
Functions ¶
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 ¶
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
type Matched ¶
type Matched struct {
// contains filtered or unexported fields
}
func Matchmaker ¶
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
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 (*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.