occache

package
v0.1.526 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package cache is a tree-based cache of timestamped state provided from one or more gNMI targets. It accepts updates from the target(s) to refresh internal values that are made available to clients via subscriptions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func T

func T(n int64) time.Time

T provides a shorthand function to reference a timestamp with an int64 (nanoseconds since epoch).

Types

type Cache

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

Cache is a structure holding state information for multiple targets.

func New

func New(targets []string, opts ...Option) *Cache

New creates a new instance of Cache that receives target updates from the translator and provides an interface to service client queries.

func (*Cache) Add

func (c *Cache) Add(target string) *Target

Add reserves space in c to receive updates for the specified target.

func (*Cache) Connect

func (c *Cache) Connect(name string)

Connect creates an internal gnmi.Notification for metadata/connected path to set the state to true for the specified target.

func (*Cache) ConnectError

func (c *Cache) ConnectError(name string, err error)

ConnectError updates the target's metadata with the provided error.

func (*Cache) GetTarget

func (c *Cache) GetTarget(target string) *Target

GetTarget returns the Target from the cache corresponding to the target name.

func (*Cache) GnmiUpdate

func (c *Cache) GnmiUpdate(n *pb.Notification) error

GnmiUpdate sends a pb.Notification into the cache. If the notification has multiple Updates/Deletes, each individual Update/Delete is sent to cache as a separate gnmi.Notification.

func (*Cache) HasTarget

func (c *Cache) HasTarget(target string) bool

HasTarget reports whether the specified target exists in the cache or a glob (*) is passed which will match any target (even if no targets yet exist).

func (*Cache) LatencyWindows

func (c *Cache) LatencyWindows() []time.Duration

LatencyWindows returns the latency windows supported by the cache.

func (*Cache) Metadata

func (c *Cache) Metadata() map[string]*metadata.Metadata

Metadata returns the per-target metadata structures.

func (*Cache) Query

func (c *Cache) Query(target string, query []string, fn octree.VisitFunc) error

Query calls the specified callback for all results matching the query. All values passed to fn are client.Notification.

func (*Cache) Remove

func (c *Cache) Remove(target string)

Remove removes the space in c corresponding to the specified target.

func (*Cache) Reset

func (c *Cache) Reset(target string)

Reset clears the cache for a target once a connection is resumed after having been lost.

func (*Cache) SetClient

func (c *Cache) SetClient(client func(*octree.Leaf))

SetClient registers a callback function to receive calls for each update accepted by the cache. This call should be made prior to sending any updates into the cache, just after initialization.

func (*Cache) Sync

func (c *Cache) Sync(name string)

Sync creates an internal gnmi.Notification with metadata/sync path to set the state to true for the specified target.

func (*Cache) UpdateMetadata

func (c *Cache) UpdateMetadata()

UpdateMetadata copies the current metadata for each target cache to the metadata path within each target cache.

func (*Cache) UpdateSize

func (c *Cache) UpdateSize()

UpdateSize computes the size of each target cache and updates the size metadata reported within the each target cache.

type Option

type Option func(*options)

Option defines the function prototype to set options for creating a Cache.

func WithAvgLatencyPrecision

func WithAvgLatencyPrecision(avgLatencyPrecision time.Duration) Option

WithAvgLatencyPrecision returns an Option to set the precision of average latency stats calculated in Cache.

func WithLatencyWindows

func WithLatencyWindows(ws []string, metaUpdatePeriod time.Duration) (Option, error)

WithLatencyWindows returns an Option to set latency windows for which latency stats are calculated and exported for each target in Cache. metaUpdatePeriod is the period for updating target metadata. The latency windows need to be multiples of this period.

type Target

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

A Target hosts an indexed cache of state for a single target.

func (*Target) Connect

func (t *Target) Connect()

Connect creates an internal gnmi.Notification for metadata/connected path to set the state to true for the specified target, and clear connectErr.

func (*Target) GnmiUpdate

func (t *Target) GnmiUpdate(n *pb.Notification) error

GnmiUpdate sends a pb.Notification into the target cache. If the notification has multiple Updates/Deletes, each individual Update/Delete is sent to cache as a separate gnmi.Notification.

func (*Target) Name

func (t *Target) Name() string

Name returns the name of the target.

func (*Target) Reset

func (t *Target) Reset()

Reset clears the Target of stale data upon a reconnection and notifies cache client of the removal.

func (*Target) Sync

func (t *Target) Sync()

Sync creates an internal gnmi.Notification with metadata/sync path to set the state to true for the specified target.

Jump to

Keyboard shortcuts

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