Documentation
¶
Index ¶
- func Eject[K comparable, V any](q *LRUEjector[K], b *Backend[K, V]) K
- func EjectPanic[K comparable, V any](b *Backend[K, V]) (K, V, bool)
- func EjectRandomFast[K comparable, V any](b *Backend[K, V]) (bool, error)
- type Assignments
- type Backend
- func (b *Backend[K, V]) Add(key K, value V) bool
- func (b *Backend[K, V]) Adjust(key K, f func(V) V) (V, bool)
- func (b *Backend[K, V]) AdjustWithInit(key K, adjust func(V) V, init func() V) (V, bool)
- func (b *Backend[K, V]) All() map[K]V
- func (b *Backend[K, V]) Clear()
- func (b *Backend[K, V]) Get(key K) (V, bool)
- func (b *Backend[K, V]) Has(key K) bool
- func (b *Backend[K, V]) Limit() uint
- func (b *Backend[K, V]) RegisterEjectionCallbacks(callbacks ...mempool.OnEjection[V])
- func (b *Backend[K, V]) Remove(key K) bool
- func (b *Backend[K, V]) Run(f func(backdata mempool.BackData[K, V]) error) error
- func (b *Backend[K, V]) Size() uint
- func (b *Backend[K, V]) Values() []V
- type BatchEjectFunc
- type ChunkRequests
- func (cs *ChunkRequests) Add(request *verification.ChunkDataPackRequest) bool
- func (cs *ChunkRequests) All() verification.ChunkDataPackRequestInfoList
- func (cs *ChunkRequests) IncrementAttempt(chunkID flow.Identifier) bool
- func (cs *ChunkRequests) PopAll(chunkID flow.Identifier) (chunks.LocatorMap, bool)
- func (cs *ChunkRequests) RequestHistory(chunkID flow.Identifier) (uint64, time.Time, time.Duration, bool)
- func (cs *ChunkRequests) UpdateRequestHistory(chunkID flow.Identifier, updater mempool.ChunkRequestHistoryUpdaterFunc) (uint64, time.Time, time.Duration, bool)
- type ChunkStatuses
- type EjectFunc
- type Guarantees
- type IdentifierMap
- type IncorporatedResultSeals
- func (ir *IncorporatedResultSeals) Add(seal *flow.IncorporatedResultSeal) (bool, error)
- func (ir *IncorporatedResultSeals) All() []*flow.IncorporatedResultSeal
- func (ir *IncorporatedResultSeals) Clear()
- func (ir *IncorporatedResultSeals) PruneUpToHeight(height uint64) error
- func (ir *IncorporatedResultSeals) Remove(id flow.Identifier) bool
- type LRUEjector
- type OptionFunc
- type PendingReceipts
- type Receipts
- type Times
- type TransactionTimings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Eject ¶ added in v0.43.0
func Eject[K comparable, V any](q *LRUEjector[K], b *Backend[K, V]) K
Eject implements EjectFunc for LRUEjector. It finds the value with the lowest sequence number (i.e., the oldest entity). It also untracks. This is using a linear search.
func EjectPanic ¶
func EjectPanic[K comparable, V any](b *Backend[K, V]) (K, V, bool)
EjectPanic simply panics, crashing the program. Useful when cache is not expected to grow beyond certain limits, but ejecting is not applicable
func EjectRandomFast ¶ added in v0.32.0
func EjectRandomFast[K comparable, V any](b *Backend[K, V]) (bool, error)
EjectRandomFast checks if the map size is beyond the threshold size, and will iterate through them and eject unneeded entries if that is the case. Return values are unused
Types ¶
type Assignments ¶
type Assignments struct { *Backend[flow.Identifier, *chunkmodels.Assignment] }
Assignments implements the chunk assignment memory pool. Stored assignments are keyed by assignment fingerprint.
func NewAssignments ¶
func NewAssignments(limit uint) *Assignments
NewAssignments creates a new memory pool for Assignments.
type Backend ¶
type Backend[K comparable, V any] struct { sync.RWMutex // contains filtered or unexported fields }
Backend is a wrapper around the mutable backdata that provides concurrency-safe operations.
func NewBackend ¶
func NewBackend[K comparable, V any](options ...OptionFunc[K, V]) *Backend[K, V]
NewBackend creates a new memory pool backend. This is using EjectRandomFast()
func (*Backend[K, V]) Add ¶
Add attempts to add the given value, without overwriting existing data. If a value is already stored under the input key, Add is a no-op and returns false. If no value is stored under the input key, Add adds the value and returns true.
func (*Backend[K, V]) Adjust ¶
Adjust will adjust the value item using the given function if the given key can be found. Returns:
- value, true if the value with the given key was found. The returned value is the version after the update is applied.
- nil, false if no value with the given key was found
func (*Backend[K, V]) AdjustWithInit ¶ added in v0.33.1
AdjustWithInit adjusts the value using the given function if the given identifier can be found. When the value is not found, it initializes the value using the given init function and then applies the adjust function. Args: - key: the identifier of the value to adjust. - adjust: the function that adjusts the value. - init: the function that initializes the value when it is not found. Returns: - the adjusted value. - a bool which indicates whether the value was adjusted.
func (*Backend[K, V]) All ¶
func (b *Backend[K, V]) All() map[K]V
All returns all stored key-value pairs as a map from the pool. ATTENTION: All does not guarantee returning key-value pairs in the same order as they are added.
func (*Backend[K, V]) Clear ¶ added in v0.11.0
func (b *Backend[K, V]) Clear()
Clear removes all entities from the pool.
func (*Backend[K, V]) Get ¶ added in v0.43.0
Get returns the value for the given key. Returns true if the key-value pair exists, and false otherwise.
func (*Backend[K, V]) RegisterEjectionCallbacks ¶ added in v0.13.0
func (b *Backend[K, V]) RegisterEjectionCallbacks(callbacks ...mempool.OnEjection[V])
RegisterEjectionCallbacks adds the provided OnEjection callbacks
func (*Backend[K, V]) Remove ¶ added in v0.27.0
Remove removes the value with the given key. If the key-value pair exists, returns the value and true. Otherwise, returns the zero value for type V and false.
func (*Backend[K, V]) Run ¶
Run executes a function giving it exclusive access to the backdata. All errors returned from the input functor f are considered exceptions. No errors are expected during normal operation.
type BatchEjectFunc ¶ added in v0.21.0
type BatchEjectFunc[K comparable, V any] func(b *Backend[K, V]) (bool, error)
BatchEjectFunc implements an ejection policy to remove elements when the mempool exceeds its specified capacity. A custom ejection policy can be injected into the memory pool upon creation to change the strategy of eviction. The ejection policy is executed from within the thread that serves the mempool. Implementations should adhere to the following convention:
- The ejector function has the freedom to eject _multiple_ elements.
- In a single `eject` call, it must eject as many elements to statistically keep the mempool size within the desired limit.
- The ejector _might_ (for performance reasons) retain more elements in the mempool than the targeted capacity.
- The ejector _must_ notify the `Backend.ejectionCallbacks` for _each_ element it removes from the mempool.
- Implementations do _not_ need to be concurrency safe. The Backend handles concurrency (specifically, it locks the mempool during ejection).
- The implementation should be non-blocking (though, it is allowed to take a bit of time; the mempool will just be locked during this time).
type ChunkRequests ¶ added in v0.17.0
type ChunkRequests struct { *Backend[flow.Identifier, *chunkRequestStatus] }
ChunkRequests is an implementation of in-memory storage for maintaining chunk requests data objects.
In this implementation, the ChunkRequests wraps the ChunkDataPackRequests around an internal ChunkRequestStatus data object, and maintains the wrapped version in memory. Stored chunk request status are keyed by chunk ID.
func NewChunkRequests ¶ added in v0.17.0
func NewChunkRequests(limit uint) *ChunkRequests
func (*ChunkRequests) Add ¶ added in v0.17.0
func (cs *ChunkRequests) Add(request *verification.ChunkDataPackRequest) bool
Add provides insertion functionality into the memory pool. The insertion is only successful if there is no duplicate chunk request for the same tuple of (chunkID, resultID, chunkIndex).
func (*ChunkRequests) All ¶ added in v0.17.0
func (cs *ChunkRequests) All() verification.ChunkDataPackRequestInfoList
All returns all chunk requests stored in this memory pool.
func (*ChunkRequests) IncrementAttempt ¶ added in v0.17.0
func (cs *ChunkRequests) IncrementAttempt(chunkID flow.Identifier) bool
IncrementAttempt increments the Attempt field of the corresponding status of the chunk request in memory pool that has the specified chunk ID. If such chunk ID does not exist in the memory pool, it returns false.
The increments are done atomically, thread-safe, and in isolation.
func (*ChunkRequests) PopAll ¶ added in v0.23.2
func (cs *ChunkRequests) PopAll(chunkID flow.Identifier) (chunks.LocatorMap, bool)
PopAll atomically returns all locators associated with this chunk ID while clearing out the chunk request status for this chunk id. Boolean return value indicates whether there are requests in the memory pool associated with chunk ID.
func (*ChunkRequests) RequestHistory ¶ added in v0.17.0
func (cs *ChunkRequests) RequestHistory(chunkID flow.Identifier) (uint64, time.Time, time.Duration, bool)
RequestHistory returns the number of times the chunk has been requested, last time the chunk has been requested, and the retryAfter duration of the underlying request status of this chunk.
The last boolean parameter returns whether a chunk request for this chunk ID exists in memory-pool.
func (*ChunkRequests) UpdateRequestHistory ¶ added in v0.17.0
func (cs *ChunkRequests) UpdateRequestHistory(chunkID flow.Identifier, updater mempool.ChunkRequestHistoryUpdaterFunc) (uint64, time.Time, time.Duration, bool)
UpdateRequestHistory updates the request history of the specified chunk ID. If the update was successful, i.e., the updater returns true, the result of update is committed to the mempool, and the time stamp of the chunk request is updated to the current time. Otherwise, it aborts and returns false.
It returns the updated request history values.
The updates under this method are atomic, thread-safe, and done in isolation.
type ChunkStatuses ¶ added in v0.17.0
type ChunkStatuses struct { *Backend[flow.Identifier, *verification.ChunkStatus] }
ChunkStatuses is an implementation of in-memory storage for maintaining the chunk status data objects. Stored chunk statuses are keyed by chunks.Locator ID.
func NewChunkStatuses ¶ added in v0.17.0
func NewChunkStatuses(limit uint) *ChunkStatuses
type Guarantees ¶
type Guarantees struct { *Backend[flow.Identifier, *flow.CollectionGuarantee] }
Guarantees implements the collections memory pool of the consensus nodes, used to store collection guarantees and to generate block payloads. Stored Collection Guarantees are keyed by collection ID.
func NewGuarantees ¶
func NewGuarantees(limit uint) *Guarantees
NewGuarantees creates a new memory pool for collection guarantees.
type IdentifierMap ¶
type IdentifierMap struct { *Backend[flow.Identifier, map[flow.Identifier]struct{}] }
IdentifierMap represents a concurrency-safe memory pool for sets of Identifier (keyed by some Identifier).
func NewIdentifierMap ¶
func NewIdentifierMap(limit uint) *IdentifierMap
NewIdentifierMap creates a new memory pool for sets of Identifier (keyed by some Identifier).
func (*IdentifierMap) Append ¶
func (i *IdentifierMap) Append(key, id flow.Identifier)
Append will add the id to the set of identifiers associated with key. If the key does not exist, a new set containing only `id` is stored. If `id` already exists in the set stored under `key`, Append is a no-op.
func (*IdentifierMap) Get ¶
func (i *IdentifierMap) Get(key flow.Identifier) (flow.IdentifierList, bool)
Get returns the set of all identifiers associated with key and true, if the key exists in the mempool. The set is returned as an unordered list with no duplicates. Otherwise it returns nil and false.
func (*IdentifierMap) Keys ¶
func (i *IdentifierMap) Keys() (flow.IdentifierList, bool)
Keys returns a list of all keys in the mempool.
func (*IdentifierMap) RemoveIdFromKey ¶ added in v0.27.0
func (i *IdentifierMap) RemoveIdFromKey(key, id flow.Identifier) error
RemoveIdFromKey removes the id from the list of identifiers associated with key. If the list becomes empty, it also removes the key from the map.
type IncorporatedResultSeals ¶ added in v0.11.0
type IncorporatedResultSeals struct { *Backend[flow.Identifier, *flow.IncorporatedResultSeal] // contains filtered or unexported fields }
IncorporatedResultSeals implements the incorporated result seals memory pool of the consensus nodes, used to store seals that need to be added to blocks. Incorporated result seals are keyed by the ID of the incorporated result. ATTENTION: This data structure should NEVER eject seals because it can break liveness. Modules that are using this structure expect that it NEVER ejects a seal.
func NewIncorporatedResultSeals ¶ added in v0.11.0
func NewIncorporatedResultSeals(limit uint) *IncorporatedResultSeals
NewIncorporatedResultSeals creates a mempool for the incorporated result seals
func (*IncorporatedResultSeals) Add ¶ added in v0.11.0
func (ir *IncorporatedResultSeals) Add(seal *flow.IncorporatedResultSeal) (bool, error)
Add adds an IncorporatedResultSeal to the mempool
func (*IncorporatedResultSeals) All ¶ added in v0.11.0
func (ir *IncorporatedResultSeals) All() []*flow.IncorporatedResultSeal
All returns all the items in the mempool
func (*IncorporatedResultSeals) Clear ¶ added in v0.13.0
func (ir *IncorporatedResultSeals) Clear()
func (*IncorporatedResultSeals) PruneUpToHeight ¶ added in v0.18.1
func (ir *IncorporatedResultSeals) PruneUpToHeight(height uint64) error
PruneUpToHeight remove all seals for blocks whose height is strictly smaller that height. Note: seals for blocks at height are retained. After pruning, seals below for blocks below the given height are dropped.
Monotonicity Requirement: The pruned height cannot decrease, as we cannot recover already pruned elements. If `height` is smaller than the previous value, the previous value is kept and the sentinel mempool.BelowPrunedThresholdError is returned.
func (*IncorporatedResultSeals) Remove ¶ added in v0.27.0
func (ir *IncorporatedResultSeals) Remove(id flow.Identifier) bool
Remove removes an IncorporatedResultSeal from the mempool
type LRUEjector ¶
type LRUEjector[K comparable] struct { sync.Mutex // contains filtered or unexported fields }
LRUEjector provides a swift FIFO ejection functionality
func NewLRUEjector ¶
func NewLRUEjector[K comparable]() *LRUEjector[K]
func (*LRUEjector[K]) Track ¶
func (q *LRUEjector[K]) Track(key K)
Track should be called every time a new entity is added to the mempool. It tracks the entity for later ejection.
func (*LRUEjector[K]) Untrack ¶
func (q *LRUEjector[K]) Untrack(key K)
Untrack simply removes the tracker of the ejector off the entityID
type OptionFunc ¶
type OptionFunc[K comparable, V any] func(backend *Backend[K, V])
OptionFunc is a function that can be provided to the backend on creation in order to set a certain custom option.
func WithEject ¶
func WithEject[K comparable, V any](eject EjectFunc[K, V]) OptionFunc[K, V]
WithEject can be provided to the backend on creation in order to set a custom eject function to pick the entity to be evicted upon overflow, as well as hooking into it for additional cleanup work.
func WithLimit ¶
func WithLimit[K comparable, V any](limit uint) OptionFunc[K, V]
WithLimit can be provided to the backend on creation in order to set a point where it's time to check for ejection conditions. The actual size may continue to rise by the threshold for batch ejection (currently 128)
func WithMutableBackData ¶ added in v0.43.0
func WithMutableBackData[K comparable, V any](mutableBackData mempool.MutableBackData[K, V]) OptionFunc[K, V]
WithMutableBackData sets the underlying mutable BackData for the backend.
MutableBackData represents the mutable data structure used by mempool.Backend core structure of maintaining data on memory-pools.
type PendingReceipts ¶ added in v0.14.1
type PendingReceipts struct { *Backend[flow.Identifier, *flow.ExecutionReceipt] // contains filtered or unexported fields }
PendingReceipts stores pending receipts indexed by the ID of execution receipt. It also maintains a secondary index on the previous result id. in order to allow to find receipts by the previous result id.
func NewPendingReceipts ¶ added in v0.14.1
func NewPendingReceipts(headers storage.Headers, limit uint) *PendingReceipts
NewPendingReceipts creates a new memory pool for execution receipts.
func (*PendingReceipts) Add ¶ added in v0.14.1
func (r *PendingReceipts) Add(receipt *flow.ExecutionReceipt) bool
Add adds an execution receipt to the mempool.
func (*PendingReceipts) ByPreviousResultID ¶ added in v0.14.1
func (r *PendingReceipts) ByPreviousResultID(previousResultID flow.Identifier) []*flow.ExecutionReceipt
ByPreviousResultID returns receipts whose previous result ID matches the given ID
func (*PendingReceipts) PruneUpToHeight ¶ added in v0.19.0
func (r *PendingReceipts) PruneUpToHeight(height uint64) error
PruneUpToHeight remove all receipts for blocks whose height is strictly smaller that height. Note: receipts for blocks at height are retained. After pruning, receipts below for blocks below the given height are dropped.
Monotonicity Requirement: The pruned height cannot decrease, as we cannot recover already pruned elements. If `height` is smaller than the previous value, the previous value is kept and the sentinel mempool.BelowPrunedThresholdError is returned.
func (*PendingReceipts) Remove ¶ added in v0.27.0
func (r *PendingReceipts) Remove(receiptID flow.Identifier) bool
Remove will remove a receipt by ID.
type Receipts ¶
type Receipts struct { *Backend[flow.Identifier, *flow.ExecutionReceipt] }
Receipts implements the execution receipts memory pool of the consensus node, used to store execution receipts and to generate block seals. Stored Receipts are keyed by the ID of execution receipt.
func NewReceipts ¶
NewReceipts creates a new memory pool for execution receipts.
type Times ¶
type Times struct { *Backend[flow.Identifier, time.Time] }
Times implements the times memory pool used to store time.Time values associated with flow.Identifiers for tracking transaction metrics in Access nodes.
type TransactionTimings ¶
type TransactionTimings struct { *Backend[flow.Identifier, *flow.TransactionTiming] }
TransactionTimings implements the transaction timings memory pool of access nodes, used to store transaction timings to report the timing of individual transactions. Stored transaction timings are keyed by transaction ID.
func NewTransactionTimings ¶
func NewTransactionTimings(limit uint) *TransactionTimings
NewTransactionTimings creates a new memory pool for transaction timings.