cache

package
v0.0.0-...-f0bc3ce Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package cache provides a cache of model.Model elements that can be used in an OVSDB client or server.

The cache can be accessed using a simple API:

cache.Table("Open_vSwitch").Row("<ovs-uuid>")

It implements the ovsdb.NotificationHandler interface such that it can be populated automatically by update notifications

It also contains an eventProcessor where callers may registers functions that will get called on every Add/Update/Delete event.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data map[string]map[string]model.Model

Data is the type for data that can be prepopulated in the cache

type ErrCacheInconsistent

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

ErrCacheInconsistent is an error that can occur when an operation would cause the cache to be inconsistent

func NewErrCacheInconsistent

func NewErrCacheInconsistent(details string) *ErrCacheInconsistent

func (*ErrCacheInconsistent) Error

func (e *ErrCacheInconsistent) Error() string

Error implements the error interface

type ErrIndexExists

type ErrIndexExists struct {
	Table    string
	Value    interface{}
	Index    string
	New      string
	Existing []string
}

ErrIndexExists is returned when an item in the database cannot be inserted due to existing indexes

func NewIndexExistsError

func NewIndexExistsError(table string, value interface{}, index string, new string, existing []string) *ErrIndexExists

func (*ErrIndexExists) Error

func (e *ErrIndexExists) Error() string

type EventHandler

type EventHandler interface {
	OnAdd(table string, model model.Model)
	OnUpdate(table string, old model.Model, new model.Model)
	OnDelete(table string, model model.Model)
}

EventHandler can handle events when the contents of the cache changes

type EventHandlerFuncs

type EventHandlerFuncs struct {
	AddFunc    func(table string, model model.Model)
	UpdateFunc func(table string, old model.Model, new model.Model)
	DeleteFunc func(table string, model model.Model)
}

EventHandlerFuncs is a wrapper for the EventHandler interface It allows a caller to only implement the functions they need

func (*EventHandlerFuncs) OnAdd

func (e *EventHandlerFuncs) OnAdd(table string, model model.Model)

OnAdd calls AddFunc if it is not nil

func (*EventHandlerFuncs) OnDelete

func (e *EventHandlerFuncs) OnDelete(table string, row model.Model)

OnDelete calls DeleteFunc if it is not nil

func (*EventHandlerFuncs) OnUpdate

func (e *EventHandlerFuncs) OnUpdate(table string, old, new model.Model)

OnUpdate calls UpdateFunc if it is not nil

type RowCache

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

RowCache is a collections of Models hashed by UUID

func (*RowCache) Create

func (r *RowCache) Create(uuid string, m model.Model, checkIndexes bool) error

Create writes the provided content to the cache

func (*RowCache) Delete

func (r *RowCache) Delete(uuid string) error

Delete deletes a row from the cache

func (*RowCache) HasRow

func (r *RowCache) HasRow(uuid string) bool

func (*RowCache) Index

func (r *RowCache) Index(columns ...string) (map[interface{}][]string, error)

func (*RowCache) IndexExists

func (r *RowCache) IndexExists(row model.Model) error

IndexExists checks if any of the schema indexes of the provided model is already in the cache under a different UUID.

func (*RowCache) Len

func (r *RowCache) Len() int

Len returns the length of the cache

func (*RowCache) Row

func (r *RowCache) Row(uuid string) model.Model

Row returns one model from the cache by UUID

func (*RowCache) RowByModel

func (r *RowCache) RowByModel(m model.Model) (string, model.Model, error)

RowByModel searches the cache by UUID and schema indexes. UUID search is performed first. Then schema indexes are evaluated in turn by the same order with which they are defined in the schema. The model for the first matching index is returned along with its UUID. An empty string and nil is returned if no Model is found.

func (*RowCache) Rows

func (r *RowCache) Rows() map[string]model.Model

Rows returns a copy of all Rows in the Cache

func (*RowCache) RowsByCondition

func (r *RowCache) RowsByCondition(conditions []ovsdb.Condition) (map[string]model.Model, error)

RowsByCondition searches models in the cache that match all conditions

func (*RowCache) RowsByModels

func (r *RowCache) RowsByModels(models []model.Model) (map[string]model.Model, error)

RowsByModels searches the cache by UUID, schema indexes and client indexes. UUID search is performed first. Schema indexes are evaluated next in turn by the same order with which they are defined in the schema. Finally, client indexes are evaluated in turn by the same order with which they are defined in the client DB model. The models for the first matching index are returned, which might be more than 1 if they were found through a client index since in that case uniqueness is not enforced. Nil is returned if no Model is found.

func (*RowCache) RowsShallow

func (r *RowCache) RowsShallow() map[string]model.Model

RowsShallow returns a clone'd list of f all Rows in the cache, but does not clone the underlying objects. Therefore, the objects returned are READ ONLY. This is, however, thread safe, as the cached objects are cloned before being updated when modifications come in.

func (*RowCache) Update

func (r *RowCache) Update(uuid string, m model.Model, checkIndexes bool) (model.Model, error)

Update updates the content in the cache and returns the original (pre-update) model

type TableCache

type TableCache struct {
	ovsdb.NotificationHandler
	// contains filtered or unexported fields
}

TableCache contains a collection of RowCaches, hashed by name, and an array of EventHandlers that respond to cache updates It implements the ovsdb.NotificationHandler interface so it may handle update notifications

func NewTableCache

func NewTableCache(dbModel model.DatabaseModel, data Data, logger *logr.Logger) (*TableCache, error)

NewTableCache creates a new TableCache

func (*TableCache) AddEventHandler

func (t *TableCache) AddEventHandler(handler EventHandler)

AddEventHandler registers the supplied EventHandler to receive cache events

func (*TableCache) ApplyCacheUpdate

func (t *TableCache) ApplyCacheUpdate(update cacheUpdate) error

func (*TableCache) DatabaseModel

func (t *TableCache) DatabaseModel() model.DatabaseModel

DatabaseModel returns the DatabaseModelRequest

func (*TableCache) Disconnected

func (t *TableCache) Disconnected()

Disconnected implements the disconnected method of the NotificationHandler interface

func (*TableCache) Echo

func (t *TableCache) Echo([]interface{})

Echo implements the echo method of the NotificationHandler interface

func (*TableCache) Locked

func (t *TableCache) Locked([]interface{})

Locked implements the locked method of the NotificationHandler interface

func (*TableCache) Mapper

func (t *TableCache) Mapper() mapper.Mapper

Mapper returns the mapper

func (*TableCache) Populate

func (t *TableCache) Populate(tableUpdates ovsdb.TableUpdates) error

Populate adds data to the cache and places an event on the channel

func (*TableCache) Populate2

func (t *TableCache) Populate2(tableUpdates ovsdb.TableUpdates2) error

Populate2 adds data to the cache and places an event on the channel

func (*TableCache) Purge

func (t *TableCache) Purge(dbModel model.DatabaseModel)

Purge drops all data in the cache and reinitializes it using the provided database model

func (*TableCache) Run

func (t *TableCache) Run(stopCh <-chan struct{})

Run starts the event processing and update processing loops. It blocks until the stop channel is closed. Once closed, it clears the updates/updates2 channels to ensure we don't process stale updates on a new connection

func (*TableCache) Stolen

func (t *TableCache) Stolen([]interface{})

Stolen implements the stolen method of the NotificationHandler interface

func (*TableCache) Table

func (t *TableCache) Table(name string) *RowCache

Table returns the a Table from the cache with a given name

func (*TableCache) Tables

func (t *TableCache) Tables() []string

Tables returns a list of table names that are in the cache

func (*TableCache) Update

func (t *TableCache) Update(context interface{}, tableUpdates ovsdb.TableUpdates) error

Update implements the update method of the NotificationHandler interface this populates a channel with updates so they can be processed after the initial state has been Populated

func (*TableCache) Update2

func (t *TableCache) Update2(context interface{}, tableUpdates ovsdb.TableUpdates2) error

Update2 implements the update method of the NotificationHandler interface this populates a channel with updates so they can be processed after the initial state has been Populated

Jump to

Keyboard shortcuts

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