schedulerutils

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: Apache-2.0, BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ElementIDLength = 32 + 8

ElementIDLength defines the length of an ElementID.

Variables

View Source
var ErrInsufficientMana = errors.New("insufficient node's mana to schedule the block")

ErrInsufficientMana is returned when the mana is insufficient.

Functions

This section is empty.

Types

type AccessManaCache

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

AccessManaCache is a structure which provides access to cached access mana values. Mana values are refreshed after certain amount of time has passed.

func NewAccessManaCache

func NewAccessManaCache(accessManaMapRetrieverFunc func() map[identity.ID]float64, totalAccessManaRetrieverFunc func() float64, minMana float64) *AccessManaCache

NewAccessManaCache returns a new AccessManaCache.

func (*AccessManaCache) GetCachedMana

func (a *AccessManaCache) GetCachedMana(id identity.ID) float64

GetCachedMana returns cached access mana value for a given node and refreshes mana vectors if they expired currently returns at least MinMana.

func (*AccessManaCache) GetCachedTotalMana

func (a *AccessManaCache) GetCachedTotalMana() float64

GetCachedTotalMana returns cached total mana value.

func (*AccessManaCache) RawAccessManaVector

func (a *AccessManaCache) RawAccessManaVector() map[identity.ID]float64

RawAccessManaVector returns raw access mana vector retrieved from mana plugin.

func (*AccessManaCache) RefreshCacheIfNecessary

func (a *AccessManaCache) RefreshCacheIfNecessary()

RefreshCacheIfNecessary refreshes mana cache after it has expired.

type BufferQueue

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

BufferQueue represents a buffer of NodeQueue.

func NewBufferQueue

func NewBufferQueue(maxBuffer int, maxQueue float64) *BufferQueue

NewBufferQueue returns a new BufferQueue.

func (*BufferQueue) Current

func (b *BufferQueue) Current() *NodeQueue

Current returns the current NodeQueue in round robin order.

func (*BufferQueue) IDs

func (b *BufferQueue) IDs() (ids []ElementID)

IDs returns the IDs of all submitted blocks (ready or not).

func (*BufferQueue) InsertNode

func (b *BufferQueue) InsertNode(nodeID identity.ID)

InsertNode creates a queue for the given node and adds it to the list of active nodes.

func (*BufferQueue) MaxSize

func (b *BufferQueue) MaxSize() int

MaxSize returns the max size (in bytes) of all blocks in b.

func (*BufferQueue) Next

func (b *BufferQueue) Next() *NodeQueue

Next returns the next NodeQueue in round robin order.

func (*BufferQueue) NodeIDs

func (b *BufferQueue) NodeIDs() []identity.ID

NodeIDs returns the nodeIDs of all nodes.

func (*BufferQueue) NodeQueue

func (b *BufferQueue) NodeQueue(nodeID identity.ID) *NodeQueue

NodeQueue returns the queue for the corresponding node.

func (*BufferQueue) NumActiveNodes

func (b *BufferQueue) NumActiveNodes() int

NumActiveNodes returns the number of active nodes in b.

func (*BufferQueue) PopFront

func (b *BufferQueue) PopFront() Element

PopFront removes the first ready block from the queue of the current node.

func (*BufferQueue) Ready

func (b *BufferQueue) Ready(blk Element) bool

Ready marks a previously submitted block as ready to be scheduled.

func (*BufferQueue) ReadyBlocksCount

func (b *BufferQueue) ReadyBlocksCount() (readyBlkCount int)

ReadyBlocksCount returns the number of ready blocks in the buffer.

func (*BufferQueue) RemoveNode

func (b *BufferQueue) RemoveNode(nodeID identity.ID)

RemoveNode removes all blocks (submitted and ready) for the given node.

func (*BufferQueue) Size

func (b *BufferQueue) Size() int

Size returns the total size (in bytes) of all blocks in b.

func (*BufferQueue) Submit

func (b *BufferQueue) Submit(blk Element, accessManaRetriever func(identity.ID) float64) (elements []ElementID, err error)

Submit submits a block. Return blocks dropped from the scheduler to make room for the submitted block. The submitted block can also be returned as dropped if the issuing node does not have enough access mana.

func (*BufferQueue) TotalBlocksCount

func (b *BufferQueue) TotalBlocksCount() (blkCount int)

TotalBlocksCount returns the number of blocks in the buffer.

func (*BufferQueue) Unsubmit

func (b *BufferQueue) Unsubmit(blk Element) bool

Unsubmit removes a block from the submitted blocks. If that block is already marked as ready, Unsubmit has no effect.

type Element

type Element interface {
	// IDBytes returns the ID of an Element as a byte slice.
	IDBytes() []byte

	// Size returns the size of the element.
	Size() int

	// IssuerPublicKey returns the issuer public key of the element.
	IssuerPublicKey() ed25519.PublicKey

	// IssuingTime returns the issuing time of the block.
	IssuingTime() time.Time
}

Element represents the generic interface for an block in NodeQueue.

type ElementHeap

type ElementHeap []Element

ElementHeap holds a heap of blocks with respect to their IssuingTime.

func (ElementHeap) Len

func (h ElementHeap) Len() int

Len is the number of elements in the collection.

func (ElementHeap) Less

func (h ElementHeap) Less(i, j int) bool

Less reports whether the element with index i must sort before the element with index j.

func (*ElementHeap) Pop

func (h *ElementHeap) Pop() interface{}

Pop removes and returns element with index Len() - 1.

func (*ElementHeap) Push

func (h *ElementHeap) Push(x interface{})

Push adds x as element with index Len(). It panics if x is not Element.

func (ElementHeap) Swap

func (h ElementHeap) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type ElementID

type ElementID [ElementIDLength]byte

ElementID defines the ID of element.

func ElementIDFromBytes

func ElementIDFromBytes(data []byte) (result ElementID)

ElementIDFromBytes converts byte array to an ElementID.

func (ElementID) Bytes

func (e ElementID) Bytes() []byte

type NodeQueue

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

NodeQueue keeps the submitted blocks of a node.

func NewNodeQueue

func NewNodeQueue(nodeID identity.ID) *NodeQueue

NewNodeQueue returns a new NodeQueue.

func (*NodeQueue) Front

func (q *NodeQueue) Front() Element

Front returns the first ready block in the queue.

func (*NodeQueue) IDs

func (q *NodeQueue) IDs() (ids []ElementID)

IDs returns the IDs of all submitted blocks (ready or not).

func (*NodeQueue) NodeID

func (q *NodeQueue) NodeID() identity.ID

NodeID returns the ID of the node belonging to the queue.

func (*NodeQueue) PopFront

func (q *NodeQueue) PopFront() Element

PopFront removes the first ready block from the queue.

func (*NodeQueue) Ready

func (q *NodeQueue) Ready(element Element) bool

Ready marks a previously submitted block as ready to be scheduled.

func (*NodeQueue) Size

func (q *NodeQueue) Size() int

Size returns the total size of the blocks in the queue. This function is thread-safe.

func (*NodeQueue) Submit

func (q *NodeQueue) Submit(element Element) bool

Submit submits a block for the queue.

func (*NodeQueue) Unsubmit

func (q *NodeQueue) Unsubmit(element Element) bool

Unsubmit removes a previously submitted block from the queue.

Jump to

Keyboard shortcuts

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